Skip to content

Commit

Permalink
Add build workflow and build script
Browse files Browse the repository at this point in the history
  • Loading branch information
mnixry committed Jan 19, 2024
1 parent b114905 commit 7c51147
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 0 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: CI

on:
push:
pull_request:
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest
container: emscripten/emsdk:latest

strategy:
matrix:
processor: # ARM ARM (thumb) AArch64 Mips (32) Mips (64) PowerPC (32) PowerPC (64) Sparc x86 (16) x86 (32) x86 (64)
- arm
- arm64
- mips
- mips64
- powerpc
- powerpc64
- sparc
- i386
- x86_64
- riscv
- riscv64
- loongarch
- loongarch64
- wasm32

steps:
- uses: actions/checkout@v3

- name: Build
id: build
run: |
chmod +x ./build.sh
./build.sh ${{ matrix.processor }}-unknown-linux-gnu
- uses: actions/upload-artifact@v4
with:
name: build-${{ matrix.processor }}
path: ${{ steps.build.outputs.build.dir }}
74 changes: 74 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#!/bin/bash -xve

target=$1
if [ -z "$target" ]; then
echo "Usage: $0 <target>"
echo " target: processor target (e.g. riscv64-linux-gnu)"
exit 1
fi

src_dir="binutils"
build_dir_base=$(realpath -f"build")

target_paths=(
"binutils/addr2line"
"binutils/ar"
"binutils/cxxfilt"
"binutils/elfedit"
"binutils/nm-new"
"binutils/objcopy"
"binutils/objdump"
"binutils/ranlib"
"binutils/readelf"
"binutils/size"
"binutils/strings"
"binutils/strip-new"
"gas/as-new"
"gprof/gprof"
"ld/ld-new"
)

common_configure_flags=(
"--disable-doc"
"--disable-nls"
"--disable-gdb"
"--disable-gdbserver"
"--disable-libdecnumber"
"--disable-readline"
"--disable-sim"
"--host=wasm32"
"--target=${target}"
)

function build_binutils() {
build_type=$1
build_dir=$(realpath -f "$build_dir_base/$build_type")

git clean -fdx
git reset --hard HEAD
find . -name 'config.cache' -delete

emconfigure ./configure "${common_configure_flags[@]}"

ldflags="-sMODULARIZE=1 -sFORCE_FILESYSTEM=1 -sEXPORTED_RUNTIME_METHODS=FS"
if [ "$build_type" = "esm" ]; then
ldflags="${ldflags} -sEXPORT_ES6=1"
fi

emmake make -j$(nproc) \
"CFLAGS=-DHAVE_PSIGNAL=1 -DELIDE_CODE -Oz" \
"LDFLAGS=$ldflags"

mkdir -p "${build_dir}"
for path in "${target_paths[@]}"; do
cp "${path}" "${build_dir}/$(basename "${path}").js"
cp "${path}.wasm" "${build_dir}/$(basename "${path}").wasm"
done

return 0
}

build_binutils cjs
build_binutils esm

echo "dir=$build_dir_base" >> $GITHUB_OUTPUT

0 comments on commit 7c51147

Please sign in to comment.