Skip to content
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

BAZEL_USE_CPP_ONLY_TOOLCHAIN doesn't work without Xcode / Xcode CLT installed. #16009

Open
uri-canva opened this issue Jul 31, 2022 · 7 comments
Labels
P3 We're not considering working on this, but happy to review a PR. (No assignee) platform: apple team-Rules-CPP Issues for C++ rules type: bug

Comments

@uri-canva
Copy link
Contributor

Description of the bug:

BAZEL_USE_CPP_ONLY_TOOLCHAIN on Darwin is meant to disable the Xcode toolchain resolution and use the common Unix toolchain resolution based on what binaries are available on the PATH and set with environment variables. However it will still hardcode several apple tools, like /usr/bin/libtool, /usr/bin/gcc and /usr/bin/install_name_tool (in cc_wrapper.sh).

What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

# Either have an install of macOS without Xcode or Xcode CLT installed, or:
ln -s $(xcode-select -p) invalid
sudo xcode-select -s invalid
rm invalid

# try building a cc target with BAZEL_USE_CPP_ONLY_TOOLCHAIN having `libtool`, `install_name_tool` and `gcc` on your `PATH`:
BAZEL_USE_CPP_ONLY_TOOLCHAIN=1 bazel build //tools/cpp/runfiles

Expected output: successful build using the binaries on your PATH.
Actual output:

ERROR: /Users/uri/github/bazelbuild/bazel/tools/cpp/runfiles/BUILD:51:11: Compiling tools/cpp/runfiles/runfiles_src.cc failed: (Exit 1): cc_wrapper.sh failed: error executing command external/local_config_cc/cc_wrapper.sh -U_FORTIFY_SOURCE -fstack-protector -Wall -Wthread-safety -Wself-assign -Wunused-but-set-parameter -Wno-free-nonheap-object -fcolor-diagnostics ... (remaining 20 arguments skipped)

Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
xcrun: error: active developer path ("/Users/uri/github/bazelbuild/bazel/invalid") does not exist
Use `sudo xcode-select --switch path/to/Xcode.app` to specify the Xcode that you wish to use for command line developer tools, or use `xcode-select --install` to install the standalone command line developer tools.
See `man xcode-select` for more details.
Target //tools/cpp/runfiles:runfiles failed to build

Which operating system are you running Bazel on?

macOS 12.5 21G72

What is the output of bazel info release?

release 5.2.0

If bazel info release returns development version or (@non-git), tell us how you built Bazel.

No response

What's the output of git remote get-url origin; git rev-parse master; git rev-parse HEAD ?

git@github.com:bazelbuild/bazel.git
c282526c071389cd6f88cb77565283b257316267
2e8458b7810eab7829fc7d28af5c45b9af91ed7c

Have you found anything relevant by searching the web?

No response

Any other information, logs, or outputs that you want to share?

No response

@oquenchil oquenchil added P3 We're not considering working on this, but happy to review a PR. (No assignee) platform: apple and removed untriaged labels Oct 26, 2022
copybara-service bot pushed a commit that referenced this issue Jan 23, 2023
Instead of hardcoding `/usr/bin/libtool` which requires Xcode / Xcode CLT installed, which `BAZEL_USE_CPP_ONLY_TOOLCHAIN` is meant to avoid.

Related to #16009.

Closes #16010.

PiperOrigin-RevId: 503922158
Change-Id: I64392ada951938d612dd0b28141e6b2e4ee6952c
ShreeM01 added a commit that referenced this issue Jan 27, 2023
Instead of hardcoding `/usr/bin/libtool` which requires Xcode / Xcode CLT installed, which `BAZEL_USE_CPP_ONLY_TOOLCHAIN` is meant to avoid.

Related to #16009.

Closes #16010.

PiperOrigin-RevId: 503922158
Change-Id: I64392ada951938d612dd0b28141e6b2e4ee6952c

Co-authored-by: Uri Baghin <uri@canva.com>
hvadehra pushed a commit that referenced this issue Feb 14, 2023
Instead of hardcoding `/usr/bin/libtool` which requires Xcode / Xcode CLT installed, which `BAZEL_USE_CPP_ONLY_TOOLCHAIN` is meant to avoid.

Related to #16009.

Closes #16010.

PiperOrigin-RevId: 503922158
Change-Id: I64392ada951938d612dd0b28141e6b2e4ee6952c
@makslevental
Copy link

makslevental commented Mar 18, 2023

there's an additional problem here:

ERROR: /Users/mlevental/dev_projects/xls/xls/passes/BUILD:179:11: Linking xls/passes/libunroll_pass.pic.a failed: (Exit 1): sandbox-exec failed: error executing command 
  (cd /private/var/tmp/_bazel_mlevental/77aa60ef93768a50da7e847fcf47eca8/sandbox/darwin-sandbox/17524/execroot/com_google_xls && \
  exec env - \
    BAZEL_CXXOPTS='-std=c++17' \
    BAZEL_USE_CPP_ONLY_TOOLCHAIN=1 \
    PATH='/Users/mlevental/.cabal/bin:/Users/mlevental/.ghcup/bin:/opt/homebrew/opt/binutils/bin:/opt/homebrew/opt/llvm/bin:/opt/homebrew/opt/bison/bin:/opt/homebrew/opt/ruby/bin:/opt/homebrew/opt/qt@5/bin:/opt/homebrew/bin:/opt/homebrew/opt/bison/bin:/opt/homebrew/bin/:/opt/homebrew/opt/libtool/libexec/gnubin:/Users/mlevental/miniforge3/bin:/Users/mlevental/miniforge3/condabin:/Library/Frameworks/Python.framework/Versions/3.11/bin:/Library/Frameworks/Python.framework/Versions/3.10/bin:/opt/local/bin:/opt/local/sbin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/opt/X11/bin:/Library/Apple/usr/bin:/Users/mlevental/.cargo/bin:/opt/homebrew/opt/ccache/libexec:/Users/mlevental/Library/Application Support/JetBrains/Toolbox/scripts' \
    PWD=/proc/self/cwd \
    TMPDIR=/var/folders/5r/nhx6kb2j2bq9zh1lng031l800000gn/T/ \
  /usr/bin/sandbox-exec -f /private/var/tmp/_bazel_mlevental/77aa60ef93768a50da7e847fcf47eca8/sandbox/darwin-sandbox/17524/sandbox.sb /var/tmp/_bazel_mlevental/install/492267a38d620c777a8b281ba7e366a6/process-wrapper '--timeout=0' '--kill_delay=15' '--stats=/private/var/tmp/_bazel_mlevental/77aa60ef93768a50da7e847fcf47eca8/sandbox/darwin-sandbox/17524/stats.out' /opt/homebrew/opt/libtool/libexec/gnubin/libtool @bazel-out/darwin_arm64-opt/bin/xls/passes/libunroll_pass.pic.a-2.params)
libtool:   error: you must specify an output file
Usage: /opt/homebrew/opt/libtool/libexec/gnubin/libtool [OPTION]... [MODE-ARG]...
Try 'libtool --help' for more information.

I.e., that while the GNU libtool is found, it's not passed the correct argument; I tried patching libtool itself (because I don't know how to configure which options to pass it through bazel itself) and in addition to the mode (link) you need to pass --tag and the output file name. The lack of these three things (and possibly others) is preventing me from compiling a bazel project on my M1.

Uninstalled gnu libtool then gets me back to apple's libtool but then symbols aren't resolved at runtime (despite successful linking during the link stage).

Copy link

Thank you for contributing to the Bazel repository! This issue has been marked as stale since it has not had any activity in the last 1+ years. It will be closed in the next 90 days unless any other activity occurs. If you think this issue is still relevant and should stay open, please post any comment here and the issue will no longer be marked as stale.

@github-actions github-actions bot added the stale Issues or PRs that are stale (no activity for 30 days) label May 22, 2024
@uri-canva
Copy link
Contributor Author

Just checked, there are still references to /usr/bin/xcrun in the wrapper.

@keith
Copy link
Member

keith commented May 22, 2024

Fwiw I don't think there was ever a goal of supporting builds without even the CLT. I imagine the best solution if you wanted that would be to use a custom cc toolchain like toolchains_llvm. I think some changes would still be required though.

@uri-canva
Copy link
Contributor Author

I think builds without that environment variable already work with CLT and without Xcode though. I thought it was meant to support toolchains provided through other means like brew etc.

If not then maybe it's pointless to have it?

@keith
Copy link
Member

keith commented May 22, 2024

The point is to allow you to use the CLT without a full Xcode install (and has the side benefit of making your build more similar to Linux builds if you care about cross platform, at the cost of some platform specific improvements)

@github-actions github-actions bot removed the stale Issues or PRs that are stale (no activity for 30 days) label May 23, 2024
@uri-canva
Copy link
Contributor Author

What I mean is that bazel never needed full Xcode install as far as I remember, regardless of whether you use BAZEL_USE_CPP_ONLY_TOOLCHAIN. Maybe it was necessary in older, pre-open source versions?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P3 We're not considering working on this, but happy to review a PR. (No assignee) platform: apple team-Rules-CPP Issues for C++ rules type: bug
Projects
None yet
Development

No branches or pull requests

5 participants