-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tool/cross: build for common linux, apple triplets
- Loading branch information
Will
committed
Sep 14, 2024
1 parent
05e4416
commit fb1528e
Showing
3 changed files
with
175 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters