mozilla / cbindgen

A project for generating C bindings from Rust code
Mozilla Public License 2.0
2.35k stars 304 forks source link

Macro Expansion Not Working #839

Closed coffeebe4code closed 1 year ago

coffeebe4code commented 1 year ago

cbindgen does not generate macros. You can see this project for reference. type-lang

I generated the output from the cranelift directory. cbindgen --config cbindgen.toml --crate cranelift-export --output ./headers/craneliftc.h

It does not appear that my declarative macros are expanded. Let me know what I am missing, thanks!

emilio commented 1 year ago

See parse.expand config option. Let me know if that doesn't answer your question.

coffeebe4code commented 1 year ago

@emilio I'm not sure if it did or not. [parse.expand] seems for other crates macros. When I attempted it on the same crate I'm doing the bindgen for, cranelift-export. I did this.

I tried it with and without the paste crate. My results are the same. some sort of crash.

ERROR: Parsing crate `cranelift-export`: couldn't run `cargo rustc -Zunpretty=expanded`: Compile("       Fresh version_check v0.9.4\n       Fresh cfg-if v1.0.0\n       Fresh autocfg v1.1.0\n       Fresh once_cell v1.17.1\n       Fresh hashbrown v0.12.3\n       Fresh arbitrary v1.3.0\n       Fresh rustc-hash v1.1.0\n       Fresh stable_deref_trait v1.2.0\n       Fresh cranelift-codegen-meta v0.96.2\n       Fresh ahash v0.8.3\n       Fresh cranelift-isle v0.96.2\n       Fresh slice-group-by v0.3.1\n       Fresh fallible-iterator v0.2.0\n       Fresh smallvec v1.10.0\n       Fresh cranelift-entity v0.96.2\n       Fresh cranelift-control v0.96.2\n       Fresh bumpalo v3.13.0\n       Fresh cranelift-codegen-shared v0.96.2\n       Fresh hashbrown v0.13.2\n       Fresh log v0.4.17\n       Fresh cranelift-bforest v0.96.2\n       Fresh target-lexicon v0.12.7\n       Fresh indexmap v1.9.3\n       Fresh regalloc2 v0.8.1\n       Fresh paste v1.0.12\n       Fresh gimli v0.27.2\n       Fresh cranelift-codegen v0.96.2\n       Fresh cranelift-frontend v0.96.1\n       Fresh cranelift v0.96.1\n    Checking cranelift-export v0.1.0 (/home/christopher/source/type-lang/cranelift/export)\n     Running `rustc --crate-name craneliftc --edition=2021 export/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type staticlib --crate-type cdylib --emit=dep-info,metadata -C embed-bitcode=no -C debuginfo=2 -Zunpretty=expanded -C metadata=9ff967dedaadaecf -C extra-filename=-9ff967dedaadaecf --out-dir /home/christopher/source/type-lang/cranelift/target/debug/deps -C incremental=/home/christopher/source/type-lang/cranelift/target/debug/incremental -L dependency=/home/christopher/source/type-lang/cranelift/target/debug/deps --extern cranelift=/home/christopher/source/type-lang/cranelift/target/debug/deps/libcranelift-10db80be698894a0.rmeta --extern paste=/home/christopher/source/type-lang/cranelift/target/debug/deps/libpaste-b379911497bfa74c.so`\nerror: the option `Z` is only accepted on the nightly compiler\n\nerror: could not compile `cranelift-export`\n\nCaused by:\n  process didn't exit successfully: `rustc --crate-name craneliftc --edition=2021 export/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type staticlib --crate-type cdylib --emit=dep-info,metadata -C embed-bitcode=no -C debuginfo=2 -Zunpretty=expanded -C metadata=9ff967dedaadaecf -C extra-filename=-9ff967dedaadaecf --out-dir /home/christopher/source/type-lang/cranelift/target/debug/deps -C incremental=/home/christopher/source/type-lang/cranelift/target/debug/incremental -L dependency=/home/christopher/source/type-lang/cranelift/target/debug/deps --extern cranelift=/home/christopher/source/type-lang/cranelift/target/debug/deps/libcranelift-10db80be698894a0.rmeta --extern paste=/home/christopher/source/type-lang/cranelift/target/debug/deps/libpaste-b379911497bfa74c.so` (exit status: 1)\n")
ERROR: Couldn't generate bindings for /home/christopher/source/type-lang/cranelift.

The command ran in the cranelift directory. cbindgen --config cbindgen.toml --crate cranelift-export --output ./headers/craneliftc.h

emilio commented 1 year ago

Parse expansion needs rust nightly.