From b61d56131c3f218dbc8edce4c395fd7c1b7cce3b Mon Sep 17 00:00:00 2001 From: Niklas Eicker Date: Thu, 28 Dec 2023 01:27:34 +0100 Subject: [PATCH] Improve and document cargo profiles --- .github/workflows/release.yaml | 17 ++++++----------- Cargo.toml | 11 +++++++++-- README.md | 3 +-- mobile/build_rust_deps.sh | 2 +- 4 files changed, 17 insertions(+), 16 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 550e0a9..718281a 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -51,7 +51,7 @@ jobs: targets: aarch64-apple-darwin - name: Build release for Apple Silicon run: | - SDKROOT=$(xcrun -sdk macosx --show-sdk-path) cargo build --release --target=aarch64-apple-darwin + SDKROOT=$(xcrun -sdk macosx --show-sdk-path) cargo build --profile dist --target=aarch64-apple-darwin - name: Install rust toolchain for Apple x86 uses: dtolnay/rust-toolchain@master with: @@ -59,7 +59,7 @@ jobs: targets: x86_64-apple-darwin - name: Build release for x86 Apple run: | - SDKROOT=$(xcrun -sdk macosx --show-sdk-path) cargo build --release --target=x86_64-apple-darwin + SDKROOT=$(xcrun -sdk macosx --show-sdk-path) cargo build --profile dist --target=x86_64-apple-darwin - name: Create Universal Binary run: | lipo -create -output target/release/${{ env.GAME_EXECUTABLE_NAME }} target/aarch64-apple-darwin/release/${{ env.GAME_EXECUTABLE_NAME }} target/x86_64-apple-darwin/release/${{ env.GAME_EXECUTABLE_NAME }} @@ -69,7 +69,6 @@ jobs: cp -r assets/ build/macos/src/Game.app/Contents/MacOS/assets cp -r credits/ build/macos/src/Game.app/Contents/MacOS/credits cp target/release/${{ env.GAME_EXECUTABLE_NAME }} build/macos/src/Game.app/Contents/MacOS/ - strip build/macos/src/Game.app/Contents/MacOS/${{ env.GAME_EXECUTABLE_NAME }} mv build/macos/src/Game.app build/macos/src/${{ env.GAME_OSX_APP_NAME }}.app ln -s /Applications build/macos/src/ hdiutil create -fs HFS+ -volname "${{ env.GAME_OSX_APP_NAME }}" -srcfolder build/macos/src ${{ env.GAME_EXECUTABLE_NAME }}.dmg @@ -99,10 +98,9 @@ jobs: run: sudo apt-get update; sudo apt-get install pkg-config libx11-dev libasound2-dev libudev-dev - name: Build release run: | - cargo build --release + cargo build --profile dist - name: Prepare release run: | - strip target/release/${{ env.GAME_EXECUTABLE_NAME }} chmod +x target/release/${{ env.GAME_EXECUTABLE_NAME }} mv target/release/${{ env.GAME_EXECUTABLE_NAME }} . - name: Bundle release @@ -138,7 +136,7 @@ jobs: global-json-file: build/windows/installer/global.json - name: Build release run: | - cargo build --release + cargo build --profile dist - name: Prepare release run: | mkdir target/release/assets && cp -r assets target/release/assets @@ -263,10 +261,7 @@ jobs: - name: Install Cargo APK run: cargo install --force cargo-apk - name: Build app for Android - run: ANDROID_NDK_ROOT=$ANDROID_NDK_LATEST_HOME cargo apk build --package mobile - env: - # This will reduce the APK size from 1GB to ~200MB - CARGO_PROFILE_DEV_DEBUG: false + run: ANDROID_NDK_ROOT=$ANDROID_NDK_LATEST_HOME cargo apk build --profile dist --package mobile - name: Upload release uses: svenstaro/upload-release-action@v2 with: @@ -275,4 +270,4 @@ jobs: asset_name: ${{ env.GAME_EXECUTABLE_NAME }}_${{ env.VERSION }}_android.apk release_name: ${{ env.VERSION }} tag: ${{ env.VERSION }} - overwrite: true \ No newline at end of file + overwrite: true diff --git a/Cargo.toml b/Cargo.toml index d0bd045..2f80dac 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,14 +15,21 @@ opt-level = 3 [profile.dev] opt-level = 1 +# This is used by trunk as it doesn't support custom profiles: https://github.com/trunk-rs/trunk/issues/605 +# xbuild also uses this profile for building android AABs because I couldn't find a configuration for it [profile.release] +opt-level = "s" lto = true codegen-units = 1 +strip = true -# The profile that 'cargo dist' will build with +# Profile for distribution [profile.dist] inherits = "release" -lto = "thin" +opt-level = 3 +lto = true +codegen-units = 1 +strip = true [features] dev = [ diff --git a/README.md b/README.md index deb671b..1f26493 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,7 @@ You should keep the `credits` directory up to date. The release workflow automat 3. Replace `build/android/res/mipmap-mdpi/icon.png` with `macos/AppIcon.iconset/icon_256x256.png`, but rename it to `icon.png` ### Deploy web build to GitHub pages + 1. Trigger the `deploy-github-page` workflow 2. Activate [GitHub pages](https://pages.github.com/) for your repository 1. Source from the `gh-pages` branch (created by the just executed action) @@ -49,8 +50,6 @@ You should keep the `credits` directory up to date. The release workflow automat To deploy newer versions, just run the `deploy-github-page` workflow again. -Note that this does a `cargo build` and thus does not work with local dependencies. Consider pushing your "custom Bevy fork" to GitHub and using it as a git dependency. - # Deploy mobile platforms For general info on mobile support, you can take a look at [one of my blog posts about mobile development with Bevy][mobile_dev_with_bevy_2] which is relevant to the current setup. diff --git a/mobile/build_rust_deps.sh b/mobile/build_rust_deps.sh index 2914faa..3f112da 100644 --- a/mobile/build_rust_deps.sh +++ b/mobile/build_rust_deps.sh @@ -8,7 +8,7 @@ PATH=$PATH:$HOME/.cargo/bin RELFLAG= if [[ "$CONFIGURATION" != "Debug" ]]; then - RELFLAG=--release + RELFLAG=--profile dist fi set -euvx