Skip to content

Commit

Permalink
Rename UniversalArtifact to Artifact
Browse files Browse the repository at this point in the history
  • Loading branch information
epilys committed Jul 20, 2022
1 parent 3de4bfc commit ec375b1
Show file tree
Hide file tree
Showing 14 changed files with 54 additions and 55 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Looking for changes that affect our C API? See the [C API Changelog](lib/c-api/C
- [#2946](https://github.com/wasmerio/wasmer/pull/2946) Remove dylib,staticlib engines in favor of a single Universal engine
- [#2949](https://github.com/wasmerio/wasmer/pull/2949) Switch back to using custom LLVM builds on CI
- #2892 Renamed `get_native_function` to `get_typed_function`, marked former as deprecated.
- [#2869](https://github.com/wasmerio/wasmer/pull/2869) Removed Artifact, Engine traits. Renamed UniversalArtifact to Artifact, and UniversalEngine to Engine.

### Fixed
- [#2963](https://github.com/wasmerio/wasmer/pull/2963) Remove accidental dependency on libwayland and libxcb in ClI
Expand Down
2 changes: 1 addition & 1 deletion docs/migration_to_3.0.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ let wasm_bytes = wat2wasm(
let compiler_config = Cranelift::default();
let mut store = Store::new(&compiler_config);
let module = Module::new(&store, wasm_bytes)?;
let instance = Instance::new(&module, &imports! {})?;
let instance = Instance::new(&mut store, &module, &imports! {})?;
```

[examples]: https://docs.wasmer.io/integrations/examples
Expand Down
2 changes: 1 addition & 1 deletion lib/api/src/sys/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ pub use wasmer_compiler_cranelift::{Cranelift, CraneliftOptLevel};
pub use wasmer_compiler_llvm::{LLVMOptLevel, LLVM};

#[cfg(feature = "universal")]
pub use wasmer_compiler::{Engine, Universal, UniversalArtifact};
pub use wasmer_compiler::{Artifact, Engine, Universal};

/// Version number of this crate.
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
Expand Down
8 changes: 4 additions & 4 deletions lib/api/src/sys/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use std::io;
use std::path::Path;
use std::sync::Arc;
use thiserror::Error;
use wasmer_compiler::Artifact;
use wasmer_compiler::ArtifactCreate;
use wasmer_compiler::UniversalArtifact;
#[cfg(feature = "wat")]
use wasmer_types::WasmError;
use wasmer_types::{
Expand Down Expand Up @@ -50,7 +50,7 @@ pub struct Module {
//
// In the future, this code should be refactored to properly describe the
// ownership of the code and its metadata.
artifact: Arc<UniversalArtifact>,
artifact: Arc<Artifact>,
module_info: Arc<ModuleInfo>,
}

Expand Down Expand Up @@ -281,7 +281,7 @@ impl Module {
Ok(Self::from_artifact(artifact))
}

fn from_artifact(artifact: Arc<UniversalArtifact>) -> Self {
fn from_artifact(artifact: Arc<Artifact>) -> Self {
Self {
module_info: Arc::new(artifact.create_module_info()),
artifact,
Expand Down Expand Up @@ -456,7 +456,7 @@ impl Module {
/// this functionality is required for some core functionality though, like
/// the object file engine.
#[doc(hidden)]
pub fn artifact(&self) -> &Arc<UniversalArtifact> {
pub fn artifact(&self) -> &Arc<Artifact> {
&self.artifact
}
}
Expand Down
8 changes: 5 additions & 3 deletions lib/cli-compiler/src/commands/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use anyhow::{Context, Result};
use std::path::{Path, PathBuf};
use structopt::StructOpt;
use wasmer_compiler::ModuleEnvironment;
use wasmer_compiler::{ArtifactCreate, UniversalArtifactBuild};
use wasmer_compiler::{ArtifactBuild, ArtifactCreate};
use wasmer_types::entity::PrimaryMap;
use wasmer_types::{
CompileError, CpuFeature, MemoryIndex, MemoryStyle, TableIndex, TableStyle, Target, Triple,
Expand Down Expand Up @@ -40,7 +40,9 @@ impl Compile {
}

pub(crate) fn get_recommend_extension(target_triple: &Triple) -> Result<&'static str> {
Ok(wasmer_compiler::UniversalArtifactBuild::get_default_extension(target_triple))
Ok(wasmer_compiler::ArtifactBuild::get_default_extension(
target_triple,
))
}

fn inner_execute(&self) -> Result<()> {
Expand Down Expand Up @@ -97,7 +99,7 @@ impl Compile {
.values()
.map(|table_type| tunables.table_style(table_type))
.collect();
let artifact = UniversalArtifactBuild::new(
let artifact = ArtifactBuild::new(
&mut engine,
&wasm_bytes,
&target,
Expand Down
2 changes: 1 addition & 1 deletion lib/cli/src/commands/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl Compile {
.map(|osstr| osstr.to_string_lossy().to_string())
.unwrap_or_default();
let recommended_extension =
wasmer_compiler::UniversalArtifact::get_default_extension(target.triple());
wasmer_compiler::Artifact::get_default_extension(target.triple());
match self.output.extension() {
Some(ext) => {
if ext != recommended_extension {
Expand Down
4 changes: 2 additions & 2 deletions lib/cli/src/commands/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ impl Run {

fn get_store_module(&self) -> Result<(Store, Module)> {
let contents = std::fs::read(self.path.clone())?;
if wasmer_compiler::UniversalArtifact::is_deserializable(&contents) {
if wasmer_compiler::Artifact::is_deserializable(&contents) {
let engine = wasmer_compiler::Universal::headless().engine();
let store = Store::new_with_engine(&engine);
let module = unsafe { Module::deserialize_from_file(&store, &self.path)? };
Expand Down Expand Up @@ -309,7 +309,7 @@ impl Run {
let mut cache = FileSystemCache::new(cache_dir_root)?;

let extension =
wasmer_compiler::UniversalArtifact::get_default_extension(&Triple::host()).to_string();
wasmer_compiler::Artifact::get_default_extension(&Triple::host()).to_string();
cache.set_cache_extension(Some(extension));
Ok(cache)
}
Expand Down
38 changes: 19 additions & 19 deletions lib/compiler/src/engine/universal/artifact.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
//! Define `UniversalArtifact`, based on `UniversalArtifactBuild`
//! Define `Artifact`, based on `ArtifactBuild`
//! to allow compiling and instantiating to be done as separate steps.
use super::engine::{Engine, EngineInner};
use crate::engine::universal::link::link_module;
use crate::ArtifactBuild;
use crate::ArtifactCreate;
use crate::Features;
#[cfg(feature = "universal_engine")]
use crate::ModuleEnvironment;
use crate::UniversalArtifactBuild;
use crate::{
register_frame_info, resolve_imports, FunctionExtent, GlobalFrameInfoRegistration,
InstantiationError, MetadataHeader, RuntimeError, Tunables,
Expand All @@ -25,8 +25,8 @@ use wasmer_vm::{FunctionBodyPtr, MemoryStyle, TableStyle, VMSharedSignatureIndex
use wasmer_vm::{InstanceAllocator, InstanceHandle, StoreObjects, TrapHandlerFn, VMExtern};

/// A compiled wasm module, ready to be instantiated.
pub struct UniversalArtifact {
artifact: UniversalArtifactBuild,
pub struct Artifact {
artifact: ArtifactBuild,
finished_functions: BoxedSlice<LocalFunctionIndex, FunctionBodyPtr>,
finished_function_call_trampolines: BoxedSlice<SignatureIndex, VMTrampoline>,
finished_dynamic_function_trampolines: BoxedSlice<FunctionIndex, FunctionBodyPtr>,
Expand All @@ -35,8 +35,8 @@ pub struct UniversalArtifact {
finished_function_lengths: BoxedSlice<LocalFunctionIndex, usize>,
}

impl UniversalArtifact {
/// Compile a data buffer into a `UniversalArtifactBuild`, which may then be instantiated.
impl Artifact {
/// Compile a data buffer into a `ArtifactBuild`, which may then be instantiated.
#[cfg(feature = "universal_engine")]
pub fn new(
engine: &Engine,
Expand All @@ -58,7 +58,7 @@ impl UniversalArtifact {
.map(|table_type| tunables.table_style(table_type))
.collect();

let artifact = UniversalArtifactBuild::new(
let artifact = ArtifactBuild::new(
inner_engine.builder_mut(),
data,
engine.target(),
Expand All @@ -69,38 +69,38 @@ impl UniversalArtifact {
Self::from_parts(&mut inner_engine, artifact)
}

/// Compile a data buffer into a `UniversalArtifactBuild`, which may then be instantiated.
/// Compile a data buffer into a `ArtifactBuild`, which may then be instantiated.
#[cfg(not(feature = "universal_engine"))]
pub fn new(_engine: &Engine, _data: &[u8]) -> Result<Self, CompileError> {
Err(CompileError::Codegen(
"Compilation is not enabled in the engine".to_string(),
))
}

/// Deserialize a UniversalArtifactBuild
/// Deserialize a ArtifactBuild
///
/// # Safety
/// This function is unsafe because rkyv reads directly without validating
/// the data.
pub unsafe fn deserialize(engine: &Engine, bytes: &[u8]) -> Result<Self, DeserializeError> {
if !UniversalArtifactBuild::is_deserializable(bytes) {
if !ArtifactBuild::is_deserializable(bytes) {
return Err(DeserializeError::Incompatible(
"The provided bytes are not wasmer-universal".to_string(),
));
}
let bytes = &bytes[UniversalArtifactBuild::MAGIC_HEADER.len()..];
let bytes = &bytes[ArtifactBuild::MAGIC_HEADER.len()..];
let metadata_len = MetadataHeader::parse(bytes)?;
let metadata_slice: &[u8] = &bytes[MetadataHeader::LEN..][..metadata_len];
let serializable = SerializableModule::deserialize(metadata_slice)?;
let artifact = UniversalArtifactBuild::from_serializable(serializable);
let artifact = ArtifactBuild::from_serializable(serializable);
let mut inner_engine = engine.inner_mut();
Self::from_parts(&mut inner_engine, artifact).map_err(DeserializeError::Compiler)
}

/// Construct a `UniversalArtifactBuild` from component parts.
/// Construct a `ArtifactBuild` from component parts.
pub fn from_parts(
engine_inner: &mut EngineInner,
artifact: UniversalArtifactBuild,
artifact: ArtifactBuild,
) -> Result<Self, CompileError> {
let module_info = artifact.create_module_info();
let (
Expand Down Expand Up @@ -182,15 +182,15 @@ impl UniversalArtifact {
}
/// Get the default extension when serializing this artifact
pub fn get_default_extension(triple: &Triple) -> &'static str {
UniversalArtifactBuild::get_default_extension(triple)
ArtifactBuild::get_default_extension(triple)
}
/// Check if the provided bytes look like a serialized `UniversalArtifactBuild`.
/// Check if the provided bytes look like a serialized `ArtifactBuild`.
pub fn is_deserializable(bytes: &[u8]) -> bool {
UniversalArtifactBuild::is_deserializable(bytes)
ArtifactBuild::is_deserializable(bytes)
}
}

impl ArtifactCreate for UniversalArtifact {
impl ArtifactCreate for Artifact {
fn create_module_info(&self) -> ModuleInfo {
self.artifact.create_module_info()
}
Expand Down Expand Up @@ -220,7 +220,7 @@ impl ArtifactCreate for UniversalArtifact {
}
}

impl UniversalArtifact {
impl Artifact {
/// Register thie `Artifact` stack frame information into the global scope.
///
/// This is required to ensure that any traps can be properly symbolicated.
Expand Down
17 changes: 7 additions & 10 deletions lib/compiler/src/engine/universal/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#[cfg(feature = "universal_engine")]
use crate::Compiler;
use crate::EngineBuilder;
use crate::{CodeMemory, UniversalArtifact};
use crate::{Artifact, CodeMemory};
use crate::{FunctionExtent, Tunables};
use memmap2::Mmap;
use std::path::Path;
Expand Down Expand Up @@ -106,8 +106,8 @@ impl Engine {
&self,
binary: &[u8],
tunables: &dyn Tunables,
) -> Result<Arc<UniversalArtifact>, CompileError> {
Ok(Arc::new(UniversalArtifact::new(self, binary, tunables)?))
) -> Result<Arc<Artifact>, CompileError> {
Ok(Arc::new(Artifact::new(self, binary, tunables)?))
}

/// Compile a WebAssembly binary
Expand All @@ -116,7 +116,7 @@ impl Engine {
&self,
_binary: &[u8],
_tunables: &dyn Tunables,
) -> Result<Arc<UniversalArtifact>, CompileError> {
) -> Result<Arc<Artifact>, CompileError> {
Err(CompileError::Codegen(
"The Engine is operating in headless mode, so it can not compile Modules.".to_string(),
))
Expand All @@ -127,11 +127,8 @@ impl Engine {
/// # Safety
///
/// The serialized content must represent a serialized WebAssembly module.
pub unsafe fn deserialize(
&self,
bytes: &[u8],
) -> Result<Arc<UniversalArtifact>, DeserializeError> {
Ok(Arc::new(UniversalArtifact::deserialize(self, bytes)?))
pub unsafe fn deserialize(&self, bytes: &[u8]) -> Result<Arc<Artifact>, DeserializeError> {
Ok(Arc::new(Artifact::deserialize(self, bytes)?))
}

/// Deserializes a WebAssembly module from a path
Expand All @@ -142,7 +139,7 @@ impl Engine {
pub unsafe fn deserialize_from_file(
&self,
file_ref: &Path,
) -> Result<Arc<UniversalArtifact>, DeserializeError> {
) -> Result<Arc<Artifact>, DeserializeError> {
let file = std::fs::File::open(file_ref)?;
let mmap = Mmap::map(&file)?;
self.deserialize(&mmap)
Expand Down
2 changes: 1 addition & 1 deletion lib/compiler/src/engine/universal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ mod engine;
mod link;
mod unwind;

pub use self::artifact::UniversalArtifact;
pub use self::artifact::Artifact;
pub use self::builder::Universal;
pub use self::code_memory::CodeMemory;
pub use self::engine::Engine;
Expand Down
16 changes: 8 additions & 8 deletions lib/compiler/src/universal_artifact/artifact.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! Define `UniversalArtifactBuild` to allow compiling and instantiating to be
//! Define `ArtifactBuild` to allow compiling and instantiating to be
//! done as separate steps.
#[cfg(feature = "universal_engine")]
Expand All @@ -24,20 +24,20 @@ use wasmer_types::{
};

/// A compiled wasm module, ready to be instantiated.
pub struct UniversalArtifactBuild {
pub struct ArtifactBuild {
serializable: SerializableModule,
}

impl UniversalArtifactBuild {
impl ArtifactBuild {
/// Header signature for wasmu binary
pub const MAGIC_HEADER: &'static [u8; 16] = b"wasmer-universal";

/// Check if the provided bytes look like a serialized `UniversalArtifactBuild`.
/// Check if the provided bytes look like a serialized `ArtifactBuild`.
pub fn is_deserializable(bytes: &[u8]) -> bool {
bytes.starts_with(Self::MAGIC_HEADER)
}

/// Compile a data buffer into a `UniversalArtifactBuild`, which may then be instantiated.
/// Compile a data buffer into a `ArtifactBuild`, which may then be instantiated.
#[cfg(feature = "universal_engine")]
pub fn new(
inner_engine: &mut EngineBuilder,
Expand Down Expand Up @@ -116,15 +116,15 @@ impl UniversalArtifactBuild {
Ok(Self { serializable })
}

/// Compile a data buffer into a `UniversalArtifactBuild`, which may then be instantiated.
/// Compile a data buffer into a `ArtifactBuild`, which may then be instantiated.
#[cfg(not(feature = "universal_engine"))]
pub fn new(_engine: &EngineBuilder, _data: &[u8]) -> Result<Self, CompileError> {
Err(CompileError::Codegen(
"Compilation is not enabled in the engine".to_string(),
))
}

/// Create a new UniversalArtifactBuild from a SerializableModule
/// Create a new ArtifactBuild from a SerializableModule
pub fn from_serializable(serializable: SerializableModule) -> Self {
Self { serializable }
}
Expand Down Expand Up @@ -187,7 +187,7 @@ impl UniversalArtifactBuild {
}
}

impl ArtifactCreate for UniversalArtifactBuild {
impl ArtifactCreate for ArtifactBuild {
fn create_module_info(&self) -> ModuleInfo {
self.serializable.compile_info.module.clone()
}
Expand Down
6 changes: 3 additions & 3 deletions lib/compiler/src/universal_artifact/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//! Generic Artifact abstraction for Wasmer Engines.
mod artifact;
mod engine;
mod builder;
mod trampoline;

pub use self::artifact::UniversalArtifactBuild;
pub use self::engine::EngineBuilder;
pub use self::artifact::ArtifactBuild;
pub use self::builder::EngineBuilder;
pub use self::trampoline::*;
3 changes: 1 addition & 2 deletions lib/types/src/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ pub struct SerializableCompilation {
pub libcall_trampoline_len: u32,
}

/// Serializable struct that is able to serialize from and to
/// a `UniversalArtifactInfo`.
/// Serializable struct that is able to serialize from and to a `ArtifactInfo`.
#[derive(Archive, RkyvDeserialize, RkyvSerialize)]
#[allow(missing_docs)]
pub struct SerializableModule {
Expand Down

0 comments on commit ec375b1

Please sign in to comment.