Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Cargo Packager support #18

Closed
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
157 changes: 157 additions & 0 deletions .github/workflows/publish_nightly.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
name: Continuous Deployment

on:
push:
branches:
- "*"
Comment on lines +4 to +6
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
push:
branches:
- "*"
pull_request:
branches:
- main

schedule:
- cron: "0 0 * * *"

jobs:

draft:
runs-on: ubuntu-latest
environment: "Init Workflow"
steps:
- uses: actions/checkout@v4

- name: create draft release
uses: crabnebula-dev/cloud-release@v0.1.0
with:
command: release draft test-verso 0.0.1 --framework packager
api-key: ${{ secrets.CN_API_KEY }}

build-linux:
name: Build [linux]
needs: draft
runs-on: ubuntu-latest # We may want this to be older for wider libc compatibility
environment: "Init Workflow"
steps:
- name: Checkout the repository
uses: actions/checkout@v4

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

- name: Set env
run: echo "LIBCLANG_PATH=/usr/lib/llvm-14/lib" >> $GITHUB_ENV

- name: Install dependencies
run: |
sudo apt-get update
sudo apt install build-essential python3-pip ccache clang cmake curl \
g++ git gperf libdbus-1-dev libfreetype6-dev libgl1-mesa-dri \
libgles2-mesa-dev libglib2.0-dev libgstreamer-plugins-base1.0-dev \
gstreamer1.0-plugins-good libgstreamer-plugins-good1.0-dev \
gstreamer1.0-plugins-bad libgstreamer-plugins-bad1.0-dev \
gstreamer1.0-plugins-ugly gstreamer1.0-plugins-base \
libgstreamer-plugins-base1.0-dev gstreamer1.0-libav \
libgstrtspserver-1.0-dev gstreamer1.0-tools libges-1.0-dev \
libharfbuzz-dev liblzma-dev libunwind-dev libunwind-dev libvulkan1 \
libx11-dev libxcb-render0-dev libxcb-shape0-dev libxcb-xfixes0-dev \
libxmu-dev libxmu6 libegl1-mesa-dev llvm-dev m4 xorg-dev

- name: Install Cargo Packager
run: cargo install cargo-packager --locked

- name: Package the App
run: cargo packager --release --verbose

- name: Move assets to workdir
run: |
mv target/release/* .

- name: upload assets
uses: crabnebula-dev/cloud-release@v0.1.0
with:
command: release upload test-verso 0.0.1 --framework packager
api-key: ${{ secrets.CN_API_KEY }}


build-windows:
name: Build [windows]
needs: draft
runs-on: windows-latest
environment: "Init Workflow"
steps:
- name: Checkout the repository
uses: actions/checkout@v4

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

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

- name: Install dependencies
run: scoop install git python llvm cmake curl

- name: Install Cargo Packager
run: cargo install cargo-packager --locked

- name: Package the App
run: cargo packager --release --verbose

- name: Move assets to workdir
run: |
mv target/release/* .

- name: upload assets
uses: crabnebula-dev/cloud-release@v0.1.0
with:
command: release upload test-verso 0.0.1 --framework packager
api-key: ${{ secrets.CN_API_KEY }}

build-macos:
name: Build [macos]
needs: draft
runs-on: macos-latest
environment: "Init Workflow"
steps:
- name: Checkout the repository
uses: actions/checkout@v4

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

- name: Install dependencies
run: brew install cmake pkg-config

- name: Install Cargo Packager
run: cargo install cargo-packager --locked

- name: Package the App
run: cargo packager --release --verbose

- name: Move assets to workdir
run: |
mv target/release/* .

- name: upload assets
uses: crabnebula-dev/cloud-release@v0.1.0
with:
command: release upload test-verso 0.0.1 --framework packager
api-key: ${{ secrets.CN_API_KEY }}

publish:
needs: [build-linux, build-windows, build-macos]

runs-on: ubuntu-latest
environment: "Init Workflow"
steps:
- uses: actions/checkout@v4

- name: publish release
uses: crabnebula-dev/cloud-release@v0.1.0
with:
command: release publish test-verso 0.0.1 --framework packager
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.

23 changes: 21 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ edition = "2021"
license = "Apache-2.0 OR MIT"
description = "A web browser"
readme = "README.md"
repository = "https://github.com/wusyong/verso"
repository = "https://github.com/european-browser/verso"
documentation = "https://docs.rs/verso"
categories = ["Web programming"]

Expand All @@ -19,9 +19,26 @@ targets = [
"x86_64-apple-darwin",
]

[package.metadata.packager]
name = "verso"
product-name = "verso"
identifier = "com.eu-browser.verso"
version = "0.0.1"
before-each-package-command = "cargo build --release --features packager"
out-dir = "target/release"
resources = [
"resources",
"demo.html"
]
icons=[
"resources/icons/icon256x256.png",
"resources/icons/icon.ico"
wusyong marked this conversation as resolved.
Show resolved Hide resolved
]

[features]
default = []

# Exclusively for cargo packager command.
packager = ["dep:cargo-packager-resource-resolver"]

[build-dependencies]
cfg_aliases = "0.1"
Expand All @@ -37,6 +54,8 @@ crossbeam-channel = "0.5"
getopts = "0.2.17"
surfman = { version = "0.9", features = ["chains", "sm-angle", "sm-angle-default", "sm-x11", "sm-raw-window-handle"] }
winit = { version = "0.29", features = ["rwh_05"] }
# Cargo Packager
cargo-packager-resource-resolver = { version = "0.1", features = ["auto-detect-format"], optional = true }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated a commit that can embed all resource files into binary. I believe we don't need to handle file path then.


[target."cfg(any(target_os = \"ios\", target_os = \"macos\"))".dependencies]
block = "0.1"
Expand Down
Binary file added resources/icons/icon.ico
Binary file not shown.
Binary file added resources/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.
10 changes: 10 additions & 0 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ use winit::{

use crate::{prefs, resources, webview::WebView};

#[cfg(feature = "packager")]
use cargo_packager_resource_resolver::{current_format, resources_dir};

/// Status of webview.
#[derive(Clone, Copy, Debug, Default)]
pub enum Status {
Expand Down Expand Up @@ -58,7 +61,14 @@ impl Verso {
CompositeTarget::Fbo,
);

#[cfg(not(feature = "packager"))]
let demo_path = std::env::current_dir().unwrap().join("demo.html");
// For production builds, use Resourse Resolver for demo file
#[cfg(feature = "packager")]
let demo_path = resources_dir(current_format().unwrap())
.unwrap()
.join("demo.html");

let url = ServoUrl::from_file_path(demo_path.to_str().unwrap()).unwrap();
init_servo
.servo
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Verso Web Browser
//!
//! This is the documentation of Verso's types and items. See [Github page](https://github.com/wusyong/Verso) for more general introduction.
//! This is the documentation of Verso's types and items. See [Github page](https://github.com/european-browser/verso) for more general introduction.

#![deny(missing_docs)]

Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use winit::{dpi::PhysicalSize, event_loop::EventLoop, window::WindowBuilder};
use verso::{Result, Status, Verso};
use winit::{dpi::PhysicalSize, event_loop::EventLoop, window::WindowBuilder};

/* window decoration */
#[cfg(target_os = "macos")]
Expand Down
17 changes: 16 additions & 1 deletion src/resources.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
use std::{env, fs, path::PathBuf};
use std::{fs, path::PathBuf};

#[cfg(not(feature = "packager"))]
use std::env;

use servo::embedder_traits::resources::{self, Resource, ResourceReaderMethods};

struct ResourceReader(PathBuf);

#[cfg(feature = "packager")]
use cargo_packager_resource_resolver::{current_format, resources_dir};

/// Initialize resource files. We currently read from `resources` directory only.
pub fn init() {
resources::set(Box::new(ResourceReader(resources_dir_path())));
Expand All @@ -25,6 +31,15 @@ impl ResourceReaderMethods for ResourceReader {
}
}

#[cfg(feature = "packager")]
fn resources_dir_path() -> PathBuf {
// For Cargo Packager builds, use Resourse Resolver
return resources_dir(current_format().unwrap())
.unwrap()
.join("resources");
}

#[cfg(not(feature = "packager"))]
fn resources_dir_path() -> PathBuf {
// Try ./resources relative to the directory containing the
// canonicalised executable path, then each of its ancestors.
Expand Down
2 changes: 1 addition & 1 deletion tests/general.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use winit::event_loop::EventLoopWindowTarget;
use verso::verso_test;
use winit::event_loop::EventLoopWindowTarget;

fn smoke(_elwt: &EventLoopWindowTarget<()>) {}
fn other_smoke(_elwt: &EventLoopWindowTarget<()>) {}
Expand Down