From 585c0ef7d76648ec874a161a9b5ffcaaf1113009 Mon Sep 17 00:00:00 2001 From: Will Date: Sat, 13 Jul 2024 20:42:44 -0400 Subject: [PATCH] watcher/python, watcher/cross --- .github/workflows/libcwatcher-cross.yml | 23 ++++++++++ .github/workflows/libcwatcher.yml | 42 ------------------- libcwatcher/cross-compile.sh | 24 +++++++++++ .../cross-files/aarch64-apple-darwin.txt | 16 ++++++- .../cross-files/aarch64-unknown-linux-gnu.txt | 12 ------ .../cross-files/x86_64-apple-darwin.txt | 14 ++++++- .../cross-files/x86_64-unknown-linux-gnu.txt | 12 ------ .../Dockerfile | 6 +++ .../build-containers.sh | 6 +++ .../build.sh | 5 +++ libcwatcher/meson.build | 4 +- 11 files changed, 94 insertions(+), 70 deletions(-) create mode 100644 .github/workflows/libcwatcher-cross.yml delete mode 100644 .github/workflows/libcwatcher.yml create mode 100755 libcwatcher/cross-compile.sh delete mode 100644 libcwatcher/cross-files/aarch64-unknown-linux-gnu.txt delete mode 100644 libcwatcher/cross-files/x86_64-unknown-linux-gnu.txt create mode 100644 libcwatcher/linux-cross-compilation-containers/Dockerfile create mode 100755 libcwatcher/linux-cross-compilation-containers/build-containers.sh create mode 100755 libcwatcher/linux-cross-compilation-containers/build.sh diff --git a/.github/workflows/libcwatcher-cross.yml b/.github/workflows/libcwatcher-cross.yml new file mode 100644 index 00000000..d7b6ed4a --- /dev/null +++ b/.github/workflows/libcwatcher-cross.yml @@ -0,0 +1,23 @@ +name: libcwatcher-cross + +on: + push: + branches: [ release, next ] + pull_request: + branches: [ release, next ] + +jobs: + build-all: + runs-on: macos-14 + strategy: + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - run: | + which meson || brew install meson + - run: | + libcwatcher/cross-compile.sh + - uses: actions/upload-artifact@v4 + with: + path: libcwatcher/out diff --git a/.github/workflows/libcwatcher.yml b/.github/workflows/libcwatcher.yml deleted file mode 100644 index f06a512a..00000000 --- a/.github/workflows/libcwatcher.yml +++ /dev/null @@ -1,42 +0,0 @@ -name: libcwatcher - -on: - push: - branches: [ release, next ] - pull_request: - branches: [ release, next ] - -jobs: - build: - runs-on: ubuntu-24.04 - strategy: - matrix: - target-triple: - - x86_64-unknown-linux-gnu - - aarch64-unknown-linux-gnu - steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - uses: actions/cache@v4 - with: - path: ${{matrix.target-triple}} - key: cache.libcwatcher.${{matrix.target-triple}}.build - restore-keys: | - cache.libcwatcher.${{matrix.target-triple}}.build - - uses: actions/cache@v3 - with: - path: /var/cache/apt/archives - key: cache.libcwatcher.${{matrix.target-triple}}.apt-cache - restore-keys: | - cache.libcwatcher.${{matrix.target-triple}}.apt-cache - - run: | - which python3 || apt-get install -yqq python3 python3-pip python3-setuptools python3-wheel ninja-build - which meson || pip3 install meson - - run: | - meson setup --cross-file libcwatcher/cross-files/${{matrix.target-triple}}.txt ${{matrix.target-triple}} - meson compile -C ${{matrix.target-triple}} - - uses: actions/upload-artifact@v4 - with: - name: ${{matrix.target-triple}} - path: ${{matrix.target-triple}} diff --git a/libcwatcher/cross-compile.sh b/libcwatcher/cross-compile.sh new file mode 100755 index 00000000..b968b73d --- /dev/null +++ b/libcwatcher/cross-compile.sh @@ -0,0 +1,24 @@ +#! /usr/bin/env bash +set -e +[ -d "$(dirname "$0")/out" ] || mkdir "$(dirname "$0")/out" +cd "$(dirname "$0")" +linux-cross-compilation-containers/build-containers.sh +[ -f out/meson.build ] || cp meson.build out +[ -d out/src ] || cp -r src out +[ -d out/include ] || cp -r include out +( + cd out + SRC=$PWD + docker run --platform linux/amd64 --rm -v "$SRC:/src" meson-builder-x86_64-unknown-linux-gnu:latest + docker run --platform linux/arm64 --rm -v "$SRC:/src" meson-builder-aarch64-unknown-linux-gnu:latest + docker run --platform linux/arm/v7 --rm -v "$SRC:/src" meson-builder-armv7-unknown-linux-gnueabihf:latest +) +[ "$(uname)" = Darwin ] && { + [ -d out/x86_64-apple-darwin ] || meson setup --cross-file cross-files/x86_64-apple-darwin.txt out/x86_64-apple-darwin + [ -d out/aarch64-apple-darwin ] || meson setup --cross-file cross-files/aarch64-apple-darwin.txt out/aarch64-apple-darwin + meson compile -C out/x86_64-apple-darwin + meson compile -C out/aarch64-apple-darwin +} +for pattern in '*.a' '*.so' '*.dylib' +do find out -type f -name "$pattern" -exec file {} \; +done diff --git a/libcwatcher/cross-files/aarch64-apple-darwin.txt b/libcwatcher/cross-files/aarch64-apple-darwin.txt index 8b21934a..a9aadedd 100644 --- a/libcwatcher/cross-files/aarch64-apple-darwin.txt +++ b/libcwatcher/cross-files/aarch64-apple-darwin.txt @@ -3,10 +3,22 @@ c = 'clang' cpp = 'clang++' ar = 'ar' strip = 'strip' +pkg-config = 'pkg-config' -[host_machine] +[built-in options] +c_args = ['-target', 'aarch64-apple-darwin20.0.0', '-isysroot', '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk'] +cpp_args = ['-target', 'aarch64-apple-darwin20.0.0', '-isysroot', '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk'] +c_link_args = ['-target', 'aarch64-apple-darwin20.0.0', '-isysroot', '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk'] +cpp_link_args = ['-target', 'aarch64-apple-darwin20.0.0', '-isysroot', '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk'] + +[target_machine] system = 'darwin' cpu_family = 'aarch64' -cpu = 'arm' +cpu = 'aarch64' endian = 'little' +[host_machine] +system = 'darwin' +cpu_family = 'aarch64' +cpu = 'aarch64' +endian = 'little' diff --git a/libcwatcher/cross-files/aarch64-unknown-linux-gnu.txt b/libcwatcher/cross-files/aarch64-unknown-linux-gnu.txt deleted file mode 100644 index dc888aa1..00000000 --- a/libcwatcher/cross-files/aarch64-unknown-linux-gnu.txt +++ /dev/null @@ -1,12 +0,0 @@ -[binaries] -c = 'clang' -cpp = 'clang++' -ar = 'ar' -strip = 'strip' - -[host_machine] -system = 'linux' -cpu_family = 'aarch64' -cpu = 'aarch64' -endian = 'little' - diff --git a/libcwatcher/cross-files/x86_64-apple-darwin.txt b/libcwatcher/cross-files/x86_64-apple-darwin.txt index abe80243..eb5acf2d 100644 --- a/libcwatcher/cross-files/x86_64-apple-darwin.txt +++ b/libcwatcher/cross-files/x86_64-apple-darwin.txt @@ -3,10 +3,22 @@ c = 'clang' cpp = 'clang++' ar = 'ar' strip = 'strip' +pkg-config = 'pkg-config' -[host_machine] +[built-in options] +c_args = ['-target', 'x86_64-apple-darwin', '-isysroot', '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk'] +cpp_args = ['-target', 'x86_64-apple-darwin', '-isysroot', '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk'] +c_link_args = ['-target', 'x86_64-apple-darwin', '-isysroot', '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk'] +cpp_link_args = ['-target', 'x86_64-apple-darwin', '-isysroot', '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk'] + +[target_machine] system = 'darwin' cpu_family = 'x86_64' cpu = 'x86_64' endian = 'little' +[host_machine] +system = 'darwin' +cpu_family = 'x86_64' +cpu = 'x86_64' +endian = 'little' diff --git a/libcwatcher/cross-files/x86_64-unknown-linux-gnu.txt b/libcwatcher/cross-files/x86_64-unknown-linux-gnu.txt deleted file mode 100644 index 8a3ae15e..00000000 --- a/libcwatcher/cross-files/x86_64-unknown-linux-gnu.txt +++ /dev/null @@ -1,12 +0,0 @@ -[binaries] -c = 'clang' -cpp = 'clang++' -ar = 'ar' -strip = 'strip' - -[host_machine] -system = 'linux' -cpu_family = 'x86_64' -cpu = 'x86_64' -endian = 'little' - diff --git a/libcwatcher/linux-cross-compilation-containers/Dockerfile b/libcwatcher/linux-cross-compilation-containers/Dockerfile new file mode 100644 index 00000000..a46ff99d --- /dev/null +++ b/libcwatcher/linux-cross-compilation-containers/Dockerfile @@ -0,0 +1,6 @@ +FROM debian:latest +ARG BUILD_DIR +RUN apt-get update -yqq && apt-get install -yqq build-essential meson ninja-build +COPY build.sh /usr/local/bin/build.sh +ENV BUILD_DIR=$BUILD_DIR +ENTRYPOINT ["build.sh"] diff --git a/libcwatcher/linux-cross-compilation-containers/build-containers.sh b/libcwatcher/linux-cross-compilation-containers/build-containers.sh new file mode 100755 index 00000000..50c645dc --- /dev/null +++ b/libcwatcher/linux-cross-compilation-containers/build-containers.sh @@ -0,0 +1,6 @@ +#! /usr/bin/env bash +set -e +cd "$(dirname "$0")" +docker build -t meson-builder-x86_64-unknown-linux-gnu --build-arg BUILD_DIR=x86_64-unknown-linux-gnu --platform linux/amd64 . +docker build -t meson-builder-aarch64-unknown-linux-gnu --build-arg BUILD_DIR=aarch64-unknown-linux-gnu --platform linux/arm64 . +docker build -t meson-builder-armv7-unknown-linux-gnueabihf --build-arg BUILD_DIR=armv7-unknown-linux-gnueabihf --platform linux/arm/v7 . diff --git a/libcwatcher/linux-cross-compilation-containers/build.sh b/libcwatcher/linux-cross-compilation-containers/build.sh new file mode 100755 index 00000000..eded487b --- /dev/null +++ b/libcwatcher/linux-cross-compilation-containers/build.sh @@ -0,0 +1,5 @@ +#! /usr/bin/env sh +set -e +cd /src +[ -d "$BUILD_DIR" ] || meson setup "$BUILD_DIR" +meson compile -C "$BUILD_DIR" diff --git a/libcwatcher/meson.build b/libcwatcher/meson.build index 741a636d..9eac5604 100644 --- a/libcwatcher/meson.build +++ b/libcwatcher/meson.build @@ -5,10 +5,12 @@ project( default_options : ['c_std=c99', 'cpp_std=c++20'], ) +# I know it's not the convential way to version a shared library... +# But I'm not sure how to do it the "right" way in Meson. libname = 'cwatcher-' + meson.project_version() if target_machine.system() == 'darwin' - deps = dependency('appleframeworks', ['CoreServices', 'CoreFoundation']) + deps = dependency(['CoreServices', 'CoreFoundation']) else deps = dependency('threads') endif