From 3eda5eef82bcf4b297d25edacb19625db326bd5d Mon Sep 17 00:00:00 2001 From: Peter Salomonsen Date: Sun, 17 Dec 2023 13:33:33 +0000 Subject: [PATCH] wasi build --- .devcontainer/devcontainer.json | 2 +- .devcontainer/post-create.sh | 20 +++++++++++++++++++- .gitignore | 2 +- setup.sh | 2 ++ setup_wasi.sh | 6 ++++++ wasibuild/.gitignore | 11 +++++++++++ wasibuild/build.sh | 14 ++++++++++++++ 7 files changed, 54 insertions(+), 3 deletions(-) create mode 100755 setup_wasi.sh create mode 100644 wasibuild/.gitignore create mode 100755 wasibuild/build.sh diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index cf7a923b..e04ec439 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -2,7 +2,7 @@ "postCreateCommand": "/workspaces/wasm-git/.devcontainer/post-create.sh", "customizations": { "vscode": { - "extensions": [] + "extensions": ["dtsvet.vscode-wasm","ms-vscode.cpptools-extension-pack"] } } } diff --git a/.devcontainer/post-create.sh b/.devcontainer/post-create.sh index 75d0166d..d1c9e047 100755 --- a/.devcontainer/post-create.sh +++ b/.devcontainer/post-create.sh @@ -1,5 +1,5 @@ #!/bin/bash - +curl https://wasmtime.dev/install.sh -sSf | bash npm install sh setup.sh @@ -9,3 +9,21 @@ git pull ./emsdk install latest ./emsdk activate latest cd .. + +sudo apt update +sudo apt install -y clang-12 +sudo apt install -y lld-12 +sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-12 100 +sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-12 100 + +sudo ln -s /usr/bin/wasm-ld-12 /usr/bin/wasm-ld + +cd wasibuild + +wget https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-20/wasi-sdk-20.0-linux.tar.gz +tar -xvzf wasi-sdk-20.0-linux.tar.gz +sudo cp -r wasi-sdk-20.0/lib/clang/16/lib/wasi /usr/lib/llvm-12/lib/clang/12.0.0/lib/ + +cd .. + +curl https://wasmtime.dev/install.sh -sSf | bash diff --git a/.gitignore b/.gitignore index e268c01f..a07c52d8 100644 --- a/.gitignore +++ b/.gitignore @@ -10,4 +10,4 @@ package .idea emsdk nodefsclonetest -google-chrome-stable_current_amd64.deb \ No newline at end of file +google-chrome-stable_current_amd64.deb diff --git a/setup.sh b/setup.sh index b538bb60..699037c1 100755 --- a/setup.sh +++ b/setup.sh @@ -1,3 +1,5 @@ +#!/bin/bash + curl -L https://github.com/libgit2/libgit2/archive/refs/tags/v1.7.1.tar.gz --output libgit2.tar.gz tar -xzf libgit2.tar.gz mv libgit2-1.7.1 libgit2 diff --git a/setup_wasi.sh b/setup_wasi.sh new file mode 100755 index 00000000..a384abc3 --- /dev/null +++ b/setup_wasi.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +curl -L https://github.com/libgit2/libgit2/archive/refs/tags/v1.7.1.tar.gz --output libgit2.tar.gz +tar -xzf libgit2.tar.gz +mv libgit2-1.7.1 libgit2 +rm libgit2.tar.gz diff --git a/wasibuild/.gitignore b/wasibuild/.gitignore new file mode 100644 index 00000000..5f196863 --- /dev/null +++ b/wasibuild/.gitignore @@ -0,0 +1,11 @@ +CMake* +src +deps +examples +libgit2* +include +Makefile +*.cmake +*.a +tests +wasi-sdk* diff --git a/wasibuild/build.sh b/wasibuild/build.sh new file mode 100755 index 00000000..825acb6f --- /dev/null +++ b/wasibuild/build.sh @@ -0,0 +1,14 @@ +#!/bin/bash +BUILD_TYPE=Debug + +# Set build type to Release for release +if [ "$1" == "Release" ]; then + BUILD_TYPE=Release + EXTRA_CMAKE_C_FLAGS="-Oz" +fi + +cmake -D CMAKE_C_COMPILER=clang -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DCMAKE_C_FLAGS="--target=wasm32-wasi --sysroot=wasi-sdk-20.0/share/wasi-sysroot $EXTRA_CMAKE_C_FLAGS" -DREGEX_BACKEND=regcomp -DSONAME=OFF -DUSE_HTTPS=OpenSSL -DBUILD_SHARED_LIBS=OFF -DTHREADSAFE=OFF -DUSE_SSH=OFF -DBUILD_CLAR=OFF -DBUILD_EXAMPLES=ON ../libgit2 +make lg2 VERBOSE=1 + + + cd /workspaces/wasm-git/wasibuild/src/util && /usr/bin/clang -DOPENSSL_API_COMPAT=0x10100000L -DSHA1DC_CUSTOM_INCLUDE_SHA1_C=\"git2_util.h\" -DSHA1DC_CUSTOM_INCLUDE_UBC_CHECK_C=\"git2_util.h\" -DSHA1DC_NO_STANDARD_INCLUDES=1 -I/workspaces/wasm-git/wasibuild/src/util -I/workspaces/wasm-git/wasibuild/include -I/workspaces/wasm-git/libgit2/src/util -I/workspaces/wasm-git/libgit2/include -I/workspaces/wasm-git/libgit2/deps/http-parser -I/workspaces/wasm-git/libgit2/deps/xdiff -I/workspaces/wasm-git/libgit2/deps/ntlmclient -D_GNU_SOURCE -Wall -Wextra -Wdocumentation -Wno-documentation-deprecated-sync -Wno-missing-field-initializers -Wmissing-declarations -Wstrict-aliasing -Wstrict-prototypes -Wdeclaration-after-statement -Wshift-count-overflow -Wunused-const-variable -Wunused-function -Wint-conversion -Wc11-extensions -Wformat -Wformat-security -g -D_DEBUG -O0 -std=gnu90 -o CMakeFiles/util.dir/alloc.c.o -c /workspaces/wasm-git/libgit2/src/util/alloc.c \ No newline at end of file