Skip to content

Commit

Permalink
ci: bundle Windows package with cargo-packager (#89)
Browse files Browse the repository at this point in the history
* build: bundle dmg with cargo-packager

Co-authored-by: Naman Garg <[email protected]>

* build(packager): support bundle with Windows NSIS

* ci: test packager bundle

* ci: revert schedule nightly release

* refactor: move resources_dir_path() to main.rs

---------

Co-authored-by: Naman Garg <[email protected]>
  • Loading branch information
pewsheen and naman-crabnebula authored Jul 26, 2024
1 parent c49b0eb commit e561e3f
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 15 deletions.
41 changes: 28 additions & 13 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ jobs:
- name: Install Rust
uses: dsherret/rust-toolchain-file@v1

- name: Install Rust toolchain for packager
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: stable

- name: Install scroop
uses: MinoruSekine/setup-scoop@v3

Expand All @@ -133,6 +138,9 @@ jobs:
- name: Run sccache-cache
uses: Mozilla-Actions/[email protected]

- name: Install Cargo Packager
run: cargo +stable install cargo-packager

- name: Build
run: |
cargo build --release
Expand All @@ -141,16 +149,22 @@ jobs:
# run: |
# cargo test --release

- name: Tar Binary
- name: Bundle
if: ${{ github.event_name == 'schedule' }}
run: tar -czvf verso-x86_64-pc-windows-msvc.tar.gz -C ./target/release/ verso.exe
run: |
cargo packager --release
- name: Fetch Verso version
if: ${{ github.event_name == 'schedule' }}
run: |
echo "VERSO_VERSION=$(cargo metadata --format-version=1 --no-deps | jq -r '.packages[] | select(.name == "verso") | .version')" >> $Env:GITHUB_ENV
- name: Upload artifact
if: ${{ github.event_name == 'schedule' }}
uses: actions/upload-artifact@v4
with:
name: verso-x86_64-pc-windows-msvc
path: verso-x86_64-pc-windows-msvc.tar.gz
name: verso_${{ env.VERSO_VERSION }}_x64-setup
path: target\release\verso_${{ env.VERSO_VERSION }}_x64-setup.exe

build-macos:
if: ${{ github.event_name != 'pull_request' }}
Expand All @@ -159,8 +173,8 @@ jobs:
fail-fast: false
matrix:
platform:
- { target: aarch64-apple-darwin, os: macos-latest }
- { target: x86_64-apple-darwin, os: macos-13 }
- { target: aarch64-apple-darwin, os: macos-latest, arch: aarch64 }
- { target: x86_64-apple-darwin, os: macos-13, arch: x64 }
runs-on: ${{ matrix.platform.os }}
env:
RUSTC_WRAPPER: sccache
Expand Down Expand Up @@ -221,41 +235,42 @@ jobs:

- name: Fetch Verso version
run: |
echo "VERSO_VERSION=$(cargo metadata --format-version=1 --no-deps | jq -r '.packages[] | select(.name == "verso") | .version')-$(date '+%Y%m%d')-nightly" >> $GITHUB_ENV
echo "VERSO_VERSION=$(cargo metadata --format-version=1 --no-deps | jq -r '.packages[] | select(.name == "verso") | .version')" >> $GITHUB_ENV
echo "VERSO_RELEASE_NAME=$(cargo metadata --format-version=1 --no-deps | jq -r '.packages[] | select(.name == "verso") | .version')-$(date '+%Y%m%d')-nightly" >> $GITHUB_ENV
- name: Draft release
uses: crabnebula-dev/[email protected]
id: draft
with:
command: release draft ${{ env.CN_APP_SLUG }} $VERSO_VERSION
command: release draft ${{ env.CN_APP_SLUG }} $VERSO_RELEASE_NAME
api-key: ${{ secrets.CN_API_KEY }}

- name: Upload macOS binary (ARM)
uses: crabnebula-dev/[email protected]
with:
command: release upload --file "verso-aarch64-apple-darwin/verso-aarch64-apple-darwin.tar.gz" ${{ env.CN_APP_SLUG }} $VERSO_VERSION
command: release upload --file "verso-aarch64-apple-darwin/verso-aarch64-apple-darwin.tar.gz" ${{ env.CN_APP_SLUG }} $VERSO_RELEASE_NAME
api-key: ${{ secrets.CN_API_KEY }}

- name: Upload macOS binary (Intel)
uses: crabnebula-dev/[email protected]
with:
command: release upload --file "verso-x86_64-apple-darwin/verso-x86_64-apple-darwin.tar.gz" ${{ env.CN_APP_SLUG }} $VERSO_VERSION
command: release upload --file "verso-x86_64-apple-darwin/verso-x86_64-apple-darwin.tar.gz" ${{ env.CN_APP_SLUG }} $VERSO_RELEASE_NAME
api-key: ${{ secrets.CN_API_KEY }}

- name: Upload Windows binary
uses: crabnebula-dev/[email protected]
with:
command: release upload --file "verso-x86_64-pc-windows-msvc/verso-x86_64-pc-windows-msvc.tar.gz" ${{ env.CN_APP_SLUG }} $VERSO_VERSION
command: release upload --file "verso_${{ env.VERSO_VERSION }}_x64-setup/verso_${{ env.VERSO_VERSION }}_x64-setup.exe" ${{ env.CN_APP_SLUG }} $VERSO_RELEASE_NAME
api-key: ${{ secrets.CN_API_KEY }}

- name: Upload Linux binary
uses: crabnebula-dev/[email protected]
with:
command: release upload --file "verso-x86_64-unknown-linux-gnu/verso-x86_64-unknown-linux-gnu.tar.gz" ${{ env.CN_APP_SLUG }} $VERSO_VERSION
command: release upload --file "verso-x86_64-unknown-linux-gnu/verso-x86_64-unknown-linux-gnu.tar.gz" ${{ env.CN_APP_SLUG }} $VERSO_RELEASE_NAME
api-key: ${{ secrets.CN_API_KEY }}

- name: Publish release
uses: crabnebula-dev/[email protected]
with:
command: release publish ${{ env.CN_APP_SLUG }} $VERSO_VERSION
command: release publish ${{ env.CN_APP_SLUG }} $VERSO_RELEASE_NAME
api-key: ${{ secrets.CN_API_KEY }}
38 changes: 38 additions & 0 deletions Cargo.lock

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

21 changes: 21 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,23 @@ repository = "https://github.com/versotile-org/verso"
documentation = "https://docs.versotile.org/verso"
categories = ["web-programming"]

[package.metadata.packager]
name = "verso"
product-name = "verso"
identifier = "org.versotile.verso"
version = "0.0.1"
before-each-package-command = "cargo build --release --features packager"
resources = [
"resources",
"icons",
"target/release/build/**/libEGL.dll",
"target/release/build/**/libGLESv2.dll",
]
icons = ["icons/icon256x256.png", "icons/icon.ico"]

[package.metadata.packager.nsis]
appdata-paths = ["$LOCALAPPDATA/$IDENTIFIER"]

[package.metadata.docs.rs]
targets = [
"x86_64-unknown-linux-gnu",
Expand All @@ -22,6 +39,7 @@ targets = [

[features]
default = []
packager = ["dep:cargo-packager-resource-resolver"]

[build-dependencies]
cfg_aliases = "0.2"
Expand All @@ -46,6 +64,9 @@ crossbeam-channel = "0.5"
getopts = "0.2.17"
surfman = { version = "0.9", features = ["chains", "sm-raw-window-handle"] }
winit = { version = "0.29", features = ["rwh_05"] }
cargo-packager-resource-resolver = { version = "0.1.1", features = [
"auto-detect-format",
], optional = true }

[target.'cfg(target_os = "windows")'.dependencies]
libservo = { git = "https://github.com/servo/servo.git", rev = "2a31e62", features = [
Expand Down
Binary file added icons/icon.ico
Binary file not shown.
Binary file added icons/icon256x256.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,21 @@ impl Config {
}
}

impl Config {
/// Returns the path to the resources directory.
pub fn resources_dir_path() -> Option<std::path::PathBuf> {
#[cfg(feature = "packager")]
let root_dir = {
use cargo_packager_resource_resolver::{current_format, resources_dir};
current_format().and_then(|format| resources_dir(format))
};
#[cfg(not(feature = "packager"))]
let root_dir = std::env::current_dir();

root_dir.ok().map(|dir| dir.join("resources"))
}
}

struct ResourceReader(PathBuf);

impl ResourceReaderMethods for ResourceReader {
Expand Down
17 changes: 15 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::env::current_dir;
// Prevent console window from appearing on Windows
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]

use verso::config::Config;
use verso::{Result, Verso};
Expand Down Expand Up @@ -30,7 +31,7 @@ fn main() -> Result<()> {
}
}

let config = Config::new(current_dir().unwrap().join("resources"));
let config = Config::new(resources_dir_path().unwrap());
let mut verso = Verso::new(window, event_loop.create_proxy(), config);
event_loop.run(move |event, evl| {
verso.run(event);
Expand Down Expand Up @@ -59,3 +60,15 @@ pub unsafe fn decorate_window(window: *mut Object, _position: LogicalPosition<f6
| NSWindowStyleMask::NSMiniaturizableWindowMask,
);
}

fn resources_dir_path() -> Option<std::path::PathBuf> {
#[cfg(feature = "packager")]
let root_dir = {
use cargo_packager_resource_resolver::{current_format, resources_dir};
current_format().and_then(|format| resources_dir(format))
};
#[cfg(not(feature = "packager"))]
let root_dir = std::env::current_dir();

root_dir.ok().map(|dir| dir.join("resources"))
}

0 comments on commit e561e3f

Please sign in to comment.