A cargo subcommand to generate platform-specific BUILD files.
You like cargo's package rich ecosystem, but are interested in using Bazel to build a multilanguage, large, or otherwise complex set of applications.
So far you've either stuck with Cargo and made do with build.rs
files, or migrated to Bazel and avoided crates.io
dependencies or manually generated a select set of BUILD files for vendored dependencies.
cargo raze
gives you the best of both worlds: rust library downloading + resolution courtesy of Cargo with the power and scalability of Bazel.
In a directory containing 'Cargo.toml'
cargo install cargo-vendor
cargo install cargo-raze
cargo generate_lockfile
cargo vendor -x
cargo raze
You dependencies each get a shiny new Cargo.bzl
file that bazel can use to link your dependencies up.
Next, visit bazel-raze to see how to include these dependencies in your project.
cargo raze
uses Cargo's own internal dependency resolution, feature flag propagation, and platform introspection to link the vendored dependencies properly for your platform.
```python """ cargo-raze generated details for net2-0.2.29.
Generated for: platformtriple: x8664-unknown-linux-gnu platformattrs: [ "debugassertions", "targetarch: x8664", "targetendian: little", "targetenv: gnu", "targetfamily: unix", "targetfeature: sse", "targetfeature: sse2", "targethasatomic: 16", "targethasatomic: 32", "targethasatomic: 64", "targethasatomic: 8", "targethasatomic: ptr", "targetos: linux", "targetpointerwidth: 64", "targetthreadlocal", "target_vendor: unknown", "unix" ]
DO NOT MODIFY! Instead, add a CargoOverride.bzl mixin. """ description = struct( package = struct( pkgname = "net2", pkgversion = "0.2.29", ), dependencies = [ struct( name = "cfg-if", version = "0.1.0", ), struct( name = "libc", version = "0.2.22", ), ], builddependencies = [], devdependencies = [], features = [], targets = [ struct( name = "net2", kinds = [ "lib", ], path = "src/lib.rs", ), struct( name = "all", kinds = [ "test", ], path = "tests/all.rs", ), ], ) ```
Cargo.bzl
. I envision mapping the existing platform-specific dependency support down to a handful of supported platforms within the bazel rule, rather than here. That lets us use bazel's select
construct to support multiple platforms with a single rule.