Skip to content
Merged
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
39 changes: 33 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,39 @@ jobs:

- name: Build
run: |
docker build -t cxx-wasi -f Dockerfile.wasi .
mkdir -p out
docker run --rm -v $PWD/out:/out cxx-wasi cp /app/build.wasi/src/frontend/cxx.wasm /out/cxx.wasm
bash -x scripts/build-wasi.sh

- name: Test
- name: Install wasmtime
run: |
curl https://wasmtime.dev/install.sh -sSf | bash
wget https://github.com/bytecodealliance/wasmtime/releases/download/v9.0.3/wasmtime-v9.0.3-x86_64-linux.tar.xz
tar Jxvf wasmtime-v9.0.3-x86_64-linux.tar.xz -C ~/

~/.wasmtime/bin/wasmtime out/cxx.wasm -- --help
- name: Test
run: |
~/wasmtime-v9.0.3-x86_64-linux/wasmtime \
--mapdir=/::${{github.workspace}}/build.wasi/install \
--mapdir tests::tests \
${{github.workspace}}/build.wasi/install/usr/bin/cxx.wasm -- -v tests/manual/source.cc

- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
name: cxx-wasi
path: |
build.wasi/install/
!build.wasi/install/usr/lib/*.a
!build.wasi/install/usr/lib/cmake
!build.wasi/install/usr/lib/wasi-sysroot/lib
!build.wasi/install/usr/lib/wasi-sysroot/share
!build.wasi/install/usr/include
retention-days: 1

release-please:
runs-on: ubuntu-latest
if: github.repository == 'robertoraggi/cplusplus' && github.ref == 'refs/heads/main'
steps:
- uses: GoogleCloudPlatform/release-please-action@v3
with:
token: ${{ secrets.RELEASE_TOKEN }}
release-type: simple
package-name: cplusplus
15 changes: 0 additions & 15 deletions .github/workflows/release-please.yml

This file was deleted.

17 changes: 2 additions & 15 deletions Dockerfile.wasi
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,7 @@ RUN apt-get update && apt-get install -y \
git \
binaryen

WORKDIR /app
COPY tools/kwgen/kwgen.cc /tmp/kwgen.cc

COPY . .
RUN clang++-16 -std=c++20 /tmp/kwgen.cc -o /usr/bin/kwgen

RUN clang++-16 -std=c++20 -o /usr/bin/kwgen tools/kwgen/kwgen.cc

RUN cmake -G Ninja \
-S . \
-B build.wasi \
-DCMAKE_TOOLCHAIN_FILE=/usr/share/cmake/wasi-sdk.cmake \
-DCMAKE_BUILD_TYPE=MinSizeRel \
-DCMAKE_INTERPROCEDURAL_OPTIMIZATION=1 \
-DKWGEN_EXECUTABLE=/usr/bin/kwgen

RUN cmake --build build.wasi

RUN wasm-opt -O --strip-debug build.wasi/src/frontend/cxx -o build.wasi/src/frontend/cxx.wasm
27 changes: 27 additions & 0 deletions scripts/build-wasi.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/sh

set -e

me=$(dirname "$0")

project_root=$(cd "$me/.." && pwd)

DOCKER_EXTRA_OPTS="--rm -t -v ${project_root}:/code -w /code -u $(id -u) cxx-wasi"

docker build -t cxx-wasi -f Dockerfile.wasi ${project_root}

docker run ${DOCKER_EXTRA_OPTS} \
cmake -G Ninja \
-S . \
-B build.wasi \
-DCMAKE_INSTALL_PREFIX=build.wasi/install/usr \
-DCMAKE_TOOLCHAIN_FILE=/usr/share/cmake/wasi-sdk.cmake \
-DCMAKE_BUILD_TYPE=MinSizeRel \
-DCMAKE_INTERPROCEDURAL_OPTIMIZATION=1 \
-DKWGEN_EXECUTABLE=/usr/bin/kwgen \
-DCXX_INSTALL_WASI_SYSROOT=ON \

docker run ${DOCKER_EXTRA_OPTS} \
cmake --build build.wasi --target install


2 changes: 2 additions & 0 deletions src/frontend/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ if(EMSCRIPTEN)
endif()

if (CMAKE_SYSTEM_NAME STREQUAL "WASI")
set_target_properties(cxx PROPERTIES SUFFIX ".wasm")

target_compile_definitions(cxx PRIVATE JSON_HAS_FILESYSTEM=0)
target_compile_definitions(cxx PRIVATE CXX_NO_FILESYSTEM)
endif()
Expand Down
9 changes: 2 additions & 7 deletions src/frontend/cxx/frontend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ auto runOnFile(const CLI& cli, const std::string& fileName) -> bool {
fs::path app_dir;

#if __wasi__
app_dir = fs::path("/");
app_dir = fs::path("/usr/bin/");
#elif __unix__
char* app_name = realpath(cli.app_name.c_str(), nullptr);
app_dir = fs::path(app_name).remove_filename().string();
Expand All @@ -251,12 +251,7 @@ auto runOnFile(const CLI& cli, const std::string& fileName) -> bool {
if (auto paths = cli.get("--sysroot"); !paths.empty()) {
wasmToolchain->setSysroot(paths.back());
} else {
fs::path sysroot_dir;
#if __wasi__
sysroot_dir = fs::path("/wasi-sysroot");
#elif __unix__
sysroot_dir = app_dir / "../lib/wasi-sysroot";
#endif
auto sysroot_dir = app_dir / "../lib/wasi-sysroot";
wasmToolchain->setSysroot(sysroot_dir.string());
}

Expand Down
13 changes: 8 additions & 5 deletions src/parser/cxx/wasm32_wasi_toolchain.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,25 @@ const std::string& Wasm32WasiToolchain::appdir() const { return appdir_; }

void Wasm32WasiToolchain::setAppdir(std::string appdir) {
appdir_ = std::move(appdir);

if (!appdir_.empty() && appdir_.back() == '/') {
appdir_.pop_back();
}
}

const std::string& Wasm32WasiToolchain::sysroot() const { return sysroot_; }

void Wasm32WasiToolchain::setSysroot(std::string sysroot) {
sysroot_ = std::move(sysroot);

if (!sysroot_.empty() && sysroot_.back() == '/') {
sysroot_.pop_back();
}
}

void Wasm32WasiToolchain::addSystemIncludePaths() {
addSystemIncludePath(fmt::format("{}/include", sysroot_));

#if __wasi__
addSystemIncludePath(fmt::format("/usr/lib/cxx/include", appdir_));
#else
addSystemIncludePath(fmt::format("{}/../lib/cxx/include", appdir_));
#endif
}

void Wasm32WasiToolchain::addSystemCppIncludePaths() {
Expand Down