Leverage Cargo's workspace inheritance feature (#4905)
* Leverage Cargo's workspace inheritance feature This commit is an attempt to reduce the complexity of the Cargo manifests in this repository with Cargo's workspace-inheritance feature becoming stable in Rust 1.64.0. This feature allows specifying fields in the root workspace `Cargo.toml` which are then reused throughout the workspace. For example this PR shares definitions such as: * All of the Wasmtime-family of crates now use `version.workspace = true` to have a single location which defines the version number. * All crates use `edition.workspace = true` to have one default edition for the entire workspace. * Common dependencies are listed in `[workspace.dependencies]` to avoid typing the same version number in a lot of different places (e.g. the `wasmparser = "0.89.0"` is now in just one spot. Currently the workspace-inheritance feature doesn't allow having two different versions to inherit, so all of the Cranelift-family of crates still manually specify their version. The inter-crate dependencies, however, are shared amongst the root workspace. This feature can be seen as a method of "preprocessing" of sorts for Cargo manifests. This will help us develop Wasmtime but shouldn't have any actual impact on the published artifacts -- everything's dependency lists are still the same. * Fix wasi-crypto tests
This commit is contained in:
@@ -105,6 +105,10 @@ const PUBLIC_CRATES: &[&str] = &[
|
||||
"wasmtime-types",
|
||||
];
|
||||
|
||||
struct Workspace {
|
||||
version: String,
|
||||
}
|
||||
|
||||
struct Crate {
|
||||
manifest: PathBuf,
|
||||
name: String,
|
||||
@@ -114,9 +118,13 @@ struct Crate {
|
||||
|
||||
fn main() {
|
||||
let mut crates = Vec::new();
|
||||
crates.push(read_crate("./Cargo.toml".as_ref()));
|
||||
find_crates("crates".as_ref(), &mut crates);
|
||||
find_crates("cranelift".as_ref(), &mut crates);
|
||||
let root = read_crate(None, "./Cargo.toml".as_ref());
|
||||
let ws = Workspace {
|
||||
version: root.version.clone(),
|
||||
};
|
||||
crates.push(root);
|
||||
find_crates("crates".as_ref(), &ws, &mut crates);
|
||||
find_crates("cranelift".as_ref(), &ws, &mut crates);
|
||||
|
||||
let pos = CRATES_TO_PUBLISH
|
||||
.iter()
|
||||
@@ -179,9 +187,9 @@ fn main() {
|
||||
}
|
||||
}
|
||||
|
||||
fn find_crates(dir: &Path, dst: &mut Vec<Crate>) {
|
||||
fn find_crates(dir: &Path, ws: &Workspace, dst: &mut Vec<Crate>) {
|
||||
if dir.join("Cargo.toml").exists() {
|
||||
let krate = read_crate(&dir.join("Cargo.toml"));
|
||||
let krate = read_crate(Some(ws), &dir.join("Cargo.toml"));
|
||||
if !krate.publish || CRATES_TO_PUBLISH.iter().any(|c| krate.name == *c) {
|
||||
dst.push(krate);
|
||||
} else {
|
||||
@@ -192,12 +200,12 @@ fn find_crates(dir: &Path, dst: &mut Vec<Crate>) {
|
||||
for entry in dir.read_dir().unwrap() {
|
||||
let entry = entry.unwrap();
|
||||
if entry.file_type().unwrap().is_dir() {
|
||||
find_crates(&entry.path(), dst);
|
||||
find_crates(&entry.path(), ws, dst);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn read_crate(manifest: &Path) -> Crate {
|
||||
fn read_crate(ws: Option<&Workspace>, manifest: &Path) -> Crate {
|
||||
let mut name = None;
|
||||
let mut version = None;
|
||||
let mut publish = true;
|
||||
@@ -218,6 +226,11 @@ fn read_crate(manifest: &Path) -> Crate {
|
||||
.to_string(),
|
||||
);
|
||||
}
|
||||
if let Some(ws) = ws {
|
||||
if version.is_none() && line.starts_with("version.workspace = true") {
|
||||
version = Some(ws.version.clone());
|
||||
}
|
||||
}
|
||||
if line.starts_with("publish = false") {
|
||||
publish = false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user