google / google/autocxx

#ifdef support

Open
#57 3 comments 0 reactions 0 assignees View on GitHub
cpp-feature
Dominant language
Rust
Stars
2.6k
Forks
175
PR merge metrics
No merged PRs in 30d

Description

It's my intention that we can support Rust compile-time feature enablement based on C++ macros.

Where users are using our `build.rs` support in https://github.com/google/autocxx/tree/main/gen/build this should really be pretty trivial by [printing](https://doc.rust-lang.org/cargo/reference/build-scripts.html#rustc-cfg) `cargo:rustc-cfg` lines to standard out as we're generating the C++ bindings.

I haven't thought about the exact syntax but obviously the goal is to allow something like `#[cfg(cxx_ifdef = ENABLE_FEATURE)]` which can disable a block of code in Rust.

I also haven't thought about `#if` but that should be achievable in a similar fashion. Probably.

This should be simple for the `build.rs` case but we need to figure out:
* How to do this for the non-Cargo case (https://github.com/google/autocxx/tree/main/gen/cmd) in a way that's easy to integrate into third party build systems. We probably need to write all the extra rustc arguments to a file which build systems can use as input to a subsequent rustc command line.
* How _on earth_ to do this for the integration tests where we just don't launch another rustc instance at all. I don't have a plan there.

I'm also concerned that the sheer number of `#define` symbols are likely to overwhelm the rustc command line so we may need to be selective.

Contributor guide

Open the contributing guide

Research direction

Start by reading the build.rs support under gen/build and the command-line path under gen/cmd, then inspect how integration tests invoke compilation. Define how C++ #define and possibly #if values become Rust cfg inputs for Cargo, third-party build systems, and tests, including whether all symbols can be passed safely. Done means an agreed syntax and working behavior across the supported compilation paths.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, rust
Domain
build-system, compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.