google / cargo-raze

Generate Bazel BUILD from Cargo dependencies!
Apache License 2.0
478 stars 104 forks source link

Allow passing custom environment variables, build deps and data deps to build scripts #287

Open sitaktif opened 3 years ago

sitaktif commented 3 years ago

Sometimes, crate build scripts need additional environment variables or addition build/data dependencies to run correctly in a given bazel repository.

For example, to use a custom-built openssl, one might want to pass the following to the cargo_build_script rule of a crate:

build_script_env = {
        "OPENSSL_DIR": "../openssl/openssl",
    },
    data = [...] + [
        "@openssl",  # Custom openssl.
    ],

We would need a way for the user to express these build script requirements, probably in the Cargo.toml file.

palfrey commented 3 years ago

actix_web needs this to exclude the tests/test space.binary from the default glob for data

jgao54 commented 2 years ago

Encountered a similar issue where jemalloc-sys 0.3.2's build script expect cargo's NUM_JOBS.

Ended up working around the issue by setting the env var in bazelrc build --action_env=NUM_JOBS=<num_jobs>

It would be preferable to be able to set build_script_env for specified crates, similar to additional_env.