Skip to content

Add rules for stdlib, rustls, and stdio#183

Merged
nunoplopes merged 15 commits into
Cpp2Rust:masterfrom
lucic71:rustls
Jun 12, 2026
Merged

Add rules for stdlib, rustls, and stdio#183
nunoplopes merged 15 commits into
Cpp2Rust:masterfrom
lucic71:rustls

Conversation

@lucic71

@lucic71 lucic71 commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

This mainly adds translation rules for rustls_ffi. I needed to do a few modifications in cpp2rust/ to be able to add translation rules for typedef'ed integers, for example rustls_ffi::rustls_result (typedef uint32_t rustls_result):

  • add support in cpp-rule-preprocessor to define rule types as typedef in C and using in C++. rustls.h uses C specific features, hence the source rules must be put in a src.c file. For example in rustls.h uses the following which is valid C but invalid C++:
enum rustls_result { ... }
typedef uint32_t rustls_result; // same name as the enum
  • zero-initialize rust enums using the enum default value, not using 0, in getIntegerLiteral, for example: rustls_result r = 0
  • install rustls.h into rules/rustls using the cargo installation instead of copy-pasting the vendored rustls.h file. rules/build.rs takes care of this

Comment thread rules/rustls/rustls.h Outdated
@@ -0,0 +1,2869 @@
#ifndef RUSTLS_H
#define RUSTLS_H

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this file needed and what's the origin?

@lucic71 lucic71 Jun 7, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's needed to get the C symbols that we translate to rust, similar to brotli: https://github.com/Cpp2Rust/cpp2rust/tree/master/rules/brotli/brotli

This is the origin: https://github.com/rustls/rustls-ffi/blob/main/librustls/src/rustls.h

I installed the deb package (https://github.com/rustls/rustls-ffi/releases/tag/v0.15.3) for rustls-ffi on my system and copied /usr/include/rustls.h into rules/rustls/rustls.h

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the copy-pasted file, see the new description of the PR

@lucic71 lucic71 force-pushed the rustls branch 2 times, most recently from 6ffc47e to 3e48952 Compare June 12, 2026 14:06
Comment thread CMakeLists.txt

add_custom_command(
OUTPUT ${rust_rules_ir_outputs}
COMMAND cargo +${RUST_STABLE_VERSION} build --release --manifest-path "${PROJECT_SOURCE_DIR}/rules/Cargo.toml"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this change doesn't look intended

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that was a mistake. It was asymptomatic because I already had rustls.h generated on my machine

@nunoplopes nunoplopes merged commit 6849e2c into Cpp2Rust:master Jun 12, 2026
9 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.

2 participants