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

Substitute ${SDKROOT} and ${DEVELOPER_DIR} by their environment variables on darwin. #2619

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 18 additions & 2 deletions bindgen/private/bindgen.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,22 @@ def _rust_bindgen_impl(ctx):

args = ctx.actions.args()

executable = bindgen_bin

# When running on darwin, we have to forward the SDKROOT environment variable,
# otherwise some system include files may not be found if the clang compiled
# from source is being used.
# Since the sdk directory given by the apple toolchain[1] may be a dummy
# variable, we have to use the process_wrapper.
#
# [1]: https://bazel.build/rules/lib/builtins/apple_toolchain.html#sdk_dir
if apple_common != None:
args.add_all(["--subst", "SDKROOT=${SDKROOT}"])
args.add_all(["--subst", "DEVELOPER_DIR=${DEVELOPER_DIR}"])
args.add_all(["--", bindgen_bin])
tools = depset([bindgen_bin], transitive = [tools])
executable = ctx.executable._process_wrapper

# Configure Bindgen Arguments
args.add_all(ctx.attr.bindgen_flags)
args.add(header)
Expand Down Expand Up @@ -266,7 +282,7 @@ def _rust_bindgen_impl(ctx):
env["DYLD_LIBRARY_PATH"] = env["LD_LIBRARY_PATH"]

ctx.actions.run(
executable = bindgen_bin,
executable = executable,
inputs = depset(
[header],
transitive = [
Expand Down Expand Up @@ -359,7 +375,7 @@ rust_bindgen_toolchain = rule(
doc = """\
The tools required for the `rust_bindgen` rule.

This rule depends on the [`bindgen`](https://crates.io/crates/bindgen) binary crate, and it
This rule depends on the [`bindgen`](https://crates.io/crates/bindgen) binary crate, and it
in turn depends on both a clang binary and the clang library. To obtain these dependencies,
`rust_bindgen_dependencies` imports bindgen and its dependencies.

Expand Down
2 changes: 1 addition & 1 deletion docs/flatten.md
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ rust_bindgen_toolchain(<a href="#rust_bindgen_toolchain-name">name</a>, <a href=

The tools required for the `rust_bindgen` rule.

This rule depends on the [`bindgen`](https://crates.io/crates/bindgen) binary crate, and it
This rule depends on the [`bindgen`](https://crates.io/crates/bindgen) binary crate, and it
in turn depends on both a clang binary and the clang library. To obtain these dependencies,
`rust_bindgen_dependencies` imports bindgen and its dependencies.

Expand Down
2 changes: 1 addition & 1 deletion docs/rust_bindgen.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ rust_bindgen_toolchain(<a href="#rust_bindgen_toolchain-name">name</a>, <a href=

The tools required for the `rust_bindgen` rule.

This rule depends on the [`bindgen`](https://crates.io/crates/bindgen) binary crate, and it
This rule depends on the [`bindgen`](https://crates.io/crates/bindgen) binary crate, and it
in turn depends on both a clang binary and the clang library. To obtain these dependencies,
`rust_bindgen_dependencies` imports bindgen and its dependencies.

Expand Down
11 changes: 7 additions & 4 deletions util/process_wrapper/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,14 @@ pub(crate) fn options() -> Result<Options, OptionError> {
OptionError::Generic(format!("empty key for substitution '{arg}'"))
})?;
let v = if val == "${pwd}" {
current_dir.as_str()
current_dir.as_str().to_owned()
} else if val == "${SDKROOT}" {
std::env::var("SDKROOT").unwrap_or(val.to_owned())
} else if val == "${DEVELOPER_DIR}" {
std::env::var("DEVELOPER_DIR").unwrap_or(val.to_owned())
} else {
val
}
.to_owned();
val.to_owned()
};
Ok((key.to_owned(), v))
})
.collect::<Result<Vec<(String, String)>, OptionError>>()?;
Expand Down