-
-
Notifications
You must be signed in to change notification settings - Fork 219
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Symlink '/usr/bin/ld' to llvm toolchain directory on Mac #105
Symlink '/usr/bin/ld' to llvm toolchain directory on Mac #105
Conversation
Mac systems still use the local `ld` executable since `lld.ld` is still experimental. Some applications, e.g. rustc when compiling rust, expect to find `ld` within the same directory as the compiler and so when compiling rust we run into an issue where the linker is not found. The first immediate solution is to use the rust rule's `extra_rustc_flags` to specify the linker explicitly (via `-Clinker=/usr/bin/ld`. This works for some crates but fails for crates using a build script, since the extra flags are not propogated to rustc invocations within the exec configuration. Another solution attempt was to link `ld` into the toolchain configuration repository instead of directly in the llvm repository, such that `ld` becomes a sibling file to `cc_wrapper.sh`. Unfortunately rustc was still unable to find the linker with this configuration. The final fully working solution is to link `ld` into the bin folder of the llvm repository. This should be fine as LLVM's own linker exists under `ld.lld` and symlinking the local linker will not clobber any files.
Thank you for the PR. We used to do this when GoCompile had the same problem. I removed these symlinks in 6e42888 because Go rules did not need it anymore. Will you be able to add some tests for Rust in the run_external_tests.sh script so we can track compatibility? |
I picked `git2-rs` since it links against a C library and has tests but isn't _massive_. There are a couple of hacks/patches here to workaround some bugs in `rules_rust`'s `crate-universe` but on the whole it's not too messy.
I'm still a little confused about why/how I added a test to |
@siddharthab Adding I can think of three ways to get around this:
I'm partial to the third option but whatever you think is best works. As a sidenote: we don't actually seem to run |
I would not worry too much about the migration failure. Just adding an exception in run_tests.sh (option 1) seems fine. If possible, file an issue with rules_rust and mention the issue in comments before our exception. For run_external_tests.sh, we can remove the block that adds migration check flags. I don't think I put too much thought into it when I added it there. |
91c8ca4
to
051b8b2
Compare
The force push was a mistake -- thought I accidentally pushed some commits, didn't realise there was some other work done on the branch. Have reverted that. |
The rules_rust repository is incompatible with this flag enabled. Have disabled it for now.
Flag already added to 'run_external_tests.sh' but also needed here.
Added the appropriate flag to |
Was sure I saw a message requesting to remove the |
Note that this also drops the check for `$TEST_MIGRATION` in run_external_tests.sh; we don't run that script in migration.yml
This was the message I think. I've removed that bit from |
I did a little more digging;
I'm still a little confused why we only seem to run into this when Regardless, I think this PR is good to go . |
That's because in that function, PATH is set to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will merge this as-is and then maybe commit some more changes to clean up later.
Sorry, that snippet is a little misleading; The actual bazel-out/darwin-opt-exec-2B5CBBC6/bin/external/rules_rust/util/process_wrapper/process_wrapper --subst 'pwd=${pwd}' -- external/rust_darwin_x86_64/bin/rustc external/crates__log__0_4_14/build.rs '--crate-name=log_build_script_script_' '--crate-type=bin' '--error-format=human' '--codegen=metadata=' '--out-dir=bazel-out/darwin-opt-exec-2B5CBBC6/bin/external/crates__log__0_4_14' '--codegen=extra-filename=' '--codegen=opt-level=3' '--codegen=debuginfo=0' '--remap-path-prefix=${pwd}=.' '--emit=dep-info,link' '--color=always' '--target=x86_64-apple-darwin' -L external/rust_darwin_x86_64/lib/rustlib/x86_64-apple-darwin/lib '--cap-lints=allow' '--codegen=linker=external/llvm_toolchain/bin/cc_wrapper.sh' --codegen 'link-args=-mlinker-version=450 --target=x86_64-apple-macosx -lm -no-canonical-prefixes -headerpad_max_install_names -undefined dynamic_lookup -lc++ -lc++abi --sysroot=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk' (note the Which then leads to a cc_wrapper.sh invocation that looks like this: "external/llvm_toolchain/bin/cc_wrapper.sh" "-m64" "-arch" "x86_64" "bazel-out/darwin-opt-exec-2B5CBBC6/bin/external/crates__log__0_4_14/log_build_script_script_.log_build_script_script_.11355ed9-cgu.0.rcgu.o" "bazel-out/darwin-opt-exec-2B5CBBC6/bin/external/crates__log__0_4_14/log_build_script_script_.log_build_script_script_.11355ed9-cgu.1.rcgu.o" "bazel-out/darwin-opt-exec-2B5CBBC6/bin/external/crates__log__0_4_14/log_build_script_script_.log_build_script_script_.11355ed9-cgu.2.rcgu.o" "bazel-out/darwin-opt-exec-2B5CBBC6/bin/external/crates__log__0_4_14/log_build_script_script_.log_build_script_script_.11355ed9-cgu.3.rcgu.o" "bazel-out/darwin-opt-exec-2B5CBBC6/bin/external/crates__log__0_4_14/log_build_script_script_.log_build_script_script_.11355ed9-cgu.4.rcgu.o" "bazel-out/darwin-opt-exec-2B5CBBC6/bin/external/crates__log__0_4_14/log_build_script_script_.log_build_script_script_.11355ed9-cgu.5.rcgu.o" "bazel-out/darwin-opt-exec-2B5CBBC6/bin/external/crates__log__0_4_14/log_build_script_script_.log_build_script_script_.11355ed9-cgu.6.rcgu.o" "bazel-out/darwin-opt-exec-2B5CBBC6/bin/external/crates__log__0_4_14/log_build_script_script_.log_build_script_script_.11355ed9-cgu.7.rcgu.o" "bazel-out/darwin-opt-exec-2B5CBBC6/bin/external/crates__log__0_4_14/log_build_script_script_.log_build_script_script_.11355ed9-cgu.8.rcgu.o" "bazel-out/darwin-opt-exec-2B5CBBC6/bin/external/crates__log__0_4_14/log_build_script_script_.5esazdxjfc5wg0qb.rcgu.o" "-L" "external/rust_darwin_x86_64/lib/rustlib/x86_64-apple-darwin/lib" "-L" "/private/var/tmp/_bazel_rahulbutani/729ef14ca5fc8012394a84396ed546ff/external/rust_darwin_x86_64/lib/rustlib/x86_64-apple-darwin/lib" "/private/var/tmp/_bazel_rahulbutani/729ef14ca5fc8012394a84396ed546ff/external/rust_darwin_x86_64/lib/rustlib/x86_64-apple-darwin/lib/libstd-35b14ca5e62c7d66.rlib" "/private/var/tmp/_bazel_rahulbutani/729ef14ca5fc8012394a84396ed546ff/external/rust_darwin_x86_64/lib/rustlib/x86_64-apple-darwin/lib/libpanic_unwind-329b6ae10a542427.rlib" "/private/var/tmp/_bazel_rahulbutani/729ef14ca5fc8012394a84396ed546ff/external/rust_darwin_x86_64/lib/rustlib/x86_64-apple-darwin/lib/libobject-09e9356fd4907aa1.rlib" "/private/var/tmp/_bazel_rahulbutani/729ef14ca5fc8012394a84396ed546ff/external/rust_darwin_x86_64/lib/rustlib/x86_64-apple-darwin/lib/libaddr2line-f077c0a492da74c3.rlib" "/private/var/tmp/_bazel_rahulbutani/729ef14ca5fc8012394a84396ed546ff/external/rust_darwin_x86_64/lib/rustlib/x86_64-apple-darwin/lib/libgimli-01a2a2a1730ab072.rlib" "/private/var/tmp/_bazel_rahulbutani/729ef14ca5fc8012394a84396ed546ff/external/rust_darwin_x86_64/lib/rustlib/x86_64-apple-darwin/lib/libstd_detect-736ff6c48d99c951.rlib" "/private/var/tmp/_bazel_rahulbutani/729ef14ca5fc8012394a84396ed546ff/external/rust_darwin_x86_64/lib/rustlib/x86_64-apple-darwin/lib/librustc_demangle-f6b7985fe24842c3.rlib" "/private/var/tmp/_bazel_rahulbutani/729ef14ca5fc8012394a84396ed546ff/external/rust_darwin_x86_64/lib/rustlib/x86_64-apple-darwin/lib/libhashbrown-6ccb889196a16125.rlib" "/private/var/tmp/_bazel_rahulbutani/729ef14ca5fc8012394a84396ed546ff/external/rust_darwin_x86_64/lib/rustlib/x86_64-apple-darwin/lib/librustc_std_workspace_alloc-2bda93c117f030a0.rlib" "/private/var/tmp/_bazel_rahulbutani/729ef14ca5fc8012394a84396ed546ff/external/rust_darwin_x86_64/lib/rustlib/x86_64-apple-darwin/lib/libunwind-bcbd09b25c64fcac.rlib" "/private/var/tmp/_bazel_rahulbutani/729ef14ca5fc8012394a84396ed546ff/external/rust_darwin_x86_64/lib/rustlib/x86_64-apple-darwin/lib/libcfg_if-ef7e97011650176d.rlib" "/private/var/tmp/_bazel_rahulbutani/729ef14ca5fc8012394a84396ed546ff/external/rust_darwin_x86_64/lib/rustlib/x86_64-apple-darwin/lib/liblibc-104a032674bfeab8.rlib" "/private/var/tmp/_bazel_rahulbutani/729ef14ca5fc8012394a84396ed546ff/external/rust_darwin_x86_64/lib/rustlib/x86_64-apple-darwin/lib/liballoc-ba3aef5f5e0e8573.rlib" "/private/var/tmp/_bazel_rahulbutani/729ef14ca5fc8012394a84396ed546ff/external/rust_darwin_x86_64/lib/rustlib/x86_64-apple-darwin/lib/librustc_std_workspace_core-9ee1c33f7a829255.rlib" "/private/var/tmp/_bazel_rahulbutani/729ef14ca5fc8012394a84396ed546ff/external/rust_darwin_x86_64/lib/rustlib/x86_64-apple-darwin/lib/libcore-20d0dacb579b8ca8.rlib" "/private/var/tmp/_bazel_rahulbutani/729ef14ca5fc8012394a84396ed546ff/external/rust_darwin_x86_64/lib/rustlib/x86_64-apple-darwin/lib/libcompiler_builtins-2fee5b6fdc3293e9.rlib" "-lSystem" "-lresolv" "-lc" "-lm" "-liconv" "-L" "/private/var/tmp/_bazel_rahulbutani/729ef14ca5fc8012394a84396ed546ff/external/rust_darwin_x86_64/lib/rustlib/x86_64-apple-darwin/lib" "-o" "bazel-out/darwin-opt-exec-2B5CBBC6/bin/external/crates__log__0_4_14/log_build_script_script_" "-Wl,-dead_strip" "-nodefaultlibs" "-mlinker-version=450" "--target=x86_64-apple-macosx" "-lm" "-no-canonical-prefixes" "-headerpad_max_install_names" "-undefined" "dynamic_lookup" "-lc++" "-lc++abi" "--sysroot=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk" I can try to run the |
This is an alternative fix to what was included in #105.
edit: whoops, just saw the other PR |
This is an alternative fix to what was included in #105.
You can verify my claim by adding a |
@siddharthab you're absolutely right; good catch I'm still fairly convinced it's not |
This is an alternative fix to what was included in #105.
This is an alternative fix to what was included in #105.
This is an alternative fix to what was included in #105.
This is an alternative fix to what was included in #105.
This is an alternative fix to what was included in #105.
This is an alternative fix to what was included in #105.
This is an alternative fix to what was included in #105.
Mac systems still use the local
ld
executable sincelld.ld
is stillexperimental. Some applications, e.g. rustc when compiling rust, expect
to find
ld
within the same directory as the compiler and so whencompiling rust we run into an issue where the linker is not found.
The first immediate solution is to use the rust rule's
extra_rustc_flags
to specify the linker explicitly (via-Clinker=/usr/bin/ld
. This works for some crates but fails for cratesusing a build script, since the extra flags are not propogated to rustc
invocations within the exec configuration.
Another solution attempt was to link
ld
into the toolchainconfiguration repository instead of directly in the llvm repository,
such that
ld
becomes a sibling file tocc_wrapper.sh
. Unfortunatelyrustc was still unable to find the linker with this configuration.
The final fully working solution is to link
ld
into the bin folder ofthe llvm repository. This should be fine as LLVM's own linker exists
under
ld.lld
and symlinking the local linker will not clobber anyfiles.