@@ -460,7 +460,9 @@ def construct_arguments(
460
460
build_flags_files ,
461
461
emit = ["dep-info" , "link" ],
462
462
force_all_deps_direct = False ,
463
- stamp = False ):
463
+ force_link = False ,
464
+ stamp = False ,
465
+ remap_path_prefix = "." ):
464
466
"""Builds an Args object containing common rustc flags
465
467
466
468
Args:
@@ -482,8 +484,10 @@ def construct_arguments(
482
484
emit (list): Values for the --emit flag to rustc.
483
485
force_all_deps_direct (bool, optional): Whether to pass the transitive rlibs with --extern
484
486
to the commandline as opposed to -L.
487
+ force_link (bool, optional): Whether to add link flags to the command regardless of `emit`.
485
488
stamp (bool, optional): Whether or not workspace status stamping is enabled. For more details see
486
489
https://docs.bazel.build/versions/main/user-manual.html#flag--stamp
490
+ remap_path_prefix (str, optional): A value used to remap `${pwd}` to. If set to a falsey value, no prefix will be set.
487
491
488
492
Returns:
489
493
tuple: A tuple of the following items
@@ -543,7 +547,7 @@ def construct_arguments(
543
547
# variables like `CARGO_BIN_EXE_${binary_name}` it will use the - version
544
548
# not the _ version. So we rename the rustc-generated file (with _s) to
545
549
# have -s if needed.
546
- emit_with_paths = emit
550
+ emit_with_paths = emit or []
547
551
if crate_info .type == "bin" and crate_info .output != None :
548
552
generated_file = crate_info .name + toolchain .binary_ext
549
553
src = "/" .join ([crate_info .output .dirname , generated_file ])
@@ -576,9 +580,11 @@ def construct_arguments(
576
580
rustc_flags .add ("--codegen=debuginfo=" + compilation_mode .debug_info )
577
581
578
582
# For determinism to help with build distribution and such
579
- rustc_flags .add ("--remap-path-prefix=${pwd}=." )
583
+ if remap_path_prefix :
584
+ rustc_flags .add ("--remap-path-prefix=${{pwd}}={}" .format (remap_path_prefix ))
580
585
581
- rustc_flags .add ("--emit=" + "," .join (emit_with_paths ))
586
+ if emit :
587
+ rustc_flags .add ("--emit=" + "," .join (emit_with_paths ))
582
588
rustc_flags .add ("--color=always" )
583
589
rustc_flags .add ("--target=" + toolchain .target_flag_value )
584
590
if hasattr (attr , "crate_features" ):
@@ -604,11 +610,14 @@ def construct_arguments(
604
610
add_edition_flags (rustc_flags , crate_info )
605
611
606
612
# Link!
607
- if "link" in emit :
613
+ if "link" in emit or force_link :
608
614
# Rust's built-in linker can handle linking wasm files. We don't want to attempt to use the cc
609
615
# linker since it won't understand.
610
616
if toolchain .target_arch != "wasm32" :
611
- rpaths = _compute_rpaths (toolchain , output_dir , dep_info )
617
+ if output_dir :
618
+ rpaths = _compute_rpaths (toolchain , output_dir , dep_info )
619
+ else :
620
+ rpaths = depset ([])
612
621
ld , link_args , link_env = get_linker_and_args (ctx , attr , cc_toolchain , feature_configuration , rpaths )
613
622
env .update (link_env )
614
623
rustc_flags .add ("--codegen=linker=" + ld )
0 commit comments