Build #47
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} | |
- name: Setup cmake | |
uses: jwlawson/[email protected] | |
with: | |
cmake-version: '3.28.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 | |
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 | |
- 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 | |
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: "" | |
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 apt update | |
sudo apt install -y mold upx libasound2-dev | |
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 | |
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 | |
build-android: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
include: | |
- target: aarch64-linux-android | |
host_cc: "" | |
target_cc: "" | |
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 JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
- name: Setup Android SDK | |
uses: android-actions/setup-android@v3 | |
- name: Setup | |
run: | | |
sdkmanager "platform-tools" "platforms;android-30" | |
rustup toolchain install nightly | |
rustup component add rust-src --toolchain nightly | |
rustup default nightly | |
rustup target add ${{ matrix.target }} | |
cargo install cargo-apk | |
write_var(){ | |
echo "$1=$(eval echo \$$1)" >> $GITHUB_ENV | |
} | |
sudo apt update | |
sudo apt install -y mold upx libasound2-dev | |
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 | |
echo ${{ secrets.KEYSTORE_CONTENT }} | base64 --decode > "n_player/n_music.keystore" | |
echo "keystore_password = \"${{ secrets.KEYSTORE_PASSWORD }}\"" >> n_player/Cargo.toml | |
sudo ln -fs /usr/bin/mold /usr/bin/ld | |
- name: Build ${{ matrix.target }} | |
run: | | |
PKG_CONFIG_SYSROOT_DIR=/ ANDROID_NDK_ROOT=$ANDROID_NDK_LATEST_HOME cargo apk build --lib --target=${{ matrix.target }} --package n_player --release | |
- name: Upload n_music-${{ matrix.target }}.apk | |
uses: actions/upload-artifact@v3 | |
with: | |
name: ${{ env.CRATE_NAME }}-${{ matrix.target }}.apk | |
path: target/release/apk/N Music.apk | |
- name: Publish in release | |
uses: softprops/action-gh-release@v1 | |
if: github.ref_type == 'tag' | |
with: | |
files: | | |
target/release/apk/N Music.apk |