Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#ifdef support #57

Open
adetaylor opened this issue Oct 30, 2020 · 3 comments
Open

#ifdef support #57

adetaylor opened this issue Oct 30, 2020 · 3 comments
Labels
cpp-feature C++ feature not yet supported

Comments

@adetaylor
Copy link
Collaborator

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 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.

@adetaylor
Copy link
Collaborator Author

Pull request #74 removes a file, preprocessor_parse_callbacks.rs, which had a lot of the code required to make this work. We should reinstate parts of that file when fixing this issue.

@adetaylor adetaylor added the cpp-feature C++ feature not yet supported label Mar 25, 2021
@adetaylor
Copy link
Collaborator Author

@adetaylor
Copy link
Collaborator Author

adetaylor commented Feb 16, 2022

Solution for non-cargo platforms: emit a file of --cfg flags which can be pulled into the downstream rustc build using @file.txt. This is proven to work in gn, so long as the filename ends in .rs. We do this already for --cfg flags produced by https://source.chromium.org/chromium/chromium/src/+/main:build/rust/cargo_crate.gni

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cpp-feature C++ feature not yet supported
Projects
None yet
Development

No branches or pull requests

1 participant