From 82bcd3d08640ef90e119ab0bb7ede285925602ce Mon Sep 17 00:00:00 2001 From: jb-alvarado Date: Fri, 26 Apr 2024 13:54:33 +0200 Subject: [PATCH] add macos cross build --- Cross.toml | 45 ++++++++++++++++++++++++++++++--------------- docs/developer.md | 35 ++++++++--------------------------- scripts/build.sh | 18 ------------------ 3 files changed, 38 insertions(+), 60 deletions(-) diff --git a/Cross.toml b/Cross.toml index f5325d03..1718f18b 100644 --- a/Cross.toml +++ b/Cross.toml @@ -1,26 +1,41 @@ [target.x86_64-unknown-linux-musl] pre-build = [ - """apt-get update && \ - apt-get --assume-yes install curl && \ - curl -fsSL https://deb.nodesource.com/setup_20.x | bash - && \ - apt-get --assume-yes install nodejs - """ + "apt-get update", + "apt-get --assume-yes install curl", + "curl -fsSL https://deb.nodesource.com/setup_20.x | bash -", + "apt-get --assume-yes install nodejs" ] [target.aarch64-unknown-linux-gnu] pre-build = [ - """apt-get update && \ - apt-get --assume-yes install curl && \ - curl -fsSL https://deb.nodesource.com/setup_20.x | bash - && \ - apt-get --assume-yes install nodejs - """ + "apt-get update", + "apt-get --assume-yes install curl", + "curl -fsSL https://deb.nodesource.com/setup_20.x | bash -", + "apt-get --assume-yes install nodejs" ] [target.x86_64-pc-windows-gnu] pre-build = [ - """apt-get update && \ - apt-get --assume-yes install curl && \ - curl -fsSL https://deb.nodesource.com/setup_20.x | bash - && \ - apt-get --assume-yes install nodejs - """ + "apt-get update", + "apt-get --assume-yes install curl", + "curl -fsSL https://deb.nodesource.com/setup_20.x | bash -", + "apt-get --assume-yes install nodejs" +] + +[target.x86_64-apple-darwin] +image = "ghcr.io/cross-rs/x86_64-apple-darwin-cross:local" +pre-build = [ + "apt-get update", + "apt-get --assume-yes install curl", + "curl -fsSL https://deb.nodesource.com/setup_20.x | bash -", + "apt-get --assume-yes install nodejs" +] + +[target.aarch64-apple-darwin] +image = "ghcr.io/cross-rs/aarch64-apple-darwin-cross:local" +pre-build = [ + "apt-get update", + "apt-get --assume-yes install curl", + "curl -fsSL https://deb.nodesource.com/setup_20.x | bash -", + "apt-get --assume-yes install nodejs" ] diff --git a/docs/developer.md b/docs/developer.md index f19e1673..ea62268c 100644 --- a/docs/developer.md +++ b/docs/developer.md @@ -31,40 +31,21 @@ Etc. ### Compile from Linux for macOS -Add toolchain: +Follow [cross-toolchains](https://github.com/cross-rs/cross-toolchains) instruction to add macOS support to cross. -```Bash -# for arm64 -rustup target add aarch64-apple-darwin +I created my image with: -# for x86_64 -rustup target add x86_64-apple-darwin +``` +cargo build-docker-image x86_64-apple-darwin-cross \ + --build-arg 'MACOS_SDK_URL=https://github.com/joseluisq/macosx-sdks/releases/download/12.3/MacOSX12.3.sdk.tar.xz' ``` -Add linker and ar settings to `~/.cargo/config`: +Build then with: -```Bash -[target.x86_64-apple-darwin] -linker = "x86_64-apple-darwin20.4-clang" -ar = "x86_64-apple-darwin20.4-ar" - -[target.aarch64-apple-darwin] -linker = "aarch64-apple-darwin20.4-clang" -ar = "aarch64-apple-darwin20.4-ar" +``` +cross build --release --target aarch64-apple-darwin ``` -Follow this guide: [rust-cross-compile-linux-to-macos](https://wapl.es/rust/2019/02/17/rust-cross-compile-linux-to-macos.html) - -Or setup [osxcross](https://github.com/tpoechtrager/osxcross) correctly. - -Add **osxcross/target/bin** to your **PATH** and run cargo with: - -```Bash -# for arm64 -CC="aarch64-apple-darwin20.4-clang -arch arm64e" cargo build --release --target=aarch64-apple-darwin - -# for x86_64 -CC="o64-clang" cargo build --release --target=x86_64-apple-darwin ``` ### Create debian DEB and RHEL RPM packages diff --git a/scripts/build.sh b/scripts/build.sh index b96b481d..e5a09ac7 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -38,24 +38,6 @@ for target in "${targets[@]}"; do cp ./target/${target}/release/ffplayout.exe . zip -r "ffplayout-v${version}_${target}.zip" assets docker docs LICENSE README.md CHANGELOG.md ffplayout.exe ffpapi.exe -x *.db -x *.db-shm -x *.db-wal -x '11-ffplayout' -x *.service rm -f ffplayout.exe ffpapi.exe - elif [[ $target == "x86_64-apple-darwin" ]] || [[ $target == "aarch64-apple-darwin" ]]; then - if [[ -f "ffplayout-v${version}_${target}.tar.gz" ]]; then - rm -f "ffplayout-v${version}_${target}.tar.gz" - fi - c_cc="x86_64-apple-darwin20.4-clang" - c_cxx="x86_64-apple-darwin20.4-clang++" - - if [[ $target == "aarch64-apple-darwin" ]]; then - c_cc="aarch64-apple-darwin20.4-clang" - c_cxx="aarch64-apple-darwin20.4-clang++" - fi - - CC="$c_cc" CXX="$c_cxx" cargo build --release --target=$target - - cp ./target/${target}/release/ffpapi . - cp ./target/${target}/release/ffplayout . - tar -czvf "ffplayout-v${version}_${target}.tar.gz" --exclude='*.db' --exclude='*.db-shm' --exclude='*.db-wal' --exclude='11-ffplayout' --exclude='*.service' assets docker docs LICENSE README.md CHANGELOG.md ffplayout ffpapi - rm -f ffplayout ffpapi else if [[ -f "ffplayout-v${version}_${target}.tar.gz" ]]; then rm -f "ffplayout-v${version}_${target}.tar.gz"