Skip to content

Commit

Permalink
Build linux binary with cross
Browse files Browse the repository at this point in the history
  • Loading branch information
Anton Hurlenko committed Jul 4, 2024
1 parent 1cb460c commit ed9fff7
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 73 deletions.
176 changes: 105 additions & 71 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,11 @@ jobs:
RUST_BACKTRACE: 1
BINARY: "orly"
PKG_CONFIG_ALL_STATIC: "true"
PKG_CONFIG_ALLOW_CROSS: "true"
PKG_CONFIG_PATH: "/usr/local/opt/libxml2/lib/pkgconfig"
MACOSX_DEPLOYMENT_TARGET: "10.7"
LIBXML_VER: "2.9.14"
PREFIX: "/musl"
strategy:
fail-fast: false
matrix:
Expand All @@ -71,24 +74,55 @@ jobs:
# os: windows-latest
# rust: nightly
# target: i686-pc-windows-msvc
# - build: linux
# os: ubuntu-latest
# rust: stable
# target: x86_64-unknown-linux-musl
# strip: x86_64-linux-musl-strip
- build: macos
os: macos-13 # macos-latest is arm-based
rust: stable
target: x86_64-apple-darwin
- build: win-msvc
os: windows-latest
- build: linux
os: ubuntu-latest
rust: stable
target: x86_64-pc-windows-msvc
target: x86_64-unknown-linux-musl
strip: x86_64-linux-musl-strip
# - build: macos
# os: macos-13 # macos-latest is arm-based
# rust: stable
# target: x86_64-apple-darwin
# - build: win-msvc
# os: windows-latest
# rust: stable
# target: x86_64-pc-windows-msvc

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Install dependencies (linux)
if: matrix.os == 'ubuntu-latest'
run: |
echo "Install musl dependencies"
sudo apt-get install musl-dev musl-tools
echo "PKG_CONFIG_PATH=$PREFIX/lib/pkgconfig" >> $GITHUB_ENV
echo "LD_LIBRARY_PATH=$PREFIX" >> $GITHUB_ENV
export PKG_CONFIG_PATH=$PREFIX/lib/pkgconfig
export LD_LIBRARY_PATH=$PREFIX
echo "Set up a prefix for musl build libraries, make the linker's job of finding them easier"
sudo mkdir $PREFIX
sudo cat /etc/ld-musl-x86_64.path || true
echo "$PREFIX/lib" | sudo tee -a /etc/ld-musl-x86_64.path
sudo echo "After"
sudo cat /etc/ld-musl-x86_64.path
sudo cat /etc/ld-musl-x86_64.path || true
sudo ln -s /usr/include/x86_64-linux-gnu/asm /usr/include/x86_64-linux-musl/asm
sudo ln -s /usr/include/asm-generic /usr/include/x86_64-linux-musl/asm-generic
sudo ln -s /usr/include/linux /usr/include/x86_64-linux-musl/linux
echo "Compile libxml"
curl -sSL https://download.gnome.org/sources/libxml2/2.9/libxml2-$LIBXML_VER.tar.xz | tar xJ
cd libxml2-$LIBXML_VER
CC="musl-gcc -fPIC -pie" LDFLAGS="-L$PREFIX/lib" CFLAGS="-I$PREFIX/include" \
./configure --with-lzma=no --with-zlib=no --with-python=no --prefix=$PREFIX --host=x86_64-unknown-linux-musl
make -j$(nproc)
sudo make install
- name: Install dependencies (macOS)
if: matrix.os == 'macos-13'
run: |
Expand Down Expand Up @@ -204,62 +238,62 @@ jobs:
# (specifically with openssl). clux/muslrust has musl-compiled version of openssl
# which solves the issue

build-release-musl:
if: ${{ always() }}
needs: ["create-release"]
runs-on: ubuntu-latest
container: clux/muslrust:1.71.0
env:
LIBXML_VER: "2.9.14"
BINARY: "orly"
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Link to predefined musl toolchain
run: |
ln -s /root/.cargo $HOME/.cargo
ln -s /root/.rustup $HOME/.rustup
- name: Compile libxml2 against musl
run: |
curl -sSL https://download.gnome.org/sources/libxml2/2.9/libxml2-$LIBXML_VER.tar.xz | tar xJ
cd libxml2-$LIBXML_VER
PREFIX=/musl CC="musl-gcc -fPIC -pie" LDFLAGS="-L$PREFIX/lib" CFLAGS="-I$PREFIX/include" \
./configure --with-lzma=no --prefix=$PREFIX --host=x86_64-unknown-linux-musl
make -j$(nproc)
make install
- name: Build release binary
run: |
cargo build --release --locked
- name: Build archive
shell: bash
run: |
ARCHIVE="$BINARY-${{ needs.create-release.outputs.version }}-x86_64-unknown-linux-musl.tar.gz"
cp "target/x86_64-unknown-linux-musl/release/$BINARY" "$BINARY"
tar -czvf "$ARCHIVE" "$BINARY"
echo "ASSET=$ARCHIVE" >> $GITHUB_ENV
- name: Upload release archive
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Install gh cli
curl -sSL https://github.com/cli/cli/releases/download/v2.32.0/gh_2.32.0_linux_amd64.tar.gz | tar xz
mv gh*/bin/gh /usr/local/bin
# Upload asset to release
git config --global --add safe.directory '*'
gh release upload ${{ needs.create-release.outputs.version }} ${{ env.ASSET }}
publish-crate:
name: publish-crate
runs-on: ubuntu-latest
needs: ["build-release", "build-release-musl"]
steps:
- uses: actions/checkout@v4
- run: cargo login ${CRATES_IO_TOKEN}
env:
CRATES_IO_TOKEN: ${{ secrets.CRATES_IO_TOKEN }}
- run: cargo publish
# build-release-musl:
# if: ${{ always() }}
# needs: ["create-release"]
# runs-on: ubuntu-latest
# container: clux/muslrust:1.71.0
# env:
# LIBXML_VER: "2.9.14"
# BINARY: "orly"
# steps:
# - name: Checkout repository
# uses: actions/checkout@v4
#
# - name: Link to predefined musl toolchain
# run: |
# ln -s /root/.cargo $HOME/.cargo
# ln -s /root/.rustup $HOME/.rustup
#
# - name: Compile libxml2 against musl
# run: |
# curl -sSL https://download.gnome.org/sources/libxml2/2.9/libxml2-$LIBXML_VER.tar.xz | tar xJ
# cd libxml2-$LIBXML_VER
# PREFIX=/musl CC="musl-gcc -fPIC -pie" LDFLAGS="-L$PREFIX/lib" CFLAGS="-I$PREFIX/include" \
# ./configure --with-lzma=no --prefix=$PREFIX --host=x86_64-unknown-linux-musl
# make -j$(nproc)
# make install
#
# - name: Build release binary
# run: |
# cargo build --release --locked
#
# - name: Build archive
# shell: bash
# run: |
# ARCHIVE="$BINARY-${{ needs.create-release.outputs.version }}-x86_64-unknown-linux-musl.tar.gz"
# cp "target/x86_64-unknown-linux-musl/release/$BINARY" "$BINARY"
# tar -czvf "$ARCHIVE" "$BINARY"
# echo "ASSET=$ARCHIVE" >> $GITHUB_ENV
#
# - name: Upload release archive
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# run: |
# # Install gh cli
# curl -sSL https://github.com/cli/cli/releases/download/v2.32.0/gh_2.32.0_linux_amd64.tar.gz | tar xz
# mv gh*/bin/gh /usr/local/bin
# # Upload asset to release
# git config --global --add safe.directory '*'
# gh release upload ${{ needs.create-release.outputs.version }} ${{ env.ASSET }}
#
# publish-crate:
# name: publish-crate
# runs-on: ubuntu-latest
# needs: ["build-release", "build-release-musl"]
# steps:
# - uses: actions/checkout@v4
# - run: cargo login ${CRATES_IO_TOKEN}
# env:
# CRATES_IO_TOKEN: ${{ secrets.CRATES_IO_TOKEN }}
# - run: cargo publish
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "orly"
version = "0.1.7"
version = "0.1.8"
edition = "2021"
authors = ["hurlenko"]
description = "Download O'Reilly books as EPUB"
Expand Down

0 comments on commit ed9fff7

Please sign in to comment.