NokiaTube | New address | Mode Phone | Off high quality for Nokia Browser
Skip to content

Generate cc_std bindings crate from CMake - #3032

Merged
copybara-service[bot] merged 1 commit into
google:mainfrom
brontosource:bindings
Nov 23, 2026
Merged

copybara-service[bot] merged 1 commit into
google:mainfrom
brontosource:bindings

Conversation

@asoffer

@asoffer asoffer commented Nov 17, 2026

Copy link
Copy Markdown
Collaborator

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

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
@copybara-service
copybara-service Bot merged commit 5bd7864 into google:main Nov 23, 2026
13 of 16 checks passed
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