Skip to content

Commit

Permalink
Build macOS natively, cross-compile other targets.
Browse files Browse the repository at this point in the history
  • Loading branch information
rdmitr committed May 27, 2024
1 parent 0ed11a1 commit db45396
Showing 1 changed file with 84 additions and 22 deletions.
106 changes: 84 additions & 22 deletions .github/workflows/cross-compile-all-targets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,103 @@ on:
push: # TODO: remove after testing, don't run on any push
workflow_dispatch:

env:
RUST_VERSION: 1.78

jobs:
cross-compile:
runs-on: macos-12
uniffi-bindings:
runs-on: ubuntu-20.04
steps:
- name: Set up Rust
run: |
rustup toolchain install 1.78
rustup default 1.78
rustup target add aarch64-apple-darwin
rustup target add x86_64-apple-darwin
rustup toolchain install ${{ env.RUST_VERSION }}
rustup default ${{ env.RUST_VERSION }}
- name: Checkout
uses: actions/checkout@v4

- name: Install uniffi-bindgen-go
run: cargo install uniffi-bindgen-go --git https://github.com/NordSecurity/uniffi-bindgen-go --tag v0.2.1+v0.25.0

- name: Generate bindings
run: uniffi-bindgen-go bindings/ldk_node.udl -o ffi/golang -c ./uniffi.toml

- name: Archive bindings
uses: actions/upload-artifact@v4
with:
name: ldk-node-bindings
path: |
ffi/golang/ldk_node/ldk_node.go
ffi/golang/ldk_node/ldk_node.h
ffi/golang/ldk_node/ldk_node.c
- name: Launch colima
run: colima start
build-linux-windows:
runs-on: ubuntu-20.04
steps:
- name: Set up Rust
run: |
rustup toolchain install ${{ env.RUST_VERSION }}
rustup default ${{ env.RUST_VERSION }}
- name: Install cross
run: cargo install cross --git https://github.com/cross-rs/cross --rev c87a52a

- name: Install uniffi-bindgen-go
run: cargo install uniffi-bindgen-go --git https://github.com/NordSecurity/uniffi-bindgen-go --tag v0.2.1+v0.25.0
- name: Checkout
uses: actions/checkout@v4

- name: Build Linux x86_64
run: cross build --release --target x86_64-unknown-linux-gnu --features uniffi

- name: Build Linux ARM
run: cross build --release --target arm-unknown-linux-gnueabihf --features uniffi

- name: Build Windows x64_64
run: cross build --release --target x86_64-pc-windows-gnu --features uniffi

- name: Archive Linux x86_64
uses: actions/upload-artifact@v4
with:
name: ldk-node-x86_64-unknown-linux-gnu
path: ffi/golang/ldk_node/x86_64-unknown-linux-gnu/libldk_node.so

- name: Archive Linux ARM
uses: actions/upload-artifact@v4
with:
name: ldk-node-arm-unknown-linux-gnueabihf
path: ffi/golang/ldk_node/arm-unknown-linux-gnueabihf/libldk_node.so

- name: Archive Windows x86_64
uses: actions/upload-artifact@v4
with:
name: ldk-node-x86_64-pc-windows-gnu
path: ffi/golang/ldk_node/x86_64-pc-windows-gnu/libldk_node.dll

build-macos:
runs-on: macos-12
steps:
- name: Set up Rust
run: |
rustup toolchain install ${{ env.RUST_VERSION }}
rustup default ${{ env.RUST_VERSION }}
rustup target add aarch64-apple-darwin
rustup target add x86_64-apple-darwin
- name: Checkout
uses: actions/checkout@v4

- name: Cross compile
run: ./scripts/uniffi_bindgen_generate_go.sh
- name: Build macOS x86_64
run: cargo build --release --target x86_64-apple-darwin --features uniffi

- name: Build macOS ARM64
run: cargo build --release --target aarch64-apple-darwin --features uniffi

- name: Archive the artifacts
- name: Make universal macOS library
run: |
mkdir -p target/universal-macos/release
lipo -create -output "target/universal-macos/release/libldk_node.dylib" "target/aarch64-apple-darwin/release/libldk_node.dylib" "target/x86_64-apple-darwin/release/libldk_node.dylib"
- name: Archive macOS
uses: actions/upload-artifact@v4
with:
name: ldk-go
path: |
ffi/golang/ldk_node/ldk_node.c
ffi/golang/ldk_node/ldk_node.h
ffi/golang/ldk_node/ldk_node.go
ffi/golang/ldk_node/universal-macos/libldk_node.dylib
ffi/golang/ldk_node/x86_64-unknown-linux-gnu/libldk_node.so
ffi/golang/ldk_node/x86_64-pc-windows-gnu/ldk_node.dll
ffi/golang/ldk_node/arm-unknown-linux-gnueabihf/libldk_node.so
name: ldk-node-universal-macos
path: target/universal-macos/release/libldk_node.dylib

0 comments on commit db45396

Please sign in to comment.