Repository navigation
Generate cc_std bindings crate from CMake - #3032
Merged
Merged
Conversation
Rust crates built with Corrosion depend on the generated bindings crates by version only (`cc_std = "0.0.0"`). A Cargo config file in the build directory, passed to Cargo with `--config`, redirects each one to its generated crate with `[patch.crates-io]`. A checked-in Cargo.toml can't name the build directory, and Cargo has no variables in `path`, so this is the way to point Cargo at crates that exist only in one build. Bazel needs no equivalent: it doesn't run Cargo, and passes each crate to rustc directly. rs_bindings_from_cc reads its param file with GNU-style quoting (llvm::cl::TokenizeGNUCommandLine), so quotes, backslashes and whitespace in arguments must be escaped. The arguments include generator expressions, whose values can't be escaped when generating, so CMake writes them one per line and CrubitQuoteParams.cmake escapes them into the param file at build time. On macOS, the SDK's <netinet/in.h> declares setipv4sourcefilter and getipv4sourcefilter outside of __BEGIN_DECLS/__END_DECLS, giving them C++ linkage, so thunks calling them fail to link against libSystem's C symbols. support/cc_std_impl/macos_sdk_workarounds.h marks them crubit_do_not_bind; it is empty on other platforms.
copybara-service Bot
pushed a commit
that referenced
this pull request
Nov 23, 2026
-- 11c642c by Andy Soffer <[email protected]>: Generate cc_std bindings crate from CMake Rust crates built with Corrosion depend on the generated bindings crates by version only (`cc_std = "0.0.0"`). A Cargo config file in the build directory, passed to Cargo with `--config`, redirects each one to its generated crate with `[patch.crates-io]`. A checked-in Cargo.toml can't name the build directory, and Cargo has no variables in `path`, so this is the way to point Cargo at crates that exist only in one build. Bazel needs no > equivalent: it doesn't run Cargo, and passes each crate to rustc directly. rs_bindings_from_cc reads its param file with GNU-style quoting (llvm::cl::TokenizeGNUCommandLine), so quotes, backslashes and whitespace in arguments must be escaped. The arguments include generator expressions, whose values can't be escaped when generating, so CMake writes them one per line and CrubitQuoteParams.cmake escapes them into the param file at build time. On macOS, the SDK's <netinet/in.h> declares setipv4sourcefilter and getipv4sourcefilter outside of __BEGIN_DECLS/__END_DECLS, giving them C++ linkage, so thunks calling them fail to link against libSystem's C symbols. support/cc_std_impl/macos_sdk_workarounds.h marks them crubit_do_not_bind; it is empty on other platforms. FUTURE_COPYBARA_INTEGRATE_REVIEW=#3032 from brontosource:bindings 11c642c PiperOrigin-RevId: 1026866774
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Rust crates built with Corrosion depend on the generated bindings crates by version only (
cc_std = "0.0.0"). A Cargo config file in the build directory, passed to Cargo with--config, redirects each one to its generated crate with[patch.crates-io]. A checked-in Cargo.toml can't name the build directory, and Cargo has no variables inpath, so this is the way to point Cargo at crates that exist only in one build. [Bazel doesn't need an equivalent because it doesn't run Cargo.]rs_bindings_from_cc reads its param file with GNU-style quoting (llvm::cl::TokenizeGNUCommandLine), so quotes, backslashes and whitespace in arguments must be escaped. The arguments include generator expressions, whose values can't be escaped when generating, so CMake writes them one per line and CrubitQuoteParams.cmake escapes them into the param file at build time.
On macOS, the SDK's <netinet/in.h> declares setipv4sourcefilter and getipv4sourcefilter outside of __BEGIN_DECLS/__END_DECLS, giving them C++ linkage, so thunks calling them fail to link against libSystem's C symbols. support/cc_std_impl/macos_sdk_workarounds.h marks them crubit_do_not_bind; it is empty on other platforms.