Skip to content

Conversation

@ricochet
Copy link
Contributor

Fixes #1419

Signed-off-by: Bailey Hayes [email protected]

@ricochet ricochet marked this pull request as draft November 17, 2025 15:03
@ricochet ricochet force-pushed the cpp-escape branch 6 times, most recently from 1450ef8 to e6f0f3a Compare November 17, 2025 21:50
- remove keywords.wit from expected failures
- use std::optional for ResultLift to avoid default constructor issues
  std::expected doesn't have a default constructor when the value type
  lacks one. Use std::optional wrapper to defer construction until the
  result is known.

Fixes bytecodealliance#1419

Signed-off-by: Bailey Hayes <[email protected]>
@ricochet
Copy link
Contributor Author

A bit of an adventure but I am now able to successfully run a wasi:http server. Check it out here: https://github.com/ricochet/sample-wasi-http-cpp

@ricochet ricochet marked this pull request as ready for review November 18, 2025 20:17
"ret" => "ret_".into(),
"err" => "err_".into(),
// C standard library macros that conflict when used as identifiers
"stdin" => "stdin_".into(),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

heads up this is for c as well as C++. Extra care that this is correct should be taken here.

Copy link
Member

@alexcrichton alexcrichton left a comment

Choose a reason for hiding this comment

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

Thanks!

@alexcrichton alexcrichton added this pull request to the merge queue Nov 18, 2025

let tmp = self.tmp();
let resultname = self.tempname("result", tmp);
// Use std::optional to avoid default constructor issues with std::expected
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe this is the best approach given the available options, but it was a technique new to me.

This is what this generates:
https://github.com/ricochet/sample-wasi-http-cpp/blob/main/bindings/http_server.cpp#L1268-L1278

@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Nov 18, 2025
@ricochet ricochet mentioned this pull request Nov 19, 2025
@alexcrichton alexcrichton added this pull request to the merge queue Nov 19, 2025
@ricochet ricochet added the gen-cpp Related to the C++ code generator label Nov 19, 2025
Merged via the queue into bytecodealliance:main with commit f11a006 Nov 19, 2025
21 of 22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gen-cpp Related to the C++ code generator

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cpp: escape keywords in parameters

2 participants