Skip to content

Commit

Permalink
CI enhancements: .app bundling, build .wasm (#486)
Browse files Browse the repository at this point in the history
Updates to enhance GitHub Actions continuous integration:

* ci: add macOS app bundle packaging using cargo-bundle, closes #352 
based on https://github.com/EndlessSkyCommunity/ESLauncher2/blob/master/Cargo.toml
* ci: add web target, building using wasm-pack (for #446) 
* ci: refactor and cleanup targets, split out instead of using matrix

* main: save config in consistent OS-specific dirs::config_dir()
Instead of storing and loading in the current working directory, change
to a consistent dedicated configuration directory. This is necessary for
.app launching since cwd is set to /. To preserve compatibility with
existing installations, if conf.cfg exists in cwd then it will be used instead,
but otherwise we will use the operating system specific config dirs:
// Lin: Some(/home/alice/.config)
// Win: Some(C:\Users\Alice\AppData\Roaming)
// Mac: Some(/Users/Alice/Library/Application Support)

* macos: add icons based on screenshotted logo
* macos: add Cmd-Q to quit
  • Loading branch information
iceiix authored Jan 19, 2021
1 parent 0b4c56b commit c7bdb60
Show file tree
Hide file tree
Showing 6 changed files with 220 additions and 29 deletions.
137 changes: 117 additions & 20 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,93 @@ on:
push:

jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os:
- windows-latest
- ubuntu-latest
- macos-latest
fail-fast: true
linux:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
# TODO: refactor toolchain version
toolchain: 1.49.0
components: clippy, rustfmt
default: true
- name: Install dependencies
if: matrix.os == 'ubuntu-latest'
run: |
sudo apt-get update
sudo apt-get install -y libxcb-composite0-dev
- name: Build binary
run: |
cargo build --verbose --release
- name: Run clippy
uses: actions-rs/[email protected]
with:
token: ${{ secrets.GITHUB_TOKEN }}
args: --all-targets -- -D warnings
- name: Check formatting
run: cargo fmt --all -- --check
- name: Upload binary
uses: actions/upload-artifact@v2
with:
name: stevenarella-linux
path: target/release/stevenarella
- name: Release binary
if: startsWith(github.ref, 'refs/tags/')
uses: softprops/action-gh-release@v1
with:
files: |
stevenarella*
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

windows:
runs-on: windows-latest
steps:
- uses: actions/checkout@v2
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: 1.49.0
components: clippy, rustfmt
default: true
- name: Build binary
run: |
cargo build --verbose --release
- name: Run clippy
uses: actions-rs/[email protected]
with:
token: ${{ secrets.GITHUB_TOKEN }}
args: --all-targets -- -D warnings
- name: Check formatting
run: cargo fmt --all -- --check
- name: Upload binary
uses: actions/upload-artifact@v2
with:
name: stevenarella.exe
path: target/release/stevenarella.exe
- name: Release binary
if: startsWith(github.ref, 'refs/tags/')
uses: softprops/action-gh-release@v1
with:
files: |
target/release/stevenarella.exe
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

macos:
runs-on: macos-latest
steps:
- uses: actions/checkout@v2
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: 1.49.0
components: clippy, rustfmt
default: true
- name: Build binary
run: |
cargo build --verbose --release
chmod a+x target/release/stevenarella
env:
MACOSX_DEPLOYMENT_TARGET: 10.14
- name: Run clippy
Expand All @@ -37,24 +99,59 @@ jobs:
args: --all-targets -- -D warnings
- name: Check formatting
run: cargo fmt --all -- --check
- name: Move binary
- name: Package binary
run: |
if [[ ${{ matrix.os }} == windows ]]; then
mv target/release/stevenarella.exe stevenarella-${{ matrix.os }}.exe
else
mv target/release/stevenarella stevenarella-${{ matrix.os }}
fi
shell: bash
cargo install cargo-bundle
cargo bundle --release
chmod a+x target/release/bundle/osx/Stevenarella.app/Contents/MacOS/stevenarella
cd target/release/bundle/osx
zip -r Stevenarella.app.zip Stevenarella.app
- name: Upload binary
uses: actions/upload-artifact@v2
with:
name: stevenarella-${{ matrix.os }}
path: stevenarella*
name: Stevenarella.app.zip
path: target/release/bundle/osx/Stevenarella.app.zip
- name: Release binary
if: startsWith(github.ref, 'refs/tags/')
uses: softprops/action-gh-release@v1
with:
files: |
stevenarella*
target/release/bundle/osx/Stevenarella.app.zip
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

web:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
# TODO: refactor toolchain version
toolchain: 1.49.0
components: clippy, rustfmt
default: true
- name: Install wasm-pack
uses: jetli/[email protected]
with:
version: 'latest'
- name: Build binary
run: |
rustup target add wasm32-unknown-unknown
cargo install wasm-bindgen-cli
wasm-pack build --dev
- name: Upload binary
uses: actions/upload-artifact@v2
with:
name: stevenarella.wasm
path: target/wasm32-unknown-unknown/debug/stevenarella.wasm
# TODO: npm bundle? or only the .wasm
- name: Release binary
if: startsWith(github.ref, 'refs/tags/')
uses: softprops/action-gh-release@v1
with:
files: |
target/wasm32-unknown-unknown/debug/stevenarella.wasm
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

73 changes: 73 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ description = "Multi-protocol multi-platform Minecraft-compatible client"
repository = "https://github.com/iceiix/stevenarella"
license = "MIT/Apache-2.0"

[package.metadata.bundle]
name = "Stevenarella"
identifier = "io.github.iceiix.stevenarella"
icon = ["resources/icon*.png"]
category = "Game"
osx_minimum_system_version = "10.14"

[lib]
crate-type = ["cdylib", "rlib"]
path = "src/main.rs"
Expand Down Expand Up @@ -40,6 +47,7 @@ rsa_public_encrypt_pkcs1 = "0.3.0"
structopt = "0.3.21"
clipboard = "0.5.0"
instant = "0.1.9"
dirs = "3.0.1"
# clippy = "*"

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
Expand Down
Binary file added resources/icon128x128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/icon32x32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 22 additions & 9 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,14 +209,7 @@ cfg_if! {
use glow::HasRenderLoop;
extern crate console_error_panic_hook;
pub use console_error_panic_hook::set_once as set_panic_hook;
} else {
#[inline]
pub fn set_panic_hook() {}
}
}

cfg_if! {
if #[cfg(target_arch = "wasm32")] {
use wasm_bindgen::prelude::*;

#[wasm_bindgen]
Expand All @@ -227,11 +220,26 @@ cfg_if! {
}
}

fn main2() {
let opt = Opt::from_args();
fn init_config_dir() {
if std::path::Path::new("conf.cfg").exists() {
return;
}

if let Some(mut path) = dirs::config_dir() {
path.push("Stevenarella");
if !path.exists() {
std::fs::create_dir_all(path.clone()).unwrap();
}
std::env::set_current_dir(path).unwrap();
}
}

fn main2() {
#[cfg(target_arch = "wasm32")]
set_panic_hook();

init_config_dir();
let opt = Opt::from_args();
let con = Arc::new(Mutex::new(console::Console::new()));
let proxy = console::ConsoleProxy::new(con.clone());

Expand Down Expand Up @@ -641,6 +649,11 @@ fn handle_window_event<T>(
if !game.focused && !game.is_ctrl_pressed && !game.is_logo_pressed {
ui_container.key_type(game, codepoint);
}

#[cfg(target_os = "macos")]
if game.is_logo_pressed && codepoint == 'q' {
game.should_close = true;
}
}

WindowEvent::MouseInput { state, button, .. } => match (state, button) {
Expand Down

0 comments on commit c7bdb60

Please sign in to comment.