diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..30c019e --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,89 @@ +name: Build releases + +on: + workflow_dispatch: + pull_request: + types: [opened, synchronize] + +jobs: + build: + strategy: + matrix: + include: + - os: macos-latest-large + target: aarch64-apple-darwin + - os: macos-latest-large + target: aarch64-apple-ios + - os: macos-latest-large + # cross-compile for Linux ARM using Apple Silicon until we have ARM runners + target: aarch64-unknown-linux-musl + - os: macos-latest + target: x86_64-apple-darwin + - os: ubuntu-latest + target: x86_64-unknown-linux-musl + # - os: windows-latest + # target: x86_64-pc-windows-msvc + name: Build ${{matrix.target}} + runs-on: ${{matrix.os}} + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Get short SHA + id: sha + run: echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT + + - name: Install build tools (Linux) + if: ${{matrix.os == 'ubuntu-latest'}} + run: | + sudo apt-get update + sudo apt-get install musl-tools + + - name: Install Rust toolchain + uses: dtolnay/rust-toolchain@1.70.0 + with: + components: llvm-tools-preview + target: ${{matrix.target}} + + - name: Install cbindgen + run: cargo install cbindgen + + - name: Cache Rust dependencies + uses: Swatinem/rust-cache@v2 + with: + shared-key: ${{matrix.target}} + + - name: Install musl for mac -> linux cross compilation + if: ${{matrix.target == 'aarch64-unknown-linux-musl'}} + run: brew install filosottile/musl-cross/musl-cross + + - name: Build library + env: + CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER: aarch64-linux-musl-gcc + run: make TARGET=${{matrix.target}} release + + - name: Run C tests + if: ${{matrix.os != 'windows-latest'}} + run: make TARGET=${{matrix.target}} test-c + + - name: Run C++ tests + if: ${{matrix.os != 'windows-latest'}} + run: make TARGET=${{matrix.target}} test-cpp + + - name: Show Windows warning + if: ${{matrix.os == 'windows-latest'}} + run: echo "::warning::C/C++ tests did NOT run in Windows" + + - name: Move files to main folder + run: mv target/release/libc2pa_c* . + + - name: Add files to archive + uses: actions/upload-artifact@v4 + with: + name: c2pa-c_${{matrix.target}}-${{ steps.sha.outputs.sha_short }}.zip + path: | + README.md + include/** + examples/** + libc2pa_c* + retention-days: 3 diff --git a/.gitignore b/.gitignore index 349614d..01f09e7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ /target +/dist +/include /Cargo.lock .vscode diff --git a/Cargo.toml b/Cargo.toml index 24e112a..a06ab90 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,4 +12,4 @@ c2pa = {version="0.28.4", features = ["file_io", "add_thumbnails", "fetch_remote serde = { version = "1.0", features = ["derive"] } serde_derive = "1.0" serde_json = "1.0" -thiserror = "1.0.49" \ No newline at end of file +thiserror = "1.0.49" diff --git a/Makefile b/Makefile index ea2da07..ecf2dda 100644 --- a/Makefile +++ b/Makefile @@ -8,6 +8,12 @@ ifeq ($(OS), Linux) CFLAGS = -pthread -Wl,--no-as-needed -ldl -lm ENV = LD_LIBRARY_PATH=target/release endif +ifneq (,$(findstring musl,$(TARGET))) +CC = musl-gcc +GCC = musl-g++ +else +GCC = g++ +endif check-format: cargo fmt -- --check @@ -19,19 +25,19 @@ test-rust: cargo test --all-features release: - cargo build --release + cargo build --release --target $(TARGET) cbindgen --config cbindgen.toml --crate c2pa-c --output include/c2pa.h --lang c -test-c: release - $(CC) $(CFLAGS) tests/test.c -o target/ctest -lc2pa_c -L./target/release - $(ENV) target/ctest +test-c: + $(CC) $(CFLAGS) tests/test.c -o target/$(TARGET)/ctest -lc2pa_c -L./target/$(TARGET)/release + LD_LIBRARY_PATH=$$LD_LIBRARY_PATH:./target/$(TARGET)/release target/$(TARGET)/ctest -test-cpp: release - g++ $(CFLAGS) -std=c++17 tests/test.cpp -o target/cpptest -lc2pa_c -L./target/release - $(ENV) target/cpptest +test-cpp: + $(GCC) $(CFLAGS) -std=c++11 tests/test.cpp -o target/$(TARGET)/cpptest -lc2pa_c -L./target/$(TARGET)/release + LD_LIBRARY_PATH=$$LD_LIBRARY_PATH:./target/$(TARGET)/release target/$(TARGET)/cpptest example: release - g++ $(CFLAGS) -std=c++17 examples/training.cpp -o target/training -lc2pa_c -L./target/release + $(GCC) $(CFLAGS) -std=c++17 examples/training.cpp -o target/training -lc2pa_c -L./target/release $(ENV) target/training # Creates a folder wtih c2patool bin, samples and readme @@ -45,4 +51,4 @@ package: test: check-format clippy test-rust test-c test-cpp -all: test example \ No newline at end of file +all: test example