HiveBrain v1.2.0
Get Started
← Back to all entries
snippetrustCritical

How to get assembly output from building with Cargo?

Submitted by: @import:stackoverflow-api··
0
Viewed 0 times
withhowfromoutputbuildingassemblycargoget

Problem

While I've seen docs on using rustc directly to output assembly, having to manually extract commands used by Cargo and edit them to write assembly is tedious.

Is there a way to run Cargo that writes out assembly files?

Solution

You can use Cargo's cargo rustc command to send arguments to rustc directly:

cargo rustc -- --emit asm
ls target/debug/deps/-.s


For optimized assembly:

cargo rustc --release -- --emit asm
ls target/release/deps/-.s


If you see multiple --.rcgu.s files instead of a -.s file, disable incremental compilation by setting the environment variable CARGO_INCREMENTAL=0.

Code Snippets

cargo rustc -- --emit asm
ls target/debug/deps/<crate_name>-<hash>.s
cargo rustc --release -- --emit asm
ls target/release/deps/<crate_name>-<hash>.s

Context

Stack Overflow Q#39219961, score: 118

Revisions (0)

No revisions yet.