Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding codegen flags to a Cargo build

On Macintosh, to allow some symbols to go unlinked, it is necessary to pass -C link-args='-Wl,-undefined,dynamic_lookup' to the Rust compiler. One needs to do this when building Postgres plugins, because some of the Postgres intrinsics are only compiled into the Postgres server, and not available for linking from shared libs.

At present, the project's process is as follows:

  • Build is run with cargo build -v.
  • Failing call to rustc is copied and -C link-args='-Wl,-undefined,dynamic_lookup' added to it.
  • Success!

This seems like a hard sell for automation. What options are available for adding codegen flags to Rust builds through cargo?

like image 257
solidsnack Avatar asked Jan 06 '16 08:01

solidsnack


People also ask

Where do I put build RS files?

Placing a file named build.rs in the root of a package will cause Cargo to compile that script and execute it just before building the package.

How many release profiles does Rust Optimisation level have?

You'll only compile in release mode once, but you'll run the compiled program many times, so release mode trades longer compile time for code that runs faster. That is why the default opt-level for the release profile is 3 .

Where does Cargo build output?

Cargo stores the output of a build into the "target" directory. By default, this is the directory named target in the root of your workspace. To change the location, you can set the CARGO_TARGET_DIR environment variable, the build. target-dir config value, or the --target-dir command-line flag.

What is Cargo TOML?

Cargo. toml is the manifest file for Rust's package manager, cargo . This file contains metadata such as name, version, and dependencies for packages, which are call "crates" in Rust.


1 Answers

cargo provides rustc command which allows one to pass arbitrary compiler flags. The following should do it:

% cargo rustc -- -C link-args='-Wl,-undefined,dynamic_lookup'
like image 196
Vladimir Matveev Avatar answered Sep 28 '22 09:09

Vladimir Matveev