Open
Description
I am comparing what cargo and rules_rust generate in terms of the rustc command line.
I setup a 1:1 comparison where each one depends one very large dependency (datafusion).
The difference in command line is massive. For instance, it appears that every transitive dependency is added to the command line when using the Bazel rules. I was expecting them to be close but that our bazel rules would show significantly more input files due to the toolchain dependencies (which do not show up in the Cargo output).
Library
Cargo
Cargo.toml
[package]
name = "rustc_lib_test"
version = "0.1.0"
edition = "2021"
[dependencies]
datafusion = "43.0.0"
lib.rs
pub fn add(left: u64, right: u64) -> u64 {
left + right
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn it_works() {
let result = add(2, 2);
assert_eq!(result, 4);
}
}
cargo build --verbose
to see the output:
Compiling rustc_lib_test v0.1.0 (/home/sschwartz/dev/playground/rustc_lib_test)
Running `/home/sschwartz/.rustup/toolchains/1.80-x86_64-unknown-linux-gnu/bin/rustc --crate-name rustc_lib_test --edition=2021 src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=207 --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C debuginfo=2 --check-cfg 'cfg(docsrs)' --check-cfg 'cfg(feature, values())' -C metadata=f7243f4cb3e2af92 -C extra-filename=-f7243f4cb3e2af92 --out-dir /home/sschwartz/dev/playground/rustc_lib_test/target/debug/deps -C incremental=/home/sschwartz/dev/playground/rustc_lib_test/target/debug/incremental -L dependency=/home/sschwartz/dev/playground/rustc_lib_test/target/debug/deps --extern datafusion=/home/sschwartz/dev/playground/rustc_lib_test/target/debug/deps/libdatafusion-718e7861d77c65d0.rmeta -L native=/home/sschwartz/dev/playground/rustc_lib_test/target/debug/build/bzip2-sys-286f47a460bead30/out/lib -L native=/home/sschwartz/dev/playground/rustc_lib_test/target/debug/build/lzma-sys-9c91f5e4b289e14a/out -L native=/home/sschwartz/dev/playground/rustc_lib_test/target/debug/build/zstd-sys-6b9356312b31bfce/out -L native=/home/sschwartz/dev/playground/rustc_lib_test/target/debug/build/blake3-b73b7dfc07d07f11/out -L native=/home/sschwartz/dev/playground/rustc_lib_test/target/debug/build/blake3-b73b7dfc07d07f11/out`
Bazel
BUILD.bazel
load("@rules_rust//rust:defs.bzl", "rust_library")
package(default_visibility = ["//visibility:public"])
rust_library(
name = "bazel_rustc_lib_test",
srcs = ["lib.rs"],
deps = [
"@crates_io//:datafusion",
],
)
lib.rs
pub fn add(left: u64, right: u64) -> u64 {
left + right
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn it_works() {
let result = add(2, 2);
assert_eq!(result, 4);
}
}
aquery
to get the output:
bazel aquery //tools/testing:bazel_rustc_lib_test > rustc_lib_test.aquery.dbg.txt
Binary
Cargo
Cargo.toml
[package]
name = "rustc_bin_test"
version = "0.1.0"
edition = "2021"
[dependencies]
datafusion = "43.0.0"
main.rs
fn main() {
println!("Hello, world!");
}
cargo build --verbose
to see the output:
Compiling rustc_bin_test v0.1.0 (/home/sschwartz/dev/playground/rustc_bin_test)
Running `/home/sschwartz/.rustup/toolchains/1.80-x86_64-unknown-linux-gnu/bin/rustc --crate-name rustc_bin_test --edition=2021 src/main.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=98 --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C debuginfo=2 --check-cfg 'cfg(docsrs)' --check-cfg 'cfg(feature, values())' -C metadata=b9ced09a3af3e361 -C extra-filename=-b9ced09a3af3e361 --out-dir /home/sschwartz/dev/playground/rustc_bin_test/target/debug/deps -C incremental=/home/sschwartz/dev/playground/rustc_bin_test/target/debug/incremental -L dependency=/home/sschwartz/dev/playground/rustc_bin_test/target/debug/deps --extern datafusion=/home/sschwartz/dev/playground/rustc_bin_test/target/debug/deps/libdatafusion-718e7861d77c65d0.rlib -L native=/home/sschwartz/dev/playground/rustc_bin_test/target/debug/build/bzip2-sys-286f47a460bead30/out/lib -L native=/home/sschwartz/dev/playground/rustc_bin_test/target/debug/build/lzma-sys-9c91f5e4b289e14a/out -L native=/home/sschwartz/dev/playground/rustc_bin_test/target/debug/build/zstd-sys-6b9356312b31bfce/out -L native=/home/sschwartz/dev/playground/rustc_bin_test/target/debug/build/blake3-b73b7dfc07d07f11/out -L native=/home/sschwartz/dev/playground/rustc_bin_test/target/debug/build/blake3-b73b7dfc07d07f11/out`
Bazel
BUILD.bazel
load("@rules_rust//rust:defs.bzl", "rust_binary")
package(default_visibility = ["//visibility:public"])
rust_binary(
name = "bazel_rustc_bin_test",
srcs = ["rustc_test.rs"],
deps = [
"@crates_io//:datafusion",
],
)
rustc_test.rs
fn main() {
println!("Hello, world!");
}
aquery
to get the output:
bazel aquery //tools/testing:bazel_rustc_bin_test > rustc_bin_test.aquery.dbg.txt
Metadata
Metadata
Assignees
Labels
No labels