CI enhancements: .app bundling, build .wasm (#486)

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
This commit is contained in:
iceiix 2021-01-18 19:05:29 -08:00 committed by GitHub
parent 0b4c56b803
commit c7bdb60d85
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 224 additions and 33 deletions

View File

@ -3,15 +3,47 @@ on:
push: push:
jobs: jobs:
build: linux:
runs-on: ${{ matrix.os }} runs-on: ubuntu-latest
strategy: steps:
matrix: - uses: actions/checkout@v2
os: - name: Install Rust
- windows-latest uses: actions-rs/toolchain@v1
- ubuntu-latest with:
- macos-latest # TODO: refactor toolchain version
fail-fast: true toolchain: 1.49.0
components: clippy, rustfmt
default: true
- name: Install dependencies
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/clippy-check@v1.0.7
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: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- name: Install Rust - name: Install Rust
@ -20,14 +52,44 @@ jobs:
toolchain: 1.49.0 toolchain: 1.49.0
components: clippy, rustfmt components: clippy, rustfmt
default: true 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 - name: Build binary
run: | run: |
cargo build --verbose --release cargo build --verbose --release
- name: Run clippy
uses: actions-rs/clippy-check@v1.0.7
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: env:
MACOSX_DEPLOYMENT_TARGET: 10.14 MACOSX_DEPLOYMENT_TARGET: 10.14
- name: Run clippy - name: Run clippy
@ -37,24 +99,59 @@ jobs:
args: --all-targets -- -D warnings args: --all-targets -- -D warnings
- name: Check formatting - name: Check formatting
run: cargo fmt --all -- --check run: cargo fmt --all -- --check
- name: Move binary - name: Package binary
run: | run: |
if [[ ${{ matrix.os }} == windows ]]; then cargo install cargo-bundle
mv target/release/stevenarella.exe stevenarella-${{ matrix.os }}.exe cargo bundle --release
else chmod a+x target/release/bundle/osx/Stevenarella.app/Contents/MacOS/stevenarella
mv target/release/stevenarella stevenarella-${{ matrix.os }} cd target/release/bundle/osx
fi zip -r Stevenarella.app.zip Stevenarella.app
shell: bash
- name: Upload binary - name: Upload binary
uses: actions/upload-artifact@v2 uses: actions/upload-artifact@v2
with: with:
name: stevenarella-${{ matrix.os }} name: Stevenarella.app.zip
path: stevenarella* path: target/release/bundle/osx/Stevenarella.app.zip
- name: Release binary - name: Release binary
if: startsWith(github.ref, 'refs/tags/') if: startsWith(github.ref, 'refs/tags/')
uses: softprops/action-gh-release@v1 uses: softprops/action-gh-release@v1
with: with:
files: | files: |
stevenarella* target/release/bundle/osx/Stevenarella.app.zip
env: env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 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/wasm-pack-action@v0.3.0
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
Cargo.lock generated
View File

@ -87,6 +87,18 @@ dependencies = [
"num-traits", "num-traits",
] ]
[[package]]
name = "arrayref"
version = "0.3.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a4c527152e37cf757a3f78aae5a06fbeefdb07ccc535c980a3208ee3060dd544"
[[package]]
name = "arrayvec"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b"
[[package]] [[package]]
name = "atty" name = "atty"
version = "0.2.14" version = "0.2.14"
@ -137,6 +149,17 @@ version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
[[package]]
name = "blake2b_simd"
version = "0.5.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "afa748e348ad3be8263be728124b24a24f268266f6f5d58af9d75f6a40b5c587"
dependencies = [
"arrayref",
"arrayvec",
"constant_time_eq",
]
[[package]] [[package]]
name = "block" name = "block"
version = "0.1.6" version = "0.1.6"
@ -389,6 +412,12 @@ version = "0.4.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cd51eab21ab4fd6a3bf889e2d0958c0a6e3a61ad04260325e919e652a2a62826" checksum = "cd51eab21ab4fd6a3bf889e2d0958c0a6e3a61ad04260325e919e652a2a62826"
[[package]]
name = "constant_time_eq"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc"
[[package]] [[package]]
name = "core-foundation" name = "core-foundation"
version = "0.7.0" version = "0.7.0"
@ -597,6 +626,26 @@ dependencies = [
"generic-array", "generic-array",
] ]
[[package]]
name = "dirs"
version = "3.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "142995ed02755914747cc6ca76fc7e4583cd18578746716d0508ea6ed558b9ff"
dependencies = [
"dirs-sys",
]
[[package]]
name = "dirs-sys"
version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e93d7f5705de3e49895a2b5e0b8855a1c27f080192ae9c32a6432d50741a57a"
dependencies = [
"libc",
"redox_users",
"winapi 0.3.9",
]
[[package]] [[package]]
name = "dispatch" name = "dispatch"
version = "0.2.0" version = "0.2.0"
@ -2080,6 +2129,17 @@ version = "0.1.57"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce" checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce"
[[package]]
name = "redox_users"
version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "de0737333e7a9502c789a36d7c7fa6092a49895d4faa31ca5df163857ded2e9d"
dependencies = [
"getrandom 0.1.15",
"redox_syscall",
"rust-argon2",
]
[[package]] [[package]]
name = "remove_dir_all" name = "remove_dir_all"
version = "0.5.3" version = "0.5.3"
@ -2134,6 +2194,18 @@ dependencies = [
"simple_asn1", "simple_asn1",
] ]
[[package]]
name = "rust-argon2"
version = "0.8.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4b18820d944b33caa75a71378964ac46f58517c92b6ae5f762636247c09e78fb"
dependencies = [
"base64",
"blake2b_simd",
"constant_time_eq",
"crossbeam-utils",
]
[[package]] [[package]]
name = "rusttype" name = "rusttype"
version = "0.9.2" version = "0.9.2"
@ -2401,6 +2473,7 @@ dependencies = [
"clipboard", "clipboard",
"collision", "collision",
"console_error_panic_hook", "console_error_panic_hook",
"dirs",
"flate2", "flate2",
"getrandom 0.2.1", "getrandom 0.2.1",
"glow", "glow",

View File

@ -7,6 +7,13 @@ description = "Multi-protocol multi-platform Minecraft-compatible client"
repository = "https://github.com/iceiix/stevenarella" repository = "https://github.com/iceiix/stevenarella"
license = "MIT/Apache-2.0" 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] [lib]
crate-type = ["cdylib", "rlib"] crate-type = ["cdylib", "rlib"]
path = "src/main.rs" path = "src/main.rs"
@ -40,6 +47,7 @@ rsa_public_encrypt_pkcs1 = "0.3.0"
structopt = "0.3.21" structopt = "0.3.21"
clipboard = "0.5.0" clipboard = "0.5.0"
instant = "0.1.9" instant = "0.1.9"
dirs = "3.0.1"
# clippy = "*" # clippy = "*"
[target.'cfg(not(target_arch = "wasm32"))'.dependencies] [target.'cfg(not(target_arch = "wasm32"))'.dependencies]

BIN
resources/icon128x128.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

BIN
resources/icon32x32.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

View File

@ -209,14 +209,7 @@ cfg_if! {
use glow::HasRenderLoop; use glow::HasRenderLoop;
extern crate console_error_panic_hook; extern crate console_error_panic_hook;
pub use console_error_panic_hook::set_once as set_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::*; use wasm_bindgen::prelude::*;
#[wasm_bindgen] #[wasm_bindgen]
@ -227,11 +220,26 @@ cfg_if! {
} }
} }
fn main2() { fn init_config_dir() {
let opt = Opt::from_args(); 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(); set_panic_hook();
init_config_dir();
let opt = Opt::from_args();
let con = Arc::new(Mutex::new(console::Console::new())); let con = Arc::new(Mutex::new(console::Console::new()));
let proxy = console::ConsoleProxy::new(con.clone()); let proxy = console::ConsoleProxy::new(con.clone());
@ -641,6 +649,11 @@ fn handle_window_event<T>(
if !game.focused && !game.is_ctrl_pressed && !game.is_logo_pressed { if !game.focused && !game.is_ctrl_pressed && !game.is_logo_pressed {
ui_container.key_type(game, codepoint); 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) { WindowEvent::MouseInput { state, button, .. } => match (state, button) {