bazelbuild / bazelbuild/rules_cc

configure_unix_toolchain: Allow overriding path to libtool on macOS

Closed
#122 1 comment 1 reaction 0 assignees View on GitHub
P3
Dominant language
Starlark
Stars
247
Forks
196
PR merge metrics
No merged PRs in 30d

Description

### Description of the problem / feature request:

The path to the archive manipulation tool is hardcoded on macOS
https://github.com/bazelbuild/rules_cc/blob/081771d4a0e9d7d3aa0eed2ef389fa4700dfb23e/cc/private/toolchain/unix_cc_configure.bzl#L375
It would be nice to have a mechanizm to override this value externally, for example by adding a `AR`/`BAZEL_AR` environment variable.

### Feature requests: what underlying problem are you trying to solve with this feature?

In nixpkgs we build our own toolchain for macOS from open source components. The static library builds rely on ar, and rules_cc hardcode it to be called at `/usr/bin/libtool`, which does not belong to our toolchain. Our builds are supposed to not rely on Apple SDK, and, in fact, it need not be even installed. We would like to supply our working version of libtool, the same way we specify `CC`, but apparently there isn't a way to do so.

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

### What operating system are you running Bazel on?

macOS

### What's the output of `bazel info release`?

release 3.7.2- (@non-git)

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

### What version of rules_cc do you use? Can you paste the workspace rule used to fetch rules_cc? What other relevant dependencies does your project have?

Same as tensorflow 2.7.0: 01d4a48911d5e7591ecb1c06d3b8af47fe872371

### What Bazel options do you use to trigger the issue? What C++ toolchain do you use?

The toolchain is "stdenv" for x86_64-darwin from nixpkgs based on:
```
clang version 7.1.0 (tags/RELEASE_710/final)
```

### Have you found anything relevant by searching the web?

No

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

> ERROR: /private/tmp/nix-build-tensorflow-2.7.0.drv-0/output/external/com_google_protobuf/BUILD:301:11: Linking of rule '@com_google_protobuf//:protoc_lib' failed (Exit 1): libtool failed: error executing command /usr/bin/libtool -static -s -o bazel-out/host/bin/external/com_google_protobuf/libprotoc_lib.a bazel-out/host/bin/external/com_google_protobuf/_objs/protoc_lib/code_generator.o ... (remaining 80 argument(s) skipped)

Contributor guide

Open the contributing guide

Research direction

Start at cc/private/toolchain/unix_cc_configure.bzl around line 375, where the macOS archive tool is hardcoded as /usr/bin/libtool. Trace how the existing CC setting is supplied and determine how an external AR or BAZEL_AR override should reach the toolchain. Done means a nixpkgs-provided libtool can be selected without relying on the Apple SDK, with the failing static-library link no longer invoking /usr/bin/libtool.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
build-system
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.