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 2 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
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.

17 changes: 17 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,21 @@ 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"
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 = []

Expand All @@ -37,6 +52,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"] }
Copy link
Member

Choose a reason for hiding this comment

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

I read the documentation of cargo-packager-resource-resolver and it seems it requires cargo packager.
I don't want any release builds being restrict to cargo packager only. Otherwise, other users won't be able to build their own release profiles. Is it possible we just access somewhere in release build? I saw there's resources tag mentioned above.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, we must use any sort of packager out there to create bundles. So, it is just better to use cargo packager instead of 3 or more separate crates.

Otherwise, other users won't be able to build their own release profiles

Why? Cargo Packager is an open source project, and any user can just install it and build their own release profile.

I don't see any alternative as well as any reason against using cargo packager to be honest.

Copy link
Member

Choose a reason for hiding this comment

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

Servo uses bundle manual commands in their mach scripts. There could be people want to build dmg all by themselves. And cargo package hasn't supported Flatpak yet which is a key format in verso's feature request issue. We should contain cargo packager metadata in Cargo.toml only.

I believe we don't need cargo packager to establish a CN cloud workflow for now. Just try to upload the binary as an artifact should be enough. We can worry about package format later.

Choose a reason for hiding this comment

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

cargo-packager-resource-resolver does rely on cargo-packager's CLI. we could move it behind a feature flag to support custom build systems

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done


[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.
9 changes: 9 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(not(debug_assertions))]
use cargo_packager_resource_resolver::{current_format, resources_dir};

/// Status of webview.
#[derive(Clone, Copy, Debug, Default)]
pub enum Status {
Expand Down Expand Up @@ -59,6 +62,12 @@ impl Verso {
);

let demo_path = std::env::current_dir().unwrap().join("demo.html");
// For production builds, use Resourse Resolver for demo file
#[cfg(not(debug_assertions))]
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/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
9 changes: 9 additions & 0 deletions src/resources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ use servo::embedder_traits::resources::{self, Resource, ResourceReaderMethods};

struct ResourceReader(PathBuf);

#[cfg(not(debug_assertions))]
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 @@ -26,6 +29,12 @@ impl ResourceReaderMethods for ResourceReader {
}

fn resources_dir_path() -> PathBuf {
// For production builds, use Resourse Resolver
#[cfg(not(debug_assertions))]
return resources_dir(current_format().unwrap())
.unwrap()
.join("resources");

// Try ./resources relative to the directory containing the
// canonicalised executable path, then each of its ancestors.
let mut path = env::current_exe().unwrap().canonicalize().unwrap();
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