add macos cross build

This commit is contained in:
jb-alvarado 2024-04-26 13:54:33 +02:00
parent 35f527bf9b
commit 82bcd3d086
3 changed files with 38 additions and 60 deletions

View File

@ -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"
]

View File

@ -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

View File

@ -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"