-
Notifications
You must be signed in to change notification settings - Fork 5
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
Add compilation to NodeJS module #111
base: main
Are you sure you want to change the base?
Changes from 38 commits
5ac67bd
88a888d
9b23e19
4f6debc
d260472
b7b28ef
b6baf6c
a934ec2
94445ba
c51d50b
c0a82ce
8c7d18a
007b79e
1837643
7f3d0ce
9a8003a
2551769
90423ff
677aedc
8a22587
93d2f3b
6e6fe20
f59b47d
64fefe7
6d16790
14991f4
ce8bf3d
563864d
010a2ed
140545e
881b883
f57ab96
cece20d
87dd77b
d88ddb2
3072c03
63da721
39e5047
f36d62c
cdebf69
7740626
fcbe00f
4918507
0a82add
a772ff1
32d4b23
8990b2a
05925f2
892c9b5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
name: Build revive-wasm | ||
on: | ||
push: | ||
branches: ["main"] | ||
pull_request: | ||
branches: ["main"] | ||
workflow_dispatch: | ||
|
||
env: | ||
CARGO_TERM_COLOR: always | ||
REVIVE_WASM_INSTALL_DIR: ${{ github.workspace }}/target/wasm32-unknown-emscripten/release | ||
EMSCRIPTEN_VERSION: 3.1.64 | ||
|
||
jobs: | ||
build-revive-wasm: | ||
runs-on: ubuntu-latest | ||
defaults: | ||
run: | ||
shell: bash | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Cache LLVM build | ||
id: cache-llvm | ||
uses: actions/cache@v3 | ||
with: | ||
path: | | ||
llvm18.0-emscripten | ||
# Use a unique key based on LLVM version or configuration files to avoid cache invalidation | ||
key: llvm-build-${{ runner.os }}-${{ hashFiles('clone-llvm.sh', 'emscripten-build-llvm.sh') }} | ||
|
||
- name: Install Dependencies | ||
run: | | ||
sudo apt-get update && sudo apt-get install -y cmake ninja-build libncurses5 | ||
rustup target add wasm32-unknown-emscripten | ||
# Install LLVM required for the compiler runtime, runtime-api and stdlib | ||
curl -sSL --output llvm.tar.xz https://github.com/llvm/llvm-project/releases/download/llvmorg-18.1.4/clang+llvm-18.1.4-x86_64-linux-gnu-ubuntu-18.04.tar.xz | ||
tar Jxf llvm.tar.xz | ||
mv clang+llvm-18.1.4-x86_64-linux-gnu-ubuntu-18.04 llvm18/ | ||
echo "$(pwd)/llvm18/bin" >> $GITHUB_PATH | ||
athei marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# Install Emscripten | ||
git clone https://github.com/emscripten-core/emsdk.git | ||
cd emsdk | ||
./emsdk install ${{ env.EMSCRIPTEN_VERSION }} | ||
./emsdk activate ${{ env.EMSCRIPTEN_VERSION }} | ||
Comment on lines
+41
to
+45
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should check out a specific tag here. Otherwise we build against a different version every time. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we are using the version defined in |
||
|
||
- run: | | ||
rustup show | ||
cargo --version | ||
rustup +nightly show | ||
cargo +nightly --version | ||
cmake --version | ||
bash --version | ||
llvm-config --version | ||
|
||
- name: Build LLVM | ||
if: steps.cache-llvm.outputs.cache-hit != 'true' | ||
run: | | ||
export EMSDK_ROOT=${PWD}/emsdk | ||
./emscripten-build-llvm.sh | ||
|
||
- name: Use Cached LLVM | ||
if: steps.cache-llvm.outputs.cache-hit == 'true' | ||
run: | | ||
echo "Using cached LLVM" | ||
|
||
- name: Build revive | ||
run: | | ||
export LLVM_LINK_PREFIX=${PWD}/llvm18.0-emscripten | ||
source ./emsdk/emsdk_env.sh | ||
make install-wasm | ||
|
||
- uses: actions/upload-artifact@v4 | ||
with: | ||
name: revive-wasm | ||
path: | | ||
${{ env.REVIVE_WASM_INSTALL_DIR }}/resolc.js | ||
${{ env.REVIVE_WASM_INSTALL_DIR }}/resolc.wasm | ||
Comment on lines
+76
to
+78
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are those all the files that are needed? What about the hand written javascript files in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will add npm package with its workflow in next PR. Now we need these 2 files only. |
||
retention-days: 1 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -27,7 +27,25 @@ resolc --version | |||||
|
||||||
### LLVM | ||||||
|
||||||
`revive` requires a build of LLVM 18.1.4 or later including `compiler-rt`. Use the provided [build-llvm.sh](build-llvm.sh) build script to compile a compatible LLVM build locally in `$PWD/llvm18.0` (don't forget to add that to `$PATH` afterwards). | ||||||
`revive` requires a build of LLVM 18.1.4 or later including `compiler-rt`. Use the provided [build-llvm.sh](build-llvm.sh) build script to compile a compatible LLVM build locally in `$PWD/llvm18.0` (don't forget to add that to `$PATH` afterwards). | ||||||
|
||||||
### Cross-compilation to WASM | ||||||
|
||||||
Cross-compiles the Revive recompiler to WASM to enable it to run in a Node.js or browser environment. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||||||
|
||||||
Install [emscripten](https://emscripten.org/docs/getting_started/downloads.html). Tested on version 3.1.64. | ||||||
To build resolc.js execute: | ||||||
|
||||||
```bash | ||||||
bash build-llvm.sh | ||||||
export PATH=${PWD}/llvm18.0/bin:$PATH | ||||||
export EMSDK_ROOT=<PATH_TO_EMSCRIPTEN_SDK> | ||||||
bash emscripten-build-llvm.sh | ||||||
source $EMSDK_ROOT/emsdk_env.sh | ||||||
export LLVM_LINK_PREFIX=${PWD}/llvm18.0-emscripten | ||||||
export PATH=$PATH:$PWD/llvm18.0-emscripten/bin/ | ||||||
make install-wasm | ||||||
``` | ||||||
|
||||||
### Development | ||||||
|
||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,17 +5,12 @@ set -euo pipefail | |
INSTALL_DIR="${PWD}/llvm18.0" | ||
mkdir -p ${INSTALL_DIR} | ||
|
||
|
||
# Clone LLVM 18 (any revision after commit bd32aaa is supposed to work) | ||
if [ ! -d "llvm-project" ]; then | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should clone into There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
git clone --depth 1 --branch release/18.x https://github.com/llvm/llvm-project.git | ||
fi | ||
|
||
./clone-llvm.sh | ||
|
||
# Build LLVM, clang | ||
LLVM_SRC_PREFIX=${PWD}/llvm-project | ||
LLVM_SRC_DIR=${LLVM_SRC_PREFIX}/llvm | ||
LLVM_BUILD_DIR=${PWD}/build/llvm | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this changed? Before the target build directory was outside the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have aligned it to this what i have in emscripten build: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes please I think it is a standard practice to keep the build outside the source, i.e. leave it as it is now. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
LLVM_BUILD_DIR=${LLVM_SRC_PREFIX}/build/llvm | ||
if [ ! -d ${LLVM_BUILD_DIR} ] ; then | ||
mkdir -p ${LLVM_BUILD_DIR} | ||
fi | ||
|
@@ -38,7 +33,7 @@ cmake --install ${LLVM_BUILD_DIR} | |
|
||
# Build compiler builtins | ||
COMPILER_RT_SRC_DIR=${LLVM_SRC_PREFIX}/compiler-rt | ||
COMPILER_RT_BUILD_DIR=${PWD}/build/compiler-rt | ||
COMPILER_RT_BUILD_DIR=${LLVM_SRC_PREFIX}/build/compiler-rt | ||
if [ ! -d ${COMPILER_RT_BUILD_DIR} ] ; then | ||
mkdir -p ${COMPILER_RT_BUILD_DIR} | ||
fi | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/bin/bash | ||
smiasojed marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# Clone LLVM 18 (any revision after commit bd32aaa is supposed to work) | ||
if [ ! -d "llvm-project" ]; then | ||
git clone --depth 1 --branch release/18.x https://github.com/llvm/llvm-project.git | ||
fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need the manual dispatch even though we build for every PR and master commit?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it uses 1day retention period, I left it in case someone would like to recreate artefacts.