-
Notifications
You must be signed in to change notification settings - Fork 267
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for cargo workspaces
- Loading branch information
1 parent
e221ba3
commit f1a4c86
Showing
12 changed files
with
383 additions
and
8 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[workspace] | ||
resolver = "2" | ||
members = ["simple-example", "not-default-example"] | ||
default-members = ["simple-example"] | ||
|
||
[workspace.package] | ||
edition = "2021" | ||
license = "MIT OR Apache-2.0" | ||
rust-version = "1.76" | ||
version = "0.27.2" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
[package] | ||
name = "not-default-example" | ||
version = "0.1.0" | ||
authors = ["Jens Reimann <[email protected]>"] | ||
edition = "2021" | ||
|
||
[dependencies] | ||
web-sys = { version = "0.3", features = [ | ||
"console", | ||
"Document", | ||
"HtmlElement", | ||
"Node", | ||
"Text", | ||
"Window", | ||
] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1" /> | ||
<title>Trunk | No-Rust</title> | ||
|
||
<base data-trunk-public-url /> | ||
</head> | ||
<body> | ||
<h1>Trunk without WASM in workspace (not default target)</h1> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
use web_sys::window; | ||
|
||
fn start_app() { | ||
let document = window() | ||
.and_then(|win| win.document()) | ||
.expect("Could not access document"); | ||
let body = document.body().expect("Could not access document.body"); | ||
let text_node = document.create_text_node("Hello, world from Vanilla Rust!"); | ||
body.append_child(text_node.as_ref()) | ||
.expect("Failed to append text"); | ||
} | ||
|
||
fn main() { | ||
start_app(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
[package] | ||
name = "simple-example" | ||
version = "0.1.0" | ||
authors = ["Jens Reimann <[email protected]>"] | ||
edition = "2021" | ||
|
||
[dependencies] | ||
web-sys = { version = "0.3", features = [ | ||
"console", | ||
"Document", | ||
"HtmlElement", | ||
"Node", | ||
"Text", | ||
"Window", | ||
] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1" /> | ||
<title>Trunk | No-Rust</title> | ||
|
||
<base data-trunk-public-url /> | ||
</head> | ||
<body> | ||
<h1>Trunk without WASM in workspace</h1> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
use web_sys::window; | ||
|
||
fn start_app() { | ||
let document = window() | ||
.and_then(|win| win.document()) | ||
.expect("Could not access document"); | ||
let body = document.body().expect("Could not access document.body"); | ||
let text_node = document.create_text_node("Hello, world from Vanilla Rust!"); | ||
body.append_child(text_node.as_ref()) | ||
.expect("Failed to append text"); | ||
} | ||
|
||
fn main() { | ||
start_app(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
mod cargo; | ||
pub mod workspace; | ||
|
||
use crate::config::{models::ConfigModel, Configuration}; | ||
use anyhow::bail; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
use anyhow::{Context, Result}; | ||
use cargo_metadata::{Metadata, MetadataCommand}; | ||
use serde::{Deserialize, Serialize}; | ||
use std::path::Path; | ||
use std::path::PathBuf; | ||
use tokio::task::spawn_blocking; | ||
|
||
#[derive(Debug, Clone, Serialize, Deserialize)] | ||
pub struct WorkspaceConfig { | ||
pub metadata: Metadata, | ||
} | ||
|
||
impl WorkspaceConfig { | ||
pub async fn new(manifest: &Path) -> Result<Self> { | ||
let mut cmd = MetadataCommand::new(); | ||
cmd.manifest_path(dunce::simplified(manifest)); | ||
let metadata = spawn_blocking(move || cmd.exec()) | ||
.await | ||
.context("error awaiting spawned cargo metadata task")? | ||
.context("error getting cargo metadata")?; | ||
Ok(Self { metadata }) | ||
} | ||
|
||
pub fn get_default_workspace(self) -> Option<PathBuf> { | ||
if let Some(default_member) = self.metadata.workspace_default_members.first() { | ||
if let Some(found) = self | ||
.metadata | ||
.packages | ||
.into_iter() | ||
.find(|p| p.id == *default_member) | ||
{ | ||
return Some(found.manifest_path.clone().into()); | ||
} | ||
} | ||
None | ||
} | ||
|
||
pub fn get_workspace_by_name(self, name: &str) -> Option<PathBuf> { | ||
// we search for the package in the workspace packages list | ||
if let Some(one_package) = self.metadata.packages.iter().find(|m| m.name == name) { | ||
// we check if the package is present in the workspace members list | ||
if self | ||
.metadata | ||
.workspace_members | ||
.into_iter() | ||
.any(|p| p == one_package.id) | ||
{ | ||
// we return the manifest path of the package | ||
return Some(one_package.manifest_path.clone().into()); | ||
} | ||
} | ||
None | ||
} | ||
} |
Oops, something went wrong.