Skip to content

Commit

Permalink
tool/cross: build for common linux, apple triplets
Browse files Browse the repository at this point in the history
  • Loading branch information
Will committed Sep 14, 2024
1 parent 05e4416 commit fb1528e
Show file tree
Hide file tree
Showing 3 changed files with 175 additions and 6 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/dist.yml
Original file line number Diff line number Diff line change
@@ -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
110 changes: 110 additions & 0 deletions tool/cross
Original file line number Diff line number Diff line change
@@ -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 <<EOF
aarch64-unknown-linux-gnu aarch64-linux-gnu
armv7-unknown-linux-gnueabihf arm-linux-gnueabihf
x86_64-unknown-linux-gnu x86_64-linux-gnu
aarch64-unknown-linux-musl aarch64-linux-musl
armv7-unknown-linux-musleabihf arm-linux-musleabihf
x86_64-unknown-linux-musl x86_64-linux-musl
EOF
}
macos-cross() {
case "$(uname -m)" in
arm64) triple=aarch64-apple-darwin ;;
*) echo "Unsupported architecture: $(uname -m)" ; exit 1 ;;
esac
cc() {
(
[ "$verbose" = true ] && set -x
c++ \
-target "$triple" \
-I watcher-c/include \
-I include \
-std=c++17 \
-fno-exceptions \
-fno-rtti \
-fno-omit-frame-pointer \
-fstrict-enums \
-fstrict-overflow \
-fstrict-aliasing \
-fstack-protector-strong \
-Os \
-framework CoreFoundation \
-framework CoreServices \
$@
)
}
build() {
if [ -e "$1" ]
then echo "[$triple] Exists: $1"
else
[ -d "$(dirname "$1")" ] || mkdir -p "$(dirname "$1")"
cc -o "$1" "${@:2}"
echo -n "[$triple] Built: " ; file "$1"
fi
}
echo "$@" | grep -q -- --target && { echo "$@" | grep -q -- "--target-$triple" || return ; }
echo "$@" | grep -q -- --clean && rm -rf "out/$triple"
build "out/$triple/libwatcher-c.so" -shared -fPIC watcher-c/src/watcher-c.cpp
build "out/$triple/watcher" src/wtr/watcher/main.cpp
build "out/$triple/tw" 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
}
linux-cross "$@"
if uname | grep -q Darwin
then macos-cross "$@"
fi
20 changes: 14 additions & 6 deletions tool/shasum.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,22 @@ def sha256sum_tree(path) -> 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:
Expand Down

0 comments on commit fb1528e

Please sign in to comment.