Skip to content

add emit_asm aspect to view rustc assembly output#21

Open
oliverlee wants to merge 1 commit into
mainfrom
asm-check-aspect
Open

add emit_asm aspect to view rustc assembly output#21
oliverlee wants to merge 1 commit into
mainfrom
asm-check-aspect

Conversation

@oliverlee

Copy link
Copy Markdown
Collaborator

Introduces a Bazel aspect that compiles Rust targets with --emit=asm and demangles the output via rustfilt, producing a .s file in an asm_files output group.

The aspect forces codegen-units=1 so rustc emits a single .s file with a predictable name rather than per-CGU files whose count isn't known at action declaration time. DWARF is stripped (debuginfo=0) to reduce noise, and --sysroot is derived from the rustc executable path. An //tools/emit_asm:opt string flag allows overriding the optimization level independently of the build configuration. rust_test targets are handled correctly via --test rather than --crate-type bin.

On the module side, bazel_skylib is added as a dev dep for string_flag, and an isolated bindeps crate extension pulls in rustfilt as a host binary built against a nightly rust_host_tools toolchain.

bazel build //path/to:target \
  --aspects=//tools/emit_asm:aspect.bzl%emit_asm_aspect \
  --output_groups=asm_files \
  --//tools/emit_asm:opt=3

Introduces a Bazel aspect that compiles Rust targets with `--emit=asm`
and demangles the output via `rustfilt`, producing a `.s` file in an
`asm_files` output group.

The aspect forces `codegen-units=1` so rustc emits a single .s file
with a predictable name rather than per-CGU files whose count isn't
known at action declaration time. DWARF is stripped (`debuginfo=0`) to
reduce noise, and `--sysroot` is derived from the rustc executable path.
An `//tools/emit_asm:opt` string flag allows overriding the optimization
level independently of the build configuration. `rust_test` targets are
handled correctly via `--test` rather than `--crate-type bin`.

On the module side, `bazel_skylib` is added as a dev dep for
`string_flag`, and an isolated `bindeps` crate extension pulls in
`rustfilt` as a host binary built against a nightly `rust_host_tools`
toolchain.

```
bazel build //path/to:target \
  --aspects=//tools/emit_asm:aspect.bzl%emit_asm_aspect \
  --output_groups=asm_files \
  --//tools/emit_asm:opt=3
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant