Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Native mesh cpp code into a cpp directory #26

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions crates/cpp/tests/native_mesh/Makefile
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@

all:
make -C component_b $@
make -C mesh $@
make -C component_a $@
make -C cpp/component_b $@
make -C cpp/mesh $@
make -C cpp/component_a $@

bindgen:
make -C component_b $@
make -C mesh $@
make -C component_a $@
make -C cpp/component_b $@
make -C cpp/mesh $@
make -C cpp/component_a $@

clean:
make -C component_b $@
make -C mesh $@
make -C component_a $@
make -C cpp/component_b $@
make -C cpp/mesh $@
make -C cpp/component_a $@

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CXXFLAGS=-g -O0 -I../../../helper-types
CXXFLAGS=-g -O0 -I../../../../helper-types -std=c++1z

all: component_a

Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CXXFLAGS=-fPIC -g -O0 -I../../../helper-types
CXXFLAGS=-fPIC -g -O0 -I../../../../helper-types -std=c++1z

all: libcomponent_b.so

Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CXXFLAGS=-fPIC -g -O0 -I../../../helper-types
CXXFLAGS=-fPIC -g -O0 -I../../../../helper-types -std=c++1z

all: libmesh.so

Expand Down
Binary file added crates/cpp/tests/native_mesh/cpp/mesh/libmesh.so
Binary file not shown.
12 changes: 6 additions & 6 deletions crates/cpp/tests/native_strings/Makefile
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
CXXFLAGS=-g -O0 -I../../helper-types
CXXFLAGS=-g -O0 -I../../helper-types --std=c++17
WIT_BINDGEN=../../../../target/debug/wit-bindgen

all: libstrings.so app-strings

libstrings.so: the_world.pie.o guest.pie.o
libstrings.so: the_world.pie.o guest_exports.pie.o
$(CXX) $(CXXFLAGS) -shared -o $@ $^ -Wl,--version-script=guest.lds

%.pie.o: %.cpp
$(CXX) $(CXXFLAGS) -fPIE -o $@ -c $^

app-strings: the_world_native.o main.o
$(CXX) $(CXXFLAGS) -o $@ $^ -L. -lstrings
app-strings: the_world_native.o main.o guest_imports.o
$(CXX) $(CXXFLAGS) -o $@ $^ -g -L. -lstrings

bindgen: wit/strings.wit
$(WIT_BINDGEN) cpp wit --wasm64 --format
$(WIT_BINDGEN) cpp wit --wasm64 --format --direct
cd rust/src ; ../../$(WIT_BINDGEN) rust ../../wit --wasm64

guest.wasm: the_world.cpp guest.cpp
guest.wasm: the_world.cpp guest_exports.cpp
/opt/wasi-sdk/bin/clang++ -o $@ $^ $(CXXFLAGS)

guest_release.wasm: the_world.cpp guest.cpp
guest_release.wasm: the_world.cpp guest_exports.cpp
/opt/wasi-sdk/bin/clang++ -o $@ $^ $(CXXFLAGS) -g0 -O3

clean:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
#include "the_world_cpp.h"

void exports::foo::foo::strings::A(wit::string &&x) {
void exports::foo::foo::strings::A(wit::string &&x)
{
::foo::foo::strings::A(x.get_view());
}

wit::string exports::foo::foo::strings::B() {
wit::string exports::foo::foo::strings::B()
{
return ::foo::foo::strings::B();
}

wit::string exports::foo::foo::strings::C(wit::string &&x, wit::string &&b) {
wit::string exports::foo::foo::strings::C(wit::string &&x, wit::string &&b)
{
return ::foo::foo::strings::C(x.get_view(), b.get_view());
}
20 changes: 20 additions & 0 deletions crates/cpp/tests/native_strings/guest_imports.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include "the_world_cpp_native.h"
#include <iostream>

using namespace std;

void foo::foo::strings::A(std::string_view x)
{
std::cout << x << std::endl;
}
wit::string foo::foo::strings::B()
{
wit::string b = wit::string::from_view(std::string_view("hello B"));
return b;
}
wit::string foo::foo::strings::C(std::string_view a, std::string_view b)
{
std::cout << a << '|' << b << std::endl;
wit::string c = wit::string::from_view(std::string_view("hello C"));
return c;
}
13 changes: 0 additions & 13 deletions crates/cpp/tests/native_strings/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,6 @@
#include "the_world_cpp_native.h"
#include <iostream>

void foo::foo::strings::A(std::string_view x) {
std::cout << x << std::endl;
}
wit::string foo::foo::strings::B() {
wit::string b = wit::string::from_view(std::string_view("hello B"));
return b;
}
wit::string foo::foo::strings::C(std::string_view a, std::string_view b) {
std::cout << a << '|' << b << std::endl;
wit::string c = wit::string::from_view(std::string_view("hello C"));
return c;
}

int main() {
wit::string a = wit::string::from_view(std::string_view("hello A"));
exports::foo::foo::strings::A(a);
Expand Down
2 changes: 2 additions & 0 deletions crates/cpp/tests/native_strings/rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::alloc::Layout;
use the_world::exports::foo::foo::strings::Guest;

mod the_world;
mod the_world_native;

struct MyWorld;

Expand All @@ -22,6 +23,7 @@ impl Guest for MyWorld {

the_world::export!(MyWorld with_types_in the_world);


// the crate wit-bindgen-rt doesn't work on native
#[no_mangle]
pub unsafe extern "C" fn cabi_realloc(
Expand Down
Loading