diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6342b3b1..e3ae0de9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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 @@ -133,6 +138,9 @@ jobs: - name: Run sccache-cache uses: Mozilla-Actions/sccache-action@v0.0.4 + - name: Install Cargo Packager + run: cargo +stable install cargo-packager + - name: Build run: | cargo build --release @@ -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' }} @@ -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 @@ -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/cloud-release@v0.1.0 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/cloud-release@v0.1.0 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/cloud-release@v0.1.0 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/cloud-release@v0.1.0 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/cloud-release@v0.1.0 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/cloud-release@v0.1.0 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 }} diff --git a/Cargo.lock b/Cargo.lock index 7057afbe..570d3ec8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -637,6 +637,27 @@ dependencies = [ "webxr-api", ] +[[package]] +name = "cargo-packager-resource-resolver" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b5ef5863f81afa1b45d1b7e01b319d9e940c9be5615bc0a988421987d35c9f8" +dependencies = [ + "cargo-packager-utils", + "heck", + "log", + "thiserror", +] + +[[package]] +name = "cargo-packager-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d435b1a5799cfee502f151f857a0b415a04d3834562d83fea2bb8c6e33bfc167" +dependencies = [ + "ctor", +] + [[package]] name = "cc" version = "1.1.6" @@ -1115,6 +1136,16 @@ dependencies = [ "quote", ] +[[package]] +name = "ctor" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "edb49164822f3ee45b17acd4a208cfc1251410cf0cad9a833234c9890774dd9f" +dependencies = [ + "quote", + "syn 2.0.72", +] + [[package]] name = "cursor-icon" version = "1.1.0" @@ -2119,6 +2150,12 @@ dependencies = [ "http", ] +[[package]] +name = "heck" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" + [[package]] name = "hermit-abi" version = "0.3.9" @@ -5776,6 +5813,7 @@ version = "0.0.1" dependencies = [ "arboard", "block", + "cargo-packager-resource-resolver", "cfg_aliases 0.2.1", "cocoa 0.25.0", "compositing_traits", diff --git a/Cargo.toml b/Cargo.toml index 0a2865b2..2fe03adb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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", @@ -22,6 +39,7 @@ targets = [ [features] default = [] +packager = ["dep:cargo-packager-resource-resolver"] [build-dependencies] cfg_aliases = "0.2" @@ -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 = [ diff --git a/icons/icon.ico b/icons/icon.ico new file mode 100644 index 00000000..c340dfb6 Binary files /dev/null and b/icons/icon.ico differ diff --git a/icons/icon256x256.png b/icons/icon256x256.png new file mode 100644 index 00000000..d1df8c6e Binary files /dev/null and b/icons/icon256x256.png differ diff --git a/src/config.rs b/src/config.rs index 9e9ab4ca..51d52c33 100644 --- a/src/config.rs +++ b/src/config.rs @@ -32,6 +32,21 @@ impl Config { } } +impl Config { + /// Returns the path to the resources directory. + pub fn resources_dir_path() -> Option { + #[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 { diff --git a/src/main.rs b/src/main.rs index 8e1ebc27..54808edd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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}; @@ -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); @@ -59,3 +60,15 @@ pub unsafe fn decorate_window(window: *mut Object, _position: LogicalPosition Option { + #[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")) +}