From 5f323016adbfa67cb1d7054d9f86e946c805b298 Mon Sep 17 00:00:00 2001 From: Anton Hurlenko Date: Wed, 3 Jul 2024 23:54:17 +0300 Subject: [PATCH] Build linux binary with cross --- .github/workflows/release.yml | 166 +++++++++++++++++++--------------- Cargo.lock | 2 +- Cargo.toml | 2 +- 3 files changed, 97 insertions(+), 73 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 8fa85f8..c49d2cf 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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: @@ -71,24 +74,45 @@ 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: | + sudo apt-get install musl-dev musl-tools + + export PKG_CONFIG_PATH=$PREFIX/lib/pkgconfig + export LD_LIBRARY_PATH=$PREFIX + + sudo mkdir $PREFIX + echo "$PREFIX/lib" >> /etc/ld-musl-x86_64.path + 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 + + 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: | @@ -204,62 +228,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 diff --git a/Cargo.lock b/Cargo.lock index 6989798..6c43167 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1344,7 +1344,7 @@ checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" [[package]] name = "orly" -version = "0.1.7" +version = "0.1.8" dependencies = [ "anyhow", "askama", diff --git a/Cargo.toml b/Cargo.toml index 97c3a27..56bfc1d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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"