Skip to content

Commit

Permalink
Ensure /usr/bin is in PATH for macOS
Browse files Browse the repository at this point in the history
This is an alternative fix to what was included in #105.
  • Loading branch information
Siddhartha Bagaria committed Sep 26, 2021
1 parent 8c24bfd commit e2e4b64
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,8 @@ the / read-only mount. Note that this will make your builds non-hermetic.

#### Compatibility

The toolchain is tested to work with `rules_go` and `rules_foreign_cc`.
The toolchain is tested to work with `rules_go`, `rules_rust`, and
`rules_foreign_cc`.

#### Accessing tools

Expand Down
8 changes: 4 additions & 4 deletions toolchain/internal/repo.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def llvm_repo_impl(rctx):

_download_llvm_preconfigured(rctx)

# darwin may use local 'ld' so symlink it to bin directory to help
# other programs locate it when called directly (e.g. rustc)
if os == "darwin":
rctx.symlink("/usr/bin/ld", "bin/ld")
# We try to avoid patches to the downloaded repo so that it is easier for
# users to bring their own LLVM distribution through `http_archive`. If we
# do want to make changes, then we should do it through a patch file, and
# document it for users of toolchain_roots attribute.
12 changes: 12 additions & 0 deletions toolchain/osx_cc_wrapper.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,18 @@ for i in "$@"; do
fi
done

# On macOS, we use ld as the linker for single-platform builds. Some
# applications may remove /usr/bin from PATH before calling this script, which
# would make /usr/bin/ld unreachable.
# For example, rules_rust sets PATH to be /bin.
# https://github.com/rust-lang/rust/blob/308dffd25cb55bbb4a1fbee9822cf82c6a5d012d/compiler/rustc_session/src/session.rs#L804-L813
# Let's restore /usr/bin to PATH in such cases. Note that /usr/bin is not a
# writeable directory on macOS even with sudo privileges, so it should be safe
# to add it to PATH even when the application wants to use a very strict PATH.
if [[ ":${PATH}:" != *":/usr/bin:"* ]]; then
PATH="${PATH}:/usr/bin"
fi

# Call the C++ compiler.
if [[ -f %{toolchain_path_prefix}bin/clang ]]; then
%{toolchain_path_prefix}bin/clang "$@"
Expand Down

0 comments on commit e2e4b64

Please sign in to comment.