Skip to content

Commit 4396c1c

Browse files
authored
chore: Improve WASI CI (#86)
1 parent a1df8ca commit 4396c1c

File tree

7 files changed

+74
-48
lines changed

7 files changed

+74
-48
lines changed

.github/workflows/ci.yml

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,39 @@ jobs:
105105

106106
- name: Build
107107
run: |
108-
docker build -t cxx-wasi -f Dockerfile.wasi .
109-
mkdir -p out
110-
docker run --rm -v $PWD/out:/out cxx-wasi cp /app/build.wasi/src/frontend/cxx.wasm /out/cxx.wasm
108+
bash -x scripts/build-wasi.sh
111109
112-
- name: Test
110+
- name: Install wasmtime
113111
run: |
114-
curl https://wasmtime.dev/install.sh -sSf | bash
112+
wget https://github.com/bytecodealliance/wasmtime/releases/download/v9.0.3/wasmtime-v9.0.3-x86_64-linux.tar.xz
113+
tar Jxvf wasmtime-v9.0.3-x86_64-linux.tar.xz -C ~/
115114
116-
~/.wasmtime/bin/wasmtime out/cxx.wasm -- --help
115+
- name: Test
116+
run: |
117+
~/wasmtime-v9.0.3-x86_64-linux/wasmtime \
118+
--mapdir=/::${{github.workspace}}/build.wasi/install \
119+
--mapdir tests::tests \
120+
${{github.workspace}}/build.wasi/install/usr/bin/cxx.wasm -- -v tests/manual/source.cc
121+
122+
- name: Upload artifacts
123+
uses: actions/upload-artifact@v3
124+
with:
125+
name: cxx-wasi
126+
path: |
127+
build.wasi/install/
128+
!build.wasi/install/usr/lib/*.a
129+
!build.wasi/install/usr/lib/cmake
130+
!build.wasi/install/usr/lib/wasi-sysroot/lib
131+
!build.wasi/install/usr/lib/wasi-sysroot/share
132+
!build.wasi/install/usr/include
133+
retention-days: 1
134+
135+
release-please:
136+
runs-on: ubuntu-latest
137+
if: github.repository == 'robertoraggi/cplusplus' && github.ref == 'refs/heads/main'
138+
steps:
139+
- uses: GoogleCloudPlatform/release-please-action@v3
140+
with:
141+
token: ${{ secrets.RELEASE_TOKEN }}
142+
release-type: simple
143+
package-name: cplusplus

.github/workflows/release-please.yml

Lines changed: 0 additions & 15 deletions
This file was deleted.

Dockerfile.wasi

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,7 @@ RUN apt-get update && apt-get install -y \
44
git \
55
binaryen
66

7-
WORKDIR /app
7+
COPY tools/kwgen/kwgen.cc /tmp/kwgen.cc
88

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

11-
RUN clang++-16 -std=c++20 -o /usr/bin/kwgen tools/kwgen/kwgen.cc
12-
13-
RUN cmake -G Ninja \
14-
-S . \
15-
-B build.wasi \
16-
-DCMAKE_TOOLCHAIN_FILE=/usr/share/cmake/wasi-sdk.cmake \
17-
-DCMAKE_BUILD_TYPE=MinSizeRel \
18-
-DCMAKE_INTERPROCEDURAL_OPTIMIZATION=1 \
19-
-DKWGEN_EXECUTABLE=/usr/bin/kwgen
20-
21-
RUN cmake --build build.wasi
22-
23-
RUN wasm-opt -O --strip-debug build.wasi/src/frontend/cxx -o build.wasi/src/frontend/cxx.wasm

scripts/build-wasi.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
me=$(dirname "$0")
6+
7+
project_root=$(cd "$me/.." && pwd)
8+
9+
DOCKER_EXTRA_OPTS="--rm -t -v ${project_root}:/code -w /code -u $(id -u) cxx-wasi"
10+
11+
docker build -t cxx-wasi -f Dockerfile.wasi ${project_root}
12+
13+
docker run ${DOCKER_EXTRA_OPTS} \
14+
cmake -G Ninja \
15+
-S . \
16+
-B build.wasi \
17+
-DCMAKE_INSTALL_PREFIX=build.wasi/install/usr \
18+
-DCMAKE_TOOLCHAIN_FILE=/usr/share/cmake/wasi-sdk.cmake \
19+
-DCMAKE_BUILD_TYPE=MinSizeRel \
20+
-DCMAKE_INTERPROCEDURAL_OPTIMIZATION=1 \
21+
-DKWGEN_EXECUTABLE=/usr/bin/kwgen \
22+
-DCXX_INSTALL_WASI_SYSROOT=ON \
23+
24+
docker run ${DOCKER_EXTRA_OPTS} \
25+
cmake --build build.wasi --target install
26+
27+

src/frontend/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ if(EMSCRIPTEN)
4141
endif()
4242

4343
if (CMAKE_SYSTEM_NAME STREQUAL "WASI")
44+
set_target_properties(cxx PROPERTIES SUFFIX ".wasm")
45+
4446
target_compile_definitions(cxx PRIVATE JSON_HAS_FILESYSTEM=0)
4547
target_compile_definitions(cxx PRIVATE CXX_NO_FILESYSTEM)
4648
endif()

src/frontend/cxx/frontend.cc

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ auto runOnFile(const CLI& cli, const std::string& fileName) -> bool {
239239
fs::path app_dir;
240240

241241
#if __wasi__
242-
app_dir = fs::path("/");
242+
app_dir = fs::path("/usr/bin/");
243243
#elif __unix__
244244
char* app_name = realpath(cli.app_name.c_str(), nullptr);
245245
app_dir = fs::path(app_name).remove_filename().string();
@@ -251,12 +251,7 @@ auto runOnFile(const CLI& cli, const std::string& fileName) -> bool {
251251
if (auto paths = cli.get("--sysroot"); !paths.empty()) {
252252
wasmToolchain->setSysroot(paths.back());
253253
} else {
254-
fs::path sysroot_dir;
255-
#if __wasi__
256-
sysroot_dir = fs::path("/wasi-sysroot");
257-
#elif __unix__
258-
sysroot_dir = app_dir / "../lib/wasi-sysroot";
259-
#endif
254+
auto sysroot_dir = app_dir / "../lib/wasi-sysroot";
260255
wasmToolchain->setSysroot(sysroot_dir.string());
261256
}
262257

src/parser/cxx/wasm32_wasi_toolchain.cc

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,25 @@ const std::string& Wasm32WasiToolchain::appdir() const { return appdir_; }
2929

3030
void Wasm32WasiToolchain::setAppdir(std::string appdir) {
3131
appdir_ = std::move(appdir);
32+
33+
if (!appdir_.empty() && appdir_.back() == '/') {
34+
appdir_.pop_back();
35+
}
3236
}
3337

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

3640
void Wasm32WasiToolchain::setSysroot(std::string sysroot) {
3741
sysroot_ = std::move(sysroot);
42+
43+
if (!sysroot_.empty() && sysroot_.back() == '/') {
44+
sysroot_.pop_back();
45+
}
3846
}
3947

4048
void Wasm32WasiToolchain::addSystemIncludePaths() {
4149
addSystemIncludePath(fmt::format("{}/include", sysroot_));
42-
43-
#if __wasi__
44-
addSystemIncludePath(fmt::format("/usr/lib/cxx/include", appdir_));
45-
#else
4650
addSystemIncludePath(fmt::format("{}/../lib/cxx/include", appdir_));
47-
#endif
4851
}
4952

5053
void Wasm32WasiToolchain::addSystemCppIncludePaths() {

0 commit comments

Comments
 (0)