Skip to content

Build

Build #10

Workflow file for this run

name: Build
on:
release:
types: [published]
workflow_dispatch:
jobs:
build-windows:
runs-on: windows-latest
strategy:
matrix:
include:
- target: x86_64-pc-windows-msvc
target_cc: x64
- target: aarch64-pc-windows-msvc
target_cc: amd64_arm64
env:
CRATE_NAME: "n_player"
steps:
- name: Check out repository code
uses: actions/checkout@v3
- name: Cache build
uses: Swatinem/rust-cache@v2
- name: Set up Visual Studio shell
uses: TheMrMilchmann/setup-msvc-dev@v3
with:
arch: ${{ matrix.target_cc }}
toolset: 17.8.5
- name: Setup cmake
uses: jwlawson/[email protected]
with:
cmake-version: '3.16.x'
- name: Setup
run: |
rustup toolchain install nightly
rustup component add rust-src --toolchain nightly
rustup default nightly
rustup target add ${{ matrix.target }}
- name: Build ${{ matrix.target }}
run: |
cargo build -Z build-std=std --target=${{ matrix.target }} --release --package n_player -vv
cd target\${{ matrix.target }}\release && tar -cavf "$env:CRATE_NAME-${{ matrix.target }}.zip" "$env:CRATE_NAME.exe" && cd ../../..
- name: Upload n_music-${{ matrix.target }}
uses: actions/upload-artifact@v3
with:
name: ${{ env.CRATE_NAME }}-${{ matrix.target }}.zip
path: target\${{ matrix.target }}\release\${{ env.CRATE_NAME }}-${{ matrix.target }}.zip
- name: Publish in release
uses: softprops/action-gh-release@v1
if: github.ref_type == 'tag'
with:
files: |
target/${{ matrix.target }}/release/${{ env.CRATE_NAME }}-${{ matrix.target }}.zip
token: ${{ secrets.GITHUB_TOKEN }}
build-macos:
runs-on: macos-latest
strategy:
matrix:
target: [x86_64-apple-darwin, aarch64-apple-darwin]
env:
CRATE_NAME: "n_player"
steps:
- name: Check out repository code
uses: actions/checkout@v3
- name: Cache build
uses: Swatinem/rust-cache@v2
- name: Setup
run: |
rustup toolchain install nightly
rustup component add rust-src --toolchain nightly
rustup default nightly
rustup target add ${{ matrix.target }}
brew install llvm upx
- name: Build ${{ matrix.target }}
env:
TARGET_LDFLAGS: "--target=${{ matrix.target }}"
TARGET_CFLAGS: "--target=${{ matrix.target }}"
run: |
cargo build -Z build-std=std --release --target=${{ matrix.target }} --package n_player -vv
upx --best --lzma "target/${{ matrix.target }}/release/$CRATE_NAME"
cd target/${{ matrix.target }}/release/ && tar -cvf "$CRATE_NAME-${{ matrix.target }}.tar.gz" "$CRATE_NAME" && cd ../../..
- name: Upload n_music-${{ matrix.target }}.tar.gz
uses: actions/upload-artifact@v3
with:
name: ${{ env.CRATE_NAME }}-${{ matrix.target }}.tar.gz
path: target/${{ matrix.target }}/release/${{ env.CRATE_NAME }}-${{ matrix.target }}.tar.gz
- name: Publish in release
uses: softprops/action-gh-release@v1
if: github.ref_type == 'tag'
with:
files: |
target/${{ matrix.target }}/release/${{ env.CRATE_NAME }}-${{ matrix.target }}.tar.gz
build-gnu-linux:
runs-on: ubuntu-latest
strategy:
matrix:
include:
- target: x86_64-unknown-linux-gnu
host_cc: ""
target_cc: ""
arch: amd64
- target: aarch64-unknown-linux-gnu
host_cc: ""
target_cc: aarch64-linux-gnu
arch: arm64
env:
CRATE_NAME: "n_player"
steps:
- name: Check out repository code
uses: actions/checkout@v3
- name: Cache build
uses: Swatinem/rust-cache@v2
- name: Setup
run: |
rustup toolchain install nightly
rustup component add rust-src --toolchain nightly
rustup default nightly
rustup target add ${{ matrix.target }}
write_var(){
echo "$1=$(eval echo \$$1)" >> $GITHUB_ENV
}
sudo deb http://bg.ports.ubuntu.com/ jammy main restricted
sudo dpkg --add-architecture ${{ matrix.arch }}
sudo apt update
sudo apt install -y mold upx libpulse-dev:${{ matrix.arch }}
if ! [[ -z "${{ matrix.host_cc }}" ]]; then
export HOST_CC="${{ matrix.host_cc }}-gcc"
write_var HOST_CC
sudo apt install -y -qq gcc-${{ matrix.host_cc }} pkg-config-${{ matrix.host_cc }}
fi
if ! [[ -z "${{ matrix.target_cc }}" ]]; then
export TARGET_CC="${{ matrix.target_cc }}-gcc"
write_var TARGET_CC
sudo apt install -y -qq gcc-${{ matrix.target_cc }} pkg-config-${{ matrix.host_cc }}
mkdir -p .cargo
echo '[target.${{ matrix.target }}]'>>.cargo/config
echo "linker = \"$TARGET_CC\"">>.cargo/config
fi
sudo ln -fs /usr/bin/mold /usr/bin/ld
- name: Build ${{ matrix.target }}
run: |
PKG_CONFIG_SYSROOT_DIR=/ cargo build -Z build-std=std --target=${{ matrix.target }} --package n_player --release -vv
upx --best --lzma "target/${{ matrix.target }}/release/$CRATE_NAME"
cd target/${{ matrix.target }}/release/ && tar -cvf "$CRATE_NAME-${{ matrix.target }}.tar.gz" "$CRATE_NAME" && cd ../../..
- name: Upload n_music-${{ matrix.target }}.tar.gz
uses: actions/upload-artifact@v3
with:
name: ${{ env.CRATE_NAME }}-${{ matrix.target }}.tar.gz
path: target/${{ matrix.target }}/release/*.tar.gz
- name: Publish in release
uses: softprops/action-gh-release@v1
if: github.ref_type == 'tag'
with:
files: |
target/${{ matrix.target }}/release/*.tar.gz