Skip to content

Commit

Permalink
Improve and document cargo profiles
Browse files Browse the repository at this point in the history
  • Loading branch information
NiklasEi committed Dec 28, 2023
1 parent 6b1517f commit b61d561
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 16 deletions.
17 changes: 6 additions & 11 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ 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:
toolchain: stable
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 }}
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -275,4 +270,4 @@ jobs:
asset_name: ${{ env.GAME_EXECUTABLE_NAME }}_${{ env.VERSION }}_android.apk
release_name: ${{ env.VERSION }}
tag: ${{ env.VERSION }}
overwrite: true
overwrite: true
11 changes: 9 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,14 @@ 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)
3. After a few minutes your game is live at `http://username.github.io/repository`

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.
Expand Down
2 changes: 1 addition & 1 deletion mobile/build_rust_deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ PATH=$PATH:$HOME/.cargo/bin

RELFLAG=
if [[ "$CONFIGURATION" != "Debug" ]]; then
RELFLAG=--release
RELFLAG=--profile dist
fi

set -euvx
Expand Down

0 comments on commit b61d561

Please sign in to comment.