-
Notifications
You must be signed in to change notification settings - Fork 32
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
Solving complex build.rs issues #48
Comments
That looks like a fairly normal |
Hacked it into working for now. The issue is that the env option sets the variable for both build script and library. So had to find a way to manually resolve the path. Please let me know if there is a better alternative! # fixup.toml
version = "=2.0.5"
[env]
# HACK: In place of $(location :mime_guess-2.0.5-build-script-run[out_dir])/mime_types_generated.rs
# The correct method causes cyclic dependency because the variable is set for both:
# :mime_guess-2.0.5 [library]
# :mime_guess-2.0.5-build-script-build [binary]
# the latter of which is a dependency of :mime_guess-2.0.5-build-script-run[out_dir].
# This only works because the OUT_DIR (set by buildscript.gen_srcs) depends on :mime_guess-2.0.5-build-script-run[out_dir].
MIME_TYPES_GENERATED_PATH = "$(location //third-party:third-party)/../../../rust/__mime_guess-2.0.5-build-script-run__/OUT_DIR/mime_types_generated.rs"
[[buildscript]]
[buildscript.gen_srcs] # third-party BUCK
genrule(name = "third-party", cmd = "echo third-party> $OUT", out = "third-party", visibility = ["PUBLIC"])
# generated BUCK
cargo.rust_library(
name = "mime_guess-2.0.5",
srcs = [":mime_guess-2.0.5.crate"],
crate = "mime_guess",
crate_root = "mime_guess-2.0.5.crate/src/lib.rs",
edition = "2015",
env = {
"MIME_TYPES_GENERATED_PATH": "$(location //third-party:third-party)/../../../rust/__mime_guess-2.0.5-build-script-run__/OUT_DIR/mime_types_generated.rs",
"OUT_DIR": "$(location :mime_guess-2.0.5-build-script-run[out_dir])",
},
rustc_flags = ["@$(location :mime_guess-2.0.5-build-script-run[rustc_flags])"],
visibility = [],
deps = [
":mime-0.3.17",
":unicase-2.7.0",
],
)
cargo.rust_binary(
name = "mime_guess-2.0.5-build-script-build",
srcs = [":mime_guess-2.0.5.crate"],
crate = "build_script_build",
crate_root = "mime_guess-2.0.5.crate/build.rs",
edition = "2015",
env = {
"MIME_TYPES_GENERATED_PATH": "$(location //third-party:third-party)/../../../rust/__mime_guess-2.0.5-build-script-run__/OUT_DIR/mime_types_generated.rs",
},
visibility = [],
deps = [":unicase-2.7.0"],
) |
Usually in this situation I would just submit a PR to the crate in question that makes the build script easier to adapt. In this case by not writing an additional environment variable, rather just writing include!(concat!(env!("OUT_DIR"), "/mime_types_generated.rs")); This is the standard way to do it. But if this pops up again, there is also rust-lang/rust#80792 which would work with this change to the prelude: --- a/prelude/rust/tools/buildscript_run.py
+++ b/prelude/rust/tools/buildscript_run.py
@@ -214,11 +214,14 @@
script_output = run_buildscript(args.buildscript, env=env, cwd=cwd)
cargo_rustc_cfg_pattern = re.compile("^cargo:rustc-cfg=(.*)")
+ cargo_rustc_env_pattern = re.compile("^cargo:rustc-env=(.*)")
flags = ""
for line in script_output.split("\n"):
- cargo_rustc_cfg_match = cargo_rustc_cfg_pattern.match(line)
- if cargo_rustc_cfg_match:
- flags += "--cfg={}\n".format(cargo_rustc_cfg_match.group(1))
+ if match := cargo_rustc_cfg_pattern.match(line):
+ flags += "--cfg={}\n".format(match.group(1))
+ elif match := cargo_rustc_env_pattern.match(line):
+ # Only works on nightly for now https://github.com/rust-lang/rust/issues/80792
+ flags += "--env-set={}\n".format(match.group(1))
else:
print(line, end="\n")
args.outfile.write(flags) |
Hi,
I'm experimenting with converting my cargo project to buck and I found that I have mime-guess as a dependency about 3 levels down. Its build.rs is really quite special! https://github.com/abonander/mime_guess/blob/master/build.rs
How should I address this in the fixup?
The text was updated successfully, but these errors were encountered: