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

Solving complex build.rs issues #48

Open
pnathan opened this issue Jun 30, 2024 · 2 comments
Open

Solving complex build.rs issues #48

pnathan opened this issue Jun 30, 2024 · 2 comments

Comments

@pnathan
Copy link

pnathan commented Jun 30, 2024

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?

@jsgf
Copy link
Contributor

jsgf commented Jul 8, 2024

That looks like a fairly normal gen_srcs fixup with env to set MIME_TYPES_GENERATED_PATH.

@Lev1ty
Copy link

Lev1ty commented Aug 4, 2024

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"],
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants