Skip to content

Commit

Permalink
Revert to using clux/muslrust for linux build
Browse files Browse the repository at this point in the history
  • Loading branch information
Anton Hurlenko committed Jul 8, 2024
1 parent 77282a8 commit 5283d30
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 113 deletions.
16 changes: 15 additions & 1 deletion .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,18 @@
[target.x86_64-pc-windows-msvc]
rustflags = ["-C", "target-feature=+crt-static"]
[target.i686-pc-windows-msvc]
rustflags = ["-C", "target-feature=+crt-static"]
rustflags = ["-C", "target-feature=+crt-static"]


# Do the same for MUSL targets. At the time of writing (2023-10-23), this is
# the default. But the plan is for the default to change to dynamic linking.
# The whole point of MUSL with respect to orly is to create a fully
# statically linked executable.
#
# See: https://github.com/rust-lang/compiler-team/issues/422
# See: https://github.com/rust-lang/compiler-team/issues/422#issuecomment-812135847
[target.x86_64-unknown-linux-musl]
rustflags = [
"-C", "target-feature=+crt-static",
"-C", "link-self-contained=yes",
]
192 changes: 80 additions & 112 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ on:
permissions:
contents: write

env:
BINARY: "orly"
RUST_VERSION: "1.71.1"

jobs:
# The create-release job runs purely to initialize the GitHub release itself,
# and names the release after the `x.y.z` tag that was pushed. It's separate
Expand Down Expand Up @@ -55,74 +59,34 @@ jobs:
CROSS_VERSION: v0.2.5
# Emit backtraces on panics.
RUST_BACKTRACE: 1
BINARY: "orly"
PKG_CONFIG_ALL_STATIC: "true"
PKG_CONFIG_ALLOW_CROSS: "true"
PKG_CONFIG_PATH: "/musl/lib/pkgconfig"
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:
include:
# - build: linux-arm
# os: ubuntu-18.04
# rust: nightly
# target: arm-unknown-linux-gnueabihf
# - build: win32-msvc
# 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
# rust: stable
# target: x86_64-pc-windows-msvc
# - build: linux
# os: ubuntu-latest
# target: x86_64-unknown-linux-musl
# strip: x86_64-linux-musl-strip
- build: macos
os: macos-13 # macos-latest is arm-based
target: x86_64-apple-darwin
- build: win-msvc
os: windows-latest
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 @@ -156,7 +120,7 @@ jobs:
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
toolchain: ${{ matrix.rust }}
toolchain: ${{ env.RUST_VERSION }}
target: ${{ matrix.target }}

- name: Use Cross
Expand All @@ -171,7 +135,7 @@ jobs:
cd "$dir"
curl -LO "https://github.com/cross-rs/cross/releases/download/$CROSS_VERSION/cross-x86_64-unknown-linux-musl.tar.gz"
tar xf cross-x86_64-unknown-linux-musl.tar.gz
echo "CARGO=cargo" >> $GITHUB_ENV
echo "CARGO=cross" >> $GITHUB_ENV
- name: Set target variables
shell: bash
Expand Down Expand Up @@ -238,62 +202,66 @@ 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:
needs: ["create-release"]
runs-on: ubuntu-latest
container: clux/muslrust:1.71.0
env:
LIBXML_VER: "2.9.14"
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: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
toolchain: ${{ env.RUST_VERSION }}
target: x86_64-unknown-linux-musl

- 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

0 comments on commit 5283d30

Please sign in to comment.