Skip to content

Commit 45dfb21

Browse files
committed
Fix missing headers, compile in C++20 mode, fix std::span usage
1 parent cdc5256 commit 45dfb21

6 files changed

Lines changed: 13 additions & 18 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/cpp/helper-types/wit.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include <string.h> // memcpy
1313
#include <stdlib.h> // free
1414
#include <new>
15-
15+
#include <span>
1616

1717
namespace wit {
1818
/// @brief Helper class to map between IDs and resources
@@ -45,12 +45,6 @@ template <class R> class ResourceTable {
4545
/// @brief Replaces void in the error position of a result
4646
struct Void {};
4747

48-
template<class To, class From>
49-
constexpr To bit_cast(const From& from) noexcept {
50-
union Bits { From from; To to; };
51-
Bits b; b.from = from; return b.to;
52-
}
53-
5448
/// A string in linear memory, freed unconditionally using free
5549
///
5650
/// A normal C++ string makes no guarantees about where the characters

crates/cpp/src/lib.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ struct Includes {
8080
needs_tuple: bool,
8181
needs_assert: bool,
8282
needs_bit: bool,
83+
needs_span: bool,
8384
// needs wit types
8485
needs_wit: bool,
8586
needs_memory: bool,
@@ -692,7 +693,7 @@ impl WorldGenerator for Cpp {
692693
if self.dependencies.needs_wit {
693694
files.push(
694695
&format!("wit-guest.h"),
695-
include_bytes!("../helper-types/wit-guest.h"),
696+
include_bytes!("../helper-types/wit.h"),
696697
);
697698
}
698699
Ok(())
@@ -1498,13 +1499,13 @@ impl CppInterfaceGenerator<'_> {
14981499
let inner = self.type_name(ty, from_namespace, flavor);
14991500
match flavor {
15001501
Flavor::BorrowedArgument => {
1501-
self.gen.dependencies.needs_wit = true;
1502+
self.gen.dependencies.needs_span = true;
15021503
format!("std::span<{inner} const>")
15031504
}
15041505
Flavor::Argument(var)
15051506
if matches!(var, AbiVariant::GuestImport) || self.gen.opts.new_api =>
15061507
{
1507-
self.gen.dependencies.needs_wit = true;
1508+
self.gen.dependencies.needs_span = true;
15081509
format!("std::span<{inner} const>")
15091510
}
15101511
Flavor::Argument(AbiVariant::GuestExport) => {

crates/test/src/cpp.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ impl LanguageMethods for Cpp17 {
131131
.arg("-Wextra")
132132
.arg("-Werror")
133133
.arg("-Wno-unused-parameter")
134-
.arg("-std=c++17")
134+
.arg("-std=c++20")
135135
.arg("-c")
136136
.arg("-g")
137137
.arg("-o")
@@ -159,7 +159,7 @@ impl LanguageMethods for Cpp17 {
159159
.arg("-Werror")
160160
.arg("-Wc++-compat")
161161
.arg("-Wno-unused-parameter")
162-
.arg("-std=c++17")
162+
.arg("-std=c++20")
163163
.arg("-g")
164164
.arg("-o")
165165
.arg(&compile.output);

tests/runtime/lists/runner.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ static bool equal(std::span<const R> const&a, std::vector<R> const& b) {
3535
}
3636
template<class R>
3737
static bool equal(wit::vector<R> const&a, std::vector<R> const& b) {
38-
return equal(a.get_view(), std::span<R>(b));
38+
return equal(a.get_view(), std::span<R const>(b));
3939
}
4040
static bool equal(wit::vector<wit::string> const&a, std::vector<std::string_view> const& b) {
41-
return equal(a.get_view(), std::span<std::string_view>(b));
41+
return equal(a.get_view(), std::span<std::string_view const>(b));
4242
}
4343
template<class R,class S, class T, class U>
4444
static bool equal(std::tuple<R,S> const&a, std::tuple<T,U> const& b) {

tests/runtime/lists/test.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ static bool equal(std::span<const R> const&a, wit::vector<R> const& b) {
2929
}
3030
template<class R>
3131
static bool equal(std::span<const R> const&a, std::vector<R> const& b) {
32-
return equal(a, std::span<R>(b));
32+
return equal(a, std::span<const R>(b));
3333
}
3434
template<class R>
3535
static bool equal(wit::vector<R> const&a, std::vector<R> const& b) {
@@ -87,15 +87,15 @@ void exports::test::lists::to_test::ListParamLarge(std::span<std::string_view co
8787
}
8888

8989
wit::vector<uint8_t> exports::test::lists::to_test::ListResult() {
90-
return wit::vector<uint8_t>::from_view(std::span<uint8_t>(std::vector<uint8_t>{1, 2, 3, 4, 5}));
90+
return wit::vector<uint8_t>::from_view(std::span<uint8_t const>(std::vector<uint8_t>{1, 2, 3, 4, 5}));
9191
}
9292

9393
wit::string exports::test::lists::to_test::ListResult2() {
9494
return wit::string::from_view("hello!");
9595
}
9696

9797
wit::vector<wit::string> exports::test::lists::to_test::ListResult3() {
98-
return wit::vector<wit::string>::from_view(std::span<wit::string>(std::vector<wit::string>{wit::string::from_view("hello,"), wit::string::from_view("world!")}));
98+
return wit::vector<wit::string>::from_view(std::span<wit::string const>(std::vector<wit::string>{wit::string::from_view("hello,"), wit::string::from_view("world!")}));
9999
}
100100

101101
wit::vector<uint8_t> exports::test::lists::to_test::ListRoundtrip(std::span<const uint8_t> x) {

0 commit comments

Comments
 (0)