Skip to content

Commit

Permalink
Cache github actions
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanharg committed Mar 6, 2024
1 parent e1683e4 commit a0f0216
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 39 deletions.
16 changes: 15 additions & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,23 @@ jobs:
if: runner.os == 'Windows'
run: 'choco install wget -y'

- name: Restore cached libbinaryen
id: cache-libbinaryen-restore
uses: actions/cache/restore@v4
with:
path: ./binaryen/libbinaryen
key: ${{ matrix.os }}-${{ runner.os }}-${{ runner.arch }}-v${{env.BINARYEN_VERSION}}-libbinaryen

- name: Build wheels
uses: pypa/[email protected]

- name: Cache libbinaryen
id: cache-libbinaryen-save
uses: actions/cache/save@v4
with:
path: ./binaryen/libbinaryen
key: ${{steps.cache-libbinaryen-restore.outputs.cache-primary-key}}

- uses: actions/upload-artifact@v4
with:
name: binaryen-py-${{ matrix.os }}-${{ strategy.job-index }}
Expand All @@ -59,5 +73,5 @@ jobs:

- uses: actions/upload-artifact@v4
with:
name: cibw-sdist
name: binaryen-py-sdist
path: dist/*.tar.gz
33 changes: 3 additions & 30 deletions BUILD.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,5 @@
# Building or updating Binaryen.py

1. Put the new precompiled dynamic libraries in `binaryen/libbinaryen` for all architectures for all operating systems
2. Update the `binaryen-c.h` and `wasm-delegations.def`
3. Delete the existing `binaryen-c.c` and run `python binaryen/libbinaryen/create_cdef.py`
4. Replace any unions in the ouputed `binaryen-c.c` to the largest of their contents
5. Copy the contents of `binaryen-c.c` to the `cdef` variable in `binaryen_build.py`
6. *Optional* run `python binaryen_build.py`

## Replacing unions

Replace all unions so that the largest type of the union is used instead. CFFI can't do this automatically without the full C source.

```c
// Change
struct BinaryenLiteral {
uintptr_t type;
union {
int32_t i32;
int64_t i64;
float f32;
double f64;
uint8_t v128[16];
const char* func;
};
};
// to
struct BinaryenLiteral {
uintptr_t type;
uint8_t v128[16];
};
```
1. (Optional) Update `BINARYEN_VERSION` in `pyproject.toml` and `.github/workflows/build.yaml`
2. Run `bash scripts/build_libbinaryen.sh`
3. Run `cibuildwheel`, `python -m pip wheel .`, `python -m pip install -e .` or whichever supported build command you would prefer
31 changes: 27 additions & 4 deletions scripts/build_libbinaryen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,37 @@ if [ -z ${BINARYEN_VERSION+x} ]; then
exit 1
fi

lib_path="./binaryen/libbinaryen/$arch-$platform"
mkdir -p $lib_path

if grep -Fxq $BINARYEN_VERSION $lib_path/version; then
# Existing version found
echo "Found existing binaryen installation, skipping."
echo "You may need to clear the binaryen/libbinaryen folder if errors occur"
exit 0
fi

wildcards="--wildcards"

if [[ "$platform" == "macos" ]]; then
wildcards=""
fi

lib_path="./binaryen/libbinaryen/$arch-$platform/"
mkdir -p $lib_path
echo "Setting up binaryen for $arch $platform"

if [[ "$platform" == "macos" ]]; then
echo "Building static binaryen for MacOS"
mkdir -p "./binaryen/libbinaryen/src/"

file="version_$BINARYEN_VERSION.tar.gz"
url="https://github.com/WebAssembly/binaryen/archive/refs/tags/$file"

wget -q -nc --no-check-certificate --content-disposition $url -P "./binaryen/libbinaryen"
echo "Downloaded source code"

tar -xzf "./binaryen/libbinaryen/binaryen-$file" -C "./binaryen/libbinaryen/src" --strip-components=1
echo "Extracted source code"

cmake -S "./binaryen/libbinaryen/src" -B "./binaryen/libbinaryen/build/" -G Ninja \
-DCMAKE_INSTALL_PREFIX="$lib_path" -DCMAKE_OSX_ARCHITECTURES=$arch \
-DCMAKE_BUILD_TYPE=Release -DBUILD_TESTS=OFF -DBUILD_TOOLS=OFF \
Expand All @@ -53,12 +69,19 @@ if [[ "$platform" == "macos" ]]; then
else
file="binaryen-version_$BINARYEN_VERSION-$arch-$platform.tar.gz"
url="https://github.com/WebAssembly/binaryen/releases/download/version_$BINARYEN_VERSION/$file"

wget -q -nc --no-check-certificate --content-disposition $url -P $lib_path
tar -xzf $lib_path$file -C $lib_path --strip-components=1 $wildcards \
echo "Downloaded release $BINARYEN_VERSION"

tar -xzf $lib_path/$file -C $lib_path --strip-components=1 $wildcards \
"binaryen-version_$BINARYEN_VERSION/include/binaryen-c.h" \
"binaryen-version_$BINARYEN_VERSION/include/wasm-delegations.def" \
"binaryen-version_$BINARYEN_VERSION/lib/*"
echo "Extracted release"
fi

echo "Running python script"
echo "Generating C def file"
python3 ./scripts/create_cdef.py
echo "Successfully generated C def file"

echo "$BINARYEN_VERSION" >| $lib_path/version
4 changes: 0 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,4 @@
setup_requires=["cffi>=1.15.0"],
cffi_modules=["binaryen/binaryen_build.py:ffibuilder"],
install_requires=["cffi>=1.15.0"],
# include_package_data=True
# package_data={
# "binaryen": ["libbinaryen/binaryen-c.c","libbinaryen/binaryen-c.h", "libbinaryen/wasm-delegations.def", "libbinaryen/*.dylib", "libbinaryen/*.a", "libbinaryen/*.lib"]
# },
)

0 comments on commit a0f0216

Please sign in to comment.