Skip to content

Commit

Permalink
refactor webc usage
Browse files Browse the repository at this point in the history
  • Loading branch information
maminrayej committed Oct 22, 2024
1 parent dd09e78 commit 34f3b66
Show file tree
Hide file tree
Showing 55 changed files with 6,674 additions and 183 deletions.
232 changes: 113 additions & 119 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,12 @@ version = "5.0.0-rc.1"

[workspace.dependencies]
# Repo-local crates
wasmer-package = { version = "0.1.0", path = "lib/package" }
wasmer-config = { path = "./lib/config" }
wasmer-wasix = { path = "./lib/wasix" }

# Wasmer-owned crates
webc = { version = "6.1.0", default-features = false, features = ["package"] }
webc = { path = "../pirita/crates/webc", version = "6.1.0", default-features = false, features = ["package"] }
shared-buffer = "0.1.4"

# Third-party crates
Expand Down
1 change: 1 addition & 0 deletions lib/backend-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ rust-version.workspace = true
[dependencies]
# Wasmer dependencies.
wasmer-config = { version = "0.9.0", path = "../config" }
wasmer-package.workspace = true
webc.workspace = true


Expand Down
5 changes: 3 additions & 2 deletions lib/backend-api/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use time::OffsetDateTime;
use tracing::Instrument;
use url::Url;
use wasmer_config::package::PackageIdent;
use wasmer_package::container::Container;

use crate::{
types::{self, *},
Expand Down Expand Up @@ -374,7 +375,7 @@ pub async fn fetch_webc_package(
client: &WasmerClient,
ident: &PackageIdent,
default_registry: &Url,
) -> Result<webc::compat::Container, anyhow::Error> {
) -> Result<Container, anyhow::Error> {
let url = match ident {
PackageIdent::Named(n) => Url::parse(&format!(
"{default_registry}/{}:{}",
Expand All @@ -398,7 +399,7 @@ pub async fn fetch_webc_package(
.bytes()
.await?;

webc::compat::Container::from_bytes(data).context("failed to parse webc package")
Container::from_bytes(data).context("failed to parse webc package")
}

/// Fetch app templates.
Expand Down
2 changes: 1 addition & 1 deletion lib/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ wasmer-compiler-cranelift = { version = "=5.0.0-rc.1", path = "../compiler-crane
wasmer-compiler-singlepass = { version = "=5.0.0-rc.1", path = "../compiler-singlepass", optional = true }
wasmer-compiler-llvm = { version = "=5.0.0-rc.1", path = "../compiler-llvm", optional = true }
wasmer-emscripten = { version = "=5.0.0-rc.1", path = "../emscripten" }
wasmer-package = { version = "=0.1.0", path = "../package" }
wasmer-package.workspace = true

wasmer-vm = { version = "=5.0.0-rc.1", path = "../vm", optional = true }
wasmer-wasix = { path = "../wasix", version = "=0.29.0", features = [
Expand Down
11 changes: 5 additions & 6 deletions lib/cli/src/commands/create_exe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@ use tar::Archive;
use wasmer::sys::Artifact;
use wasmer::*;
use wasmer_object::{emit_serialized, get_object_for_target};
use wasmer_package::container::Container;
use wasmer_package::package::{Metadata, Volume as WebcVolume};
use wasmer_types::{compilation::symbols::ModuleMetadataSymbolRegistry, ModuleInfo};
use webc::{
compat::{Container, Volume as WebcVolume},
PathSegments,
};
use webc::PathSegments;

use self::utils::normalize_atom_name;
use crate::{
Expand Down Expand Up @@ -516,14 +515,14 @@ fn serialize_volume_to_webc_v1(volume: &WebcVolume) -> Vec<u8> {
path.push(segment);

match meta {
webc::compat::Metadata::Dir { .. } => {
Metadata::Dir { .. } => {
files.insert(
webc::v1::DirOrFile::Dir(path.to_string().into()),
Vec::new(),
);
read_dir(volume, path, files);
}
webc::compat::Metadata::File { .. } => {
Metadata::File { .. } => {
if let Some((contents, _)) = volume.read_file(&*path) {
files.insert(
webc::v1::DirOrFile::File(path.to_string().into()),
Expand Down
3 changes: 2 additions & 1 deletion lib/cli/src/commands/create_obj.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::{env, path::PathBuf};
use anyhow::{Context, Result};
use clap::Parser;
use wasmer::*;
use wasmer_package::container::Container;

use crate::store::CompilerOptions;

Expand Down Expand Up @@ -83,7 +84,7 @@ impl CreateObj {
println!("Compiler: {}", compiler_type);
println!("Target: {}", target.triple());

let atoms = if let Ok(webc) = webc::compat::Container::from_disk(&input_path) {
let atoms = if let Ok(webc) = Container::from_disk(&input_path) {
crate::commands::create_exe::compile_pirita_into_directory(
&webc,
&output_directory_path,
Expand Down
5 changes: 3 additions & 2 deletions lib/cli/src/commands/gen_c_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ use anyhow::{Context, Error};
use bytes::Bytes;
use clap::Parser;
use wasmer_compiler::Artifact;
use wasmer_package::container::{Container, ContainerError};
use wasmer_types::{
compilation::symbols::ModuleMetadataSymbolRegistry, CpuFeature, MetadataHeader, Triple,
};
use webc::{compat::SharedBytes, Container, DetectError};
use webc::{compat::SharedBytes, DetectError};

use crate::store::CompilerOptions;

Expand Down Expand Up @@ -62,7 +63,7 @@ impl GenCHeader {

let atom = match Container::from_bytes(file.clone()) {
Ok(webc) => self.get_atom(&webc)?,
Err(webc::compat::ContainerError::Detect(DetectError::InvalidMagic { .. })) => {
Err(ContainerError::Detect(DetectError::InvalidMagic { .. })) => {
// we've probably got a WebAssembly file
file.into()
}
Expand Down
12 changes: 5 additions & 7 deletions lib/cli/src/commands/package/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use dialoguer::console::{style, Emoji};
use indicatif::ProgressBar;
use sha2::Digest;
use wasmer_config::package::PackageHash;
use webc::wasmer_package::Package;
use wasmer_package::package::Package;

use crate::utils::load_package_manifest;

Expand Down Expand Up @@ -54,12 +54,10 @@ impl PackageBuild {
manifest_path.display()
)
};
let pkg = webc::wasmer_package::Package::from_manifest(manifest_path.clone()).context(
format!(
"While parsing the manifest (loaded from {})",
manifest_path.canonicalize()?.display()
),
)?;
let pkg = Package::from_manifest(manifest_path.clone()).context(format!(
"While parsing the manifest (loaded from {})",
manifest_path.canonicalize()?.display()
))?;
let data = pkg.serialize().context("While validating the package")?;
let hash = sha2::Sha256::digest(&data).into();
let pkg_hash = PackageHash::from_sha256_bytes(hash);
Expand Down
2 changes: 1 addition & 1 deletion lib/cli/src/commands/package/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use std::{
};
use wasmer_api::WasmerClient;
use wasmer_config::package::{Manifest, NamedPackageIdent, PackageHash};
use webc::wasmer_package::Package;
use wasmer_package::package::Package;

pub mod macros;
pub mod wait;
Expand Down
5 changes: 3 additions & 2 deletions lib/cli/src/commands/package/download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use dialoguer::console::{style, Emoji};
use indicatif::{ProgressBar, ProgressStyle};
use tempfile::NamedTempFile;
use wasmer_config::package::{PackageIdent, PackageSource};
use wasmer_package::container::Container;

use crate::config::WasmerEnv;

Expand Down Expand Up @@ -243,7 +244,7 @@ impl PackageDownload {

step_num += 1;

webc::compat::Container::from_disk(tmpfile.path())
Container::from_disk(tmpfile.path())
.context("could not parse downloaded file as a package - invalid download?")?;
}

Expand Down Expand Up @@ -302,6 +303,6 @@ mod tests {

cmd.execute().unwrap();

webc::compat::Container::from_disk(out_path).unwrap();
Container::from_disk(out_path).unwrap();
}
}
2 changes: 1 addition & 1 deletion lib/cli/src/commands/package/push.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use is_terminal::IsTerminal;
use std::path::{Path, PathBuf};
use wasmer_api::WasmerClient;
use wasmer_config::package::{Manifest, PackageHash};
use webc::wasmer_package::Package;
use wasmer_package::package::Package;

/// Push a package to the registry.
///
Expand Down
3 changes: 2 additions & 1 deletion lib/cli/src/commands/package/unpack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::path::PathBuf;
use anyhow::Context;
use dialoguer::console::{style, Emoji};
use indicatif::ProgressBar;
use wasmer_package::container::Container;

/// Extract contents of a webc image to a directory.
///
Expand Down Expand Up @@ -67,7 +68,7 @@ impl PackageUnpack {
PACKAGE_EMOJI
));

let pkg = webc::compat::Container::from_disk(&self.package_path).with_context(|| {
let pkg = Container::from_disk(&self.package_path).with_context(|| {
format!(
"could not open package at '{}'",
self.package_path.display()
Expand Down
3 changes: 2 additions & 1 deletion lib/cli/src/commands/run/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ use wasmer::{
#[cfg(feature = "compiler")]
use wasmer_compiler::ArtifactBuild;
use wasmer_config::package::PackageSource as PackageSpecifier;
use wasmer_package::container::Container;
use wasmer_registry::{wasmer_env::WasmerEnv, Package};
use wasmer_types::ModuleHash;
#[cfg(feature = "journal")]
Expand All @@ -53,7 +54,7 @@ use wasmer_wasix::{
},
Runtime, WasiError,
};
use webc::{metadata::Manifest, Container};
use webc::metadata::Manifest;

use crate::{
commands::run::wasi::Wasi, common::HashAlgorithm, error::PrettyError, logging::Output,
Expand Down
16 changes: 16 additions & 0 deletions lib/package/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,23 @@ rust-version.workspace = true
webc.workspace = true
wasmer-config = { version = "0.9.0", path = "../config" }
toml = "0.8.0"
bytes = "1.8.0"
sha2 = "0.10.8"
shared-buffer.workspace = true
serde_json = "1.0.132"
anyhow = "1.0.90"
thiserror = "1.0.64"
cfg-if = "1.0.0"
ciborium = "0.2.2"
semver = "1.0.23"
url = "2.5.2"
serde = "1.0.211"
insta = { version = "1", features = ["filters", "yaml"] }
flate2 = "1.0.34"
tar = "0.4.42"
tempfile = "3.12.0"

[dev-dependencies]
pretty_assertions.workspace = true
tempfile = "3.12.0"
regex = "1.11.0"
Loading

0 comments on commit 34f3b66

Please sign in to comment.