diff --git a/.github/workflows/dist.yml b/.github/workflows/dist.yml new file mode 100644 index 00000000..79868957 --- /dev/null +++ b/.github/workflows/dist.yml @@ -0,0 +1,51 @@ +name: Dist + +on: + push: + branches: [ release, next ] + pull_request: + branches: [ release, next ] + +jobs: + linux-dist: + runs-on: ubuntu-24.04 + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - run: tool/cross --target-x86_64-unknown-linux-musl --target-x86_64-unknown-linux-gnu --target-x86_64-apple-darwin --target-armv7-unknown-linux-musleabihf --target-armv7-unknown-linux-gnueabihf --target-aarch64-unknown-linux-musl --target-aarch64-unknown-linux-gnu + - uses: actions/upload-artifact@v4 + with: + name: x86_64-unknown-linux-musl + path: out/x86_64-unknown-linux-musl + - uses: actions/upload-artifact@v4 + with: + name: x86_64-unknown-linux-gnu + path: out/x86_64-unknown-linux-gnu + - uses: actions/upload-artifact@v4 + with: + name: armv7-unknown-linux-musleabihf + path: out/armv7-unknown-linux-musleabihf + - uses: actions/upload-artifact@v4 + with: + name: armv7-unknown-linux-gnueabihf + path: out/armv7-unknown-linux-gnueabihf + - uses: actions/upload-artifact@v4 + with: + name: aarch64-unknown-linux-musl + path: out/aarch64-unknown-linux-musl + - uses: actions/upload-artifact@v4 + with: + name: aarch64-unknown-linux-gnu + path: out/aarch64-unknown-linux-gnu + macos-dist: + runs-on: macos-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - run: tool/cross --target-aarch64-apple-darwin + - uses: actions/upload-artifact@v4 + with: + name: aarch64-apple-darwin + path: out/aarch64-apple-darwin diff --git a/tool/cross b/tool/cross new file mode 100755 index 00000000..06232738 --- /dev/null +++ b/tool/cross @@ -0,0 +1,110 @@ +#! /usr/bin/env bash +set -e +cd "$(dirname "$0")/.." +version=$(cat .version) +verbose=$(echo "$@" | grep -q -- --verbose && echo true || echo false) +linux-cross() { + while read -r triple toolchain_name + do + crossc() { + ( + img=wlinkmeyer/$(uname -m)-cross + [ "$verbose" = true ] && set -x + docker run -v "$PWD:/src" --rm "$img" \ + "${toolchain_name}-g++" \ + --sysroot "/etc/sysroots/$triple" \ + -I "/usr/include/$toolchain_name" \ + -I "/etc/sysroots/$triple/usr/include" \ + -I "/etc/sysroots/$triple/usr/include/c++/12" \ + -I "/etc/sysroots/$triple/usr/include/$toolchain_name" \ + -I "/etc/sysroots/$triple/usr/include/$toolchain_name/c++/12" \ + -I /src/watcher-c/include \ + -I /src/include \ + -std=c++17 \ + -fno-exceptions \ + -fno-rtti \ + -fexpensive-optimizations \ + -fno-omit-frame-pointer \ + -fstrict-enums \ + -fstrict-overflow \ + -fstrict-aliasing \ + -fstack-protector-strong \ + -Os \ + $@ + ) + } + build() { + if [ -e "$1" ] + then echo "[$triple] Exists: $1" + else + [ -d "$(dirname "$1")" ] || mkdir -p "$(dirname "$1")" + crossc -o "/src/$1" "${@:2}" + sudo chown "$USER" "$1" + echo -n "[$triple] Built: " ; file "$1" + fi + } + echo "$@" | grep -q -- --target && { echo "$@" | grep -q -- "--target-$triple" || continue ; } + echo "$@" | grep -q -- --clean && rm -rf "out/$triple" + build "out/$triple/libwatcher-c.so" -shared -fPIC /src/watcher-c/src/watcher-c.cpp + build "out/$triple/watcher" /src/src/wtr/watcher/main.cpp + build "out/$triple/tw" /src/src/wtr/tiny_watcher/main.cpp + [ -e "out/$triple/libwatcher-c.so.$version" ] || cp "out/$triple/libwatcher-c.so" "out/$triple/libwatcher-c.so.$version" + [ -f "out/$triple/watcher.hpp" ] || cp include/wtr/watcher.hpp "out/$triple/watcher.hpp" + python3 tool/shasum.py "out/$triple" mk + done < dict: """ Similar to mk_dot_sha256sums, but returns a mapping of file paths to their shasums, not file path.sha256sum to shasums. + Skips already existing .sha256sum files, and files that already + have .sha256sum counterparts. """ if os.path.isfile(path): - return {path: sha256sum(path)} - tree = {} - for root, dirs, files in os.walk(path): - for p in dirs + files: - tree.update(sha256sum_tree(os.path.join(root, p))) - return tree + if path.endswith(".sha256sum"): + return {} + elif os.path.exists(f"{path}.sha256sum"): + return {} + else: + return {path: sha256sum(path)} + else: + tree = {} + for root, dirs, files in os.walk(path): + for p in dirs + files: + tree.update(sha256sum_tree(os.path.join(root, p))) + return tree def mk_dot_sha256sums(path) -> None: