Skip to content

Commit 1f4a216

Browse files
hdgarroodmeta-codesync[bot]
authored andcommitted
Fix clang-specific cc/cxx invocations in cargo_buildscript (#1373)
Summary: After updating to a version of buck2 that included these changes (using bundled prelude), we started seeing the following when building the `openssl-sys` crate via a Reindeer-generated BUCK file: ``` Header expansion error: Error { kind: ToolExecError, message: "command did not execute successfully (status code exit status: 1): LC_ALL="C" "…/__openssl-sys-0.9-build-script-main-run__/74052bece190009d/__cc_shim.sh" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "-m64" "-I" "../../../../../../toolchains/b42aeba648b8c415/__openssl_includes__/out.link-dev/include" "-Wall" "-Wextra" "-E" "build/expando.c"" } Failed to find OpenSSL development headers. ``` The real error (which, unfortunately, is not shown) is that `--ld-path` is a clang-specific flag - or at least, that it is not recognized by gcc. It seems a little unlikely to me that buildscripts need to access the linker in general so I'm not sure we necessarily need to be passing `--ld-path` at all? But this change should at least expand the set of cargo build scripts that can successfully run with gcc toolchains, without affecting clang. I've tested this in the context of Mercury's monorepo and I'm confident it works there, but I'm struggling a bit to set up a reproducer/test outside of the context of that monorepo. Can you help me figure out whether this should be accompanied by a test, and if so what kind of test? Pull Request resolved: #1373 Reviewed By: diliop Differential Revision: D112153850 Pulled By: dtolnay fbshipit-source-id: 4499512f7f6df065576127917daafcf1716bae33
1 parent 0d3d7c2 commit 1f4a216

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

prelude/rust/cargo_buildscript.bzl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,8 @@ def _cargo_buildscript_impl(ctx: AnalysisContext) -> list[Provider]:
304304
)
305305
deps_link = deps_tset.project_as_args("default")
306306
sanitizer_flags = ["-fno-sanitize=all"]
307+
cc_is_clang = cxx_toolchain_info.c_compiler_info.compiler_type.startswith("clang")
308+
cxx_is_clang = cxx_toolchain_info.cxx_compiler_info.compiler_type.startswith("clang")
307309
env["LD"] = _make_cc_shim(
308310
ctx = ctx,
309311
name = "__ld_shim",
@@ -319,7 +321,7 @@ def _cargo_buildscript_impl(ctx: AnalysisContext) -> list[Provider]:
319321
name = "__cc_shim",
320322
cmd = cmd_args(
321323
cxx_toolchain_info.c_compiler_info.compiler,
322-
cmd_args(env["LD"], format = "--ld-path={}"),
324+
cmd_args(env["LD"], format = "--ld-path={}") if cc_is_clang else cmd_args(),
323325
cxx_toolchain_info.c_compiler_info.preprocessor_flags,
324326
cxx_toolchain_info.c_compiler_info.compiler_flags,
325327
deps_preprocessor_flags,
@@ -334,7 +336,7 @@ def _cargo_buildscript_impl(ctx: AnalysisContext) -> list[Provider]:
334336
name = "__cxx_shim",
335337
cmd = cmd_args(
336338
cxx_toolchain_info.cxx_compiler_info.compiler,
337-
cmd_args(env["LD"], format = "--ld-path={}"),
339+
cmd_args(env["LD"], format = "--ld-path={}") if cxx_is_clang else cmd_args(),
338340
cxx_toolchain_info.cxx_compiler_info.preprocessor_flags,
339341
cxx_toolchain_info.cxx_compiler_info.compiler_flags,
340342
deps_preprocessor_flags,

0 commit comments

Comments
 (0)