@@ -80,6 +80,20 @@ def _assert_bin_dir_structure(env, ctx, bin_dir, toolchain):
8080 "darwin component should start with 'darwin', got '{}'" .format (darwin_component ),
8181 )
8282
83+ def _native_link_arg (ctx , action , pic_suffix = "" , stripped = False ):
84+ toolchain = _get_toolchain (ctx )
85+ if toolchain .target_os == "windows" :
86+ if toolchain .target_triple .abi == "msvc" :
87+ link_arg = "-Clink-arg=native_dep.lib"
88+ else :
89+ link_arg = "-Clink-arg=-lnative_dep.lib"
90+ else :
91+ link_arg = "-Clink-arg={}/test/unit/native_deps/libnative_dep{}.a" .format (
92+ _get_bin_dir_from_action (action ),
93+ pic_suffix ,
94+ )
95+ return link_arg .removeprefix ("-Clink-arg=" ) if stripped else link_arg
96+
8397def _rlib_has_no_native_libs_test_impl (ctx ):
8498 env = analysistest .begin (ctx )
8599 tut = analysistest .target_under_test (env )
@@ -94,78 +108,46 @@ def _cdylib_has_native_libs_test_impl(ctx):
94108 env = analysistest .begin (ctx )
95109 tut = analysistest .target_under_test (env )
96110 action = tut .actions [0 ]
97- toolchain = _get_toolchain (ctx )
98111 compilation_mode = ctx .var ["COMPILATION_MODE" ]
99112 pic_suffix = _get_pic_suffix (ctx , compilation_mode )
100113 assert_argv_contains_prefix_suffix (env , action , "-Lnative=" , "/native_deps" )
101114 assert_argv_contains (env , action , "--crate-type=cdylib" )
102115 assert_argv_contains (env , action , "-lstatic=native_dep{}" .format (pic_suffix ))
103- if toolchain .target_os == "windows" :
104- if toolchain .target_triple .abi == "msvc" :
105- native_link_arg = "-Clink-arg=native_dep.lib"
106- else :
107- native_link_arg = "-Clink-arg=-lnative_dep.lib"
108- else :
109- native_link_arg = "-Clink-arg=-lnative_dep{}" .format (pic_suffix )
110- assert_argv_contains (env , action , native_link_arg )
116+ assert_argv_contains (env , action , _native_link_arg (ctx , action , pic_suffix ))
111117 assert_argv_contains_prefix (env , action , "--codegen=linker=" )
112118 return analysistest .end (env )
113119
114120def _staticlib_has_native_libs_test_impl (ctx ):
115121 env = analysistest .begin (ctx )
116122 tut = analysistest .target_under_test (env )
117123 action = tut .actions [0 ]
118- toolchain = _get_toolchain (ctx )
119124 assert_argv_contains_prefix_suffix (env , action , "-Lnative=" , "/native_deps" )
120125 assert_argv_contains (env , action , "--crate-type=staticlib" )
121126 assert_argv_contains (env , action , "-lstatic=native_dep" )
122- if toolchain .target_os == "windows" :
123- if toolchain .target_triple .abi == "msvc" :
124- native_link_arg = "-Clink-arg=native_dep.lib"
125- else :
126- native_link_arg = "-Clink-arg=-lnative_dep.lib"
127- else :
128- native_link_arg = "-Clink-arg=-lnative_dep"
129- assert_argv_contains (env , action , native_link_arg )
127+ assert_argv_contains (env , action , _native_link_arg (ctx , action ))
130128 assert_argv_contains_prefix (env , action , "--codegen=linker=" )
131129 return analysistest .end (env )
132130
133131def _proc_macro_has_native_libs_test_impl (ctx ):
134132 env = analysistest .begin (ctx )
135133 tut = analysistest .target_under_test (env )
136134 action = tut .actions [0 ]
137- toolchain = _get_toolchain (ctx )
138135 compilation_mode = ctx .var ["COMPILATION_MODE" ]
139136 pic_suffix = _get_pic_suffix (ctx , compilation_mode )
140137 assert_argv_contains_prefix_suffix (env , action , "-Lnative=" , "/native_deps" )
141138 assert_argv_contains (env , action , "--crate-type=proc-macro" )
142139 assert_argv_contains (env , action , "-lstatic=native_dep{}" .format (pic_suffix ))
143- if toolchain .target_os == "windows" :
144- if toolchain .target_triple .abi == "msvc" :
145- native_link_arg = "-Clink-arg=native_dep.lib"
146- else :
147- native_link_arg = "-Clink-arg=-lnative_dep.lib"
148- else :
149- native_link_arg = "-Clink-arg=-lnative_dep{}" .format (pic_suffix )
150- assert_argv_contains (env , action , native_link_arg )
140+ assert_argv_contains (env , action , _native_link_arg (ctx , action , pic_suffix ))
151141 assert_argv_contains_prefix (env , action , "--codegen=linker=" )
152142 return analysistest .end (env )
153143
154144def _bin_has_native_libs_test_impl (ctx ):
155145 env = analysistest .begin (ctx )
156146 tut = analysistest .target_under_test (env )
157147 action = tut .actions [0 ]
158- toolchain = _get_toolchain (ctx )
159148 assert_argv_contains_prefix_suffix (env , action , "-Lnative=" , "/native_deps" )
160149 assert_argv_contains (env , action , "-lstatic=native_dep" )
161- if toolchain .target_os == "windows" :
162- if toolchain .target_triple .abi == "msvc" :
163- native_link_arg = "-Clink-arg=native_dep.lib"
164- else :
165- native_link_arg = "-Clink-arg=-lnative_dep.lib"
166- else :
167- native_link_arg = "-Clink-arg=-lnative_dep"
168- assert_argv_contains (env , action , native_link_arg )
150+ assert_argv_contains (env , action , _native_link_arg (ctx , action ))
169151 assert_argv_contains_prefix (env , action , "--codegen=linker=" )
170152 return analysistest .end (env )
171153
@@ -197,21 +179,22 @@ def _bin_has_native_dep_and_alwayslink_test_impl(ctx, use_cc_linker):
197179
198180 # Validate bin_dir structure (ignoring ST-{hash} suffix from config transitions)
199181 _assert_bin_dir_structure (env , ctx , bin_dir , toolchain )
182+ native_link_arg = _native_link_arg (ctx , action , stripped = True )
200183
201184 if toolchain .target_os in ["macos" , "darwin" ]:
202185 if use_cc_linker :
203186 # When using CC linker, args are passed with -Wl, prefix as separate arguments
204187 want = [
205188 "-lstatic=native_dep" ,
206- "-lnative_dep" ,
189+ native_link_arg ,
207190 "-Wl,-force_load" ,
208191 "-Wl,{}/test/unit/native_deps/libalwayslink.lo" .format (bin_dir ),
209192 ]
210193 else :
211194 # When using rust-lld directly, args are passed without prefix as separate arguments
212195 want = [
213196 "-lstatic=native_dep" ,
214- "-lnative_dep" ,
197+ native_link_arg ,
215198 "-force_load" ,
216199 "{}/test/unit/native_deps/libalwayslink.lo" .format (bin_dir ),
217200 ]
@@ -242,22 +225,23 @@ def _bin_has_native_dep_and_alwayslink_test_impl(ctx, use_cc_linker):
242225 elif toolchain .target_arch == "s390x" :
243226 want = [
244227 "-lstatic=native_dep" ,
228+ native_link_arg ,
245229 "link-arg=-Wl,--whole-archive" ,
246230 "link-arg={}/test/unit/native_deps/libalwayslink.lo" .format (bin_dir ),
247231 "link-arg=-Wl,--no-whole-archive" ,
248232 ]
249233 elif use_cc_linker :
250234 want = [
251235 "-lstatic=native_dep" ,
252- "-lnative_dep" ,
236+ native_link_arg ,
253237 "-Wl,--whole-archive" ,
254238 "{}/test/unit/native_deps/libalwayslink.lo" .format (bin_dir ),
255239 "-Wl,--no-whole-archive" ,
256240 ]
257241 else :
258242 want = [
259243 "-lstatic=native_dep" ,
260- "-lnative_dep" ,
244+ native_link_arg ,
261245 "--whole-archive" ,
262246 "{}/test/unit/native_deps/libalwayslink.lo" .format (bin_dir ),
263247 "--no-whole-archive" ,
@@ -280,21 +264,22 @@ def _cdylib_has_native_dep_and_alwayslink_test_impl(ctx, use_cc_linker):
280264
281265 compilation_mode = ctx .var ["COMPILATION_MODE" ]
282266 pic_suffix = _get_pic_suffix (ctx , compilation_mode )
267+ native_link_arg = _native_link_arg (ctx , action , pic_suffix , stripped = True )
283268
284269 if toolchain .target_os in ["macos" , "darwin" ]:
285270 if use_cc_linker :
286271 # When using CC linker, args are passed with -Wl, prefix as separate arguments
287272 want = [
288273 "-lstatic=native_dep{}" .format (pic_suffix ),
289- "-lnative_dep{}" . format ( pic_suffix ) ,
274+ native_link_arg ,
290275 "-Wl,-force_load" ,
291276 "-Wl,{}/test/unit/native_deps/libalwayslink{}.lo" .format (bin_dir , pic_suffix ),
292277 ]
293278 else :
294279 # When using rust-lld directly, args are passed without prefix as separate arguments
295280 want = [
296281 "-lstatic=native_dep{}" .format (pic_suffix ),
297- "-lnative_dep{}" . format ( pic_suffix ) ,
282+ native_link_arg ,
298283 "-force_load" ,
299284 "{}/test/unit/native_deps/libalwayslink{}.lo" .format (bin_dir , pic_suffix ),
300285 ]
@@ -324,6 +309,7 @@ def _cdylib_has_native_dep_and_alwayslink_test_impl(ctx, use_cc_linker):
324309 elif toolchain .target_arch == "s390x" :
325310 want = [
326311 "-lstatic=native_dep{}" .format (pic_suffix ),
312+ native_link_arg ,
327313 "link-arg=-Wl,--whole-archive" ,
328314 "link-arg={}/test/unit/native_deps/libalwayslink{}.lo" .format (bin_dir , pic_suffix ),
329315 "link-arg=-Wl,--no-whole-archive" ,
@@ -332,7 +318,7 @@ def _cdylib_has_native_dep_and_alwayslink_test_impl(ctx, use_cc_linker):
332318 # CC linker uses -Wl, prefix but arguments are separate
333319 want = [
334320 "-lstatic=native_dep{}" .format (pic_suffix ),
335- "-lnative_dep{}" . format ( pic_suffix ) ,
321+ native_link_arg ,
336322 "-Wl,--whole-archive" ,
337323 "{}/test/unit/native_deps/libalwayslink{}.lo" .format (bin_dir , pic_suffix ),
338324 "-Wl,--no-whole-archive" ,
@@ -341,7 +327,7 @@ def _cdylib_has_native_dep_and_alwayslink_test_impl(ctx, use_cc_linker):
341327 # rust-lld doesn't use -Wl, prefix, so flags and path are separate
342328 want = [
343329 "-lstatic=native_dep{}" .format (pic_suffix ),
344- "-lnative_dep{}" . format ( pic_suffix ) ,
330+ native_link_arg ,
345331 "--whole-archive" ,
346332 "{}/test/unit/native_deps/libalwayslink{}.lo" .format (bin_dir , pic_suffix ),
347333 "--no-whole-archive" ,
0 commit comments