Comments (2)
Build scripts (like build.rs you linked to) can print out text commands that Cargo understands. In particular, there are:
rustc-link-lib=static=libdouble.a
, which tells Cargo to look forlibdouble.a
; andrustc-link-search=native=SOME_DIR
, which tells Cargo to look for the library in "SOME_DIR".
Both of these commands are printed when you call compile()
. You can learn more about that in cc's documentation here, and also in The Book.
You can run cargo build
in verbose mode to see what the build script prints out on your machine:
# Cleaning everything to force the rebuild
$ cargo clean
$ cargo build -vv
In my case, the output was:
It's rather long, click to expand
Compiling cc v1.0.25 Compiling libc v0.2.45 Running `rustc --crate-name cc /home/minoru/.cargo/registry/src/github.com-1ecc6299db9ec823/cc-1.0.25/src/lib.rs --color always --crate-type lib --emit=dep-info,link -C debuginfo=2 -C metadata=8dc6d0eb3b3011ee -C extra-filename=-8dc6d0eb3b3011ee --out-dir /dev/shm/rust-ffi-examples/rust-to-c/target/debug/deps -L dependency=/dev/shm/rust-ffi-examples/rust-to-c/target/debug/deps --cap-lints warn` Running `rustc --crate-name build_script_build /home/minoru/.cargo/registry/src/github.com-1ecc6299db9ec823/libc-0.2.45/build.rs --color always --crate-type bin --emit=dep-info,link -C debuginfo=2 --cfg 'feature="default"' --cfg 'feature="use_std"' -C metadata=59c42b4afe560b27 -C extra-filename=-59c42b4afe560b27 --out-dir /dev/shm/rust-ffi-examples/rust-to-c/target/debug/build/libc-59c42b4afe560b27 -L dependency=/dev/shm/rust-ffi-examples/rust-to-c/target/debug/deps --cap-lints warn` Running `/dev/shm/rust-ffi-examples/rust-to-c/target/debug/build/libc-59c42b4afe560b27/build-script-build` cargo:rustc-cfg=core_cvoid Running `rustc --crate-name libc /home/minoru/.cargo/registry/src/github.com-1ecc6299db9ec823/libc-0.2.45/src/lib.rs --color always --crate-type lib --emit=dep-info,link -C debuginfo=2 --cfg 'feature="default"' --cfg 'feature="use_std"' -C metadata=0446e5f9b8b82390 -C extra-filename=-0446e5f9b8b82390 --out-dir /dev/shm/rust-ffi-examples/rust-to-c/target/debug/deps -L dependency=/dev/shm/rust-ffi-examples/rust-to-c/target/debug/deps --cap-lints warn --cfg core_cvoid` Compiling rust-to-c v0.1.0 (/dev/shm/rust-ffi-examples/rust-to-c) Running `rustc --crate-name build_script_build build.rs --color always --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=307344becb5b0d7b -C extra-filename=-307344becb5b0d7b --out-dir /dev/shm/rust-ffi-examples/rust-to-c/target/debug/build/rust-to-c-307344becb5b0d7b -C incremental=/dev/shm/rust-ffi-examples/rust-to-c/target/debug/incremental -L dependency=/dev/shm/rust-ffi-examples/rust-to-c/target/debug/deps --extern cc=/dev/shm/rust-ffi-examples/rust-to-c/target/debug/deps/libcc-8dc6d0eb3b3011ee.rlib` Running `/dev/shm/rust-ffi-examples/rust-to-c/target/debug/build/rust-to-c-307344becb5b0d7b/build-script-build` TARGET = Some("x86_64-unknown-linux-gnu") OPT_LEVEL = Some("0") HOST = Some("x86_64-unknown-linux-gnu") CC_x86_64-unknown-linux-gnu = None CC_x86_64_unknown_linux_gnu = None HOST_CC = None CC = None CFLAGS_x86_64-unknown-linux-gnu = None CFLAGS_x86_64_unknown_linux_gnu = None HOST_CFLAGS = None CFLAGS = None DEBUG = Some("true") running: "cc" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "-m64" "-Wall" "-Wextra" "-o" "/dev/shm/rust-ffi-examples/rust-to-c/target/debug/build/rust-to-c-c494e004f80bed4b/out/src/double.o" "-c" "src/double.c" exit code: 0 AR_x86_64-unknown-linux-gnu = None AR_x86_64_unknown_linux_gnu = None HOST_AR = None AR = None running: "ar" "crs" "/dev/shm/rust-ffi-examples/rust-to-c/target/debug/build/rust-to-c-c494e004f80bed4b/out/libdouble.a" "/dev/shm/rust-ffi-examples/rust-to-c/target/debug/build/rust-to-c-c494e004f80bed4b/out/src/double.o" exit code: 0 cargo:rustc-link-lib=static=double cargo:rustc-link-search=native=/dev/shm/rust-ffi-examples/rust-to-c/target/debug/build/rust-to-c-c494e004f80bed4b/out Running `rustc --crate-name rust_to_c src/main.rs --color always --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=26d4d0c4a319dc63 -C extra-filename=-26d4d0c4a319dc63 --out-dir /dev/shm/rust-ffi-examples/rust-to-c/target/debug/deps -C incremental=/dev/shm/rust-ffi-examples/rust-to-c/target/debug/incremental -L dependency=/dev/shm/rust-ffi-examples/rust-to-c/target/debug/deps --extern libc=/dev/shm/rust-ffi-examples/rust-to-c/target/debug/deps/liblibc-0446e5f9b8b82390.rlib -L native=/dev/shm/rust-ffi-examples/rust-to-c/target/debug/build/rust-to-c-c494e004f80bed4b/out -l static=double` Finished dev [unoptimized + debuginfo] target(s) in 1.96s
Look at the last few lines—there are the commands! I believe paths like "rust-to-c-c494e004f80bed4b" can change from machine to machine, so don't depend on them in any way.
from rust-ffi-examples.
https://docs.rs/cc/1.0.25/cc/struct.Build.html#method.cargo_metadata and rustc-link-lib=static=libdouble.a
were the keys. Details in https://doc.rust-lang.org/cargo/reference/build-scripts.html#outputs-of-the-build-script too.
Thanks for this master class
from rust-ffi-examples.
Related Issues (11)
- Passing strings from and to lua HOT 6
- c-to-rust example fails HOT 2
- python-to-rust string example needed HOT 4
- golang ? HOT 4
- Any plan for a rust-to-rust example? HOT 8
- Any plan for a rust to cpp with WASM example?
- C++ objects and rust both ways
- Error when running python-to-rust HOT 2
- c-to-rust lack of rust cleanup? HOT 1
- Rust-to-C : Adding pre compiled archive file HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rust-ffi-examples.