Skip to content

Commit

Permalink
Merge #2195
Browse files Browse the repository at this point in the history
2195: feat(types) Remove dependency to `cranelift-entity` r=Hywan a=Hywan

# Description

Don't be afraid, everything is cool.

`cranelift-entity` is nice, but we are limited by it. We want to go
further for some features. Those features are very likely to be
refused by Cranelift because it's out of their scope.

This patch basically copies the code from `cranelift-entity` inside
`wasmer-types`. The code has been modified to fit in our own
“`no_std`” strategy. The code will be modified deeper in upcoming
patches and most of the entities are likely to radically change. The
goal of this patch is strictly to not break our code while porting the
new code.

# Review

- [ ] Add a short description of the the change to the CHANGELOG.md file
- [ ] Do we need to update the `ATTRIBUTIONS.md` file?

Co-authored-by: Ivan Enderlin <ivan@mnt.io>
  • Loading branch information
bors[bot] and Hywan committed Mar 18, 2021
2 parents cc37172 + 805a637 commit 3c7d194
Show file tree
Hide file tree
Showing 14 changed files with 1,551 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion lib/compiler-cranelift/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ edition = "2018"
wasmer-compiler = { path = "../compiler", version = "1.0.2", features = ["translator"], default-features = false }
wasmer-vm = { path = "../vm", version = "1.0.2" }
wasmer-types = { path = "../wasmer-types", version = "1.0.2", default-features = false, features = ["std"] }
cranelift-entity = { version = "0.70", default-features = false }
cranelift-codegen = { version = "0.70", default-features = false, features = ["x86", "arm64"] }
cranelift-frontend = { version = "0.70", default-features = false }
tracing = "0.1"
Expand All @@ -36,7 +37,7 @@ maintenance = { status = "actively-developed" }
[features]
default = ["std", "enable-serde", "unwind"]
unwind = ["cranelift-codegen/unwind", "gimli"]
enable-serde = ["wasmer-compiler/enable-serde", "wasmer-types/enable-serde"]
enable-serde = ["wasmer-compiler/enable-serde", "wasmer-types/enable-serde", "cranelift-entity/enable-serde"]
std = ["cranelift-codegen/std", "cranelift-frontend/std", "wasmer-compiler/std", "wasmer-types/std"]
core = ["hashbrown", "cranelift-codegen/core", "cranelift-frontend/core"]

Expand Down
1 change: 1 addition & 0 deletions lib/compiler-cranelift/src/sink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use crate::translator::{irlibcall_to_libcall, irreloc_to_relocationkind};
use cranelift_codegen::binemit;
use cranelift_codegen::ir::{self, ExternalName};
use cranelift_entity::EntityRef as CraneliftEntityRef;
use wasmer_compiler::{JumpTable, Relocation, RelocationTarget, TrapInformation};
use wasmer_types::entity::EntityRef;
use wasmer_types::{FunctionIndex, LocalFunctionIndex};
Expand Down
3 changes: 2 additions & 1 deletion lib/compiler-cranelift/src/translator/translation_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use core::u32;
use cranelift_codegen::binemit::Reloc;
use cranelift_codegen::ir::{self, AbiParam};
use cranelift_codegen::isa::TargetFrontendConfig;
use cranelift_entity::{EntityRef as CraneliftEntityRef, SecondaryMap as CraneliftSecondaryMap};
use cranelift_frontend::FunctionBuilder;
use wasmer_compiler::wasm_unsupported;
use wasmer_compiler::wasmparser;
Expand Down Expand Up @@ -148,7 +149,7 @@ pub fn get_vmctx_value_label() -> ir::ValueLabel {

/// Transforms Cranelift JumpTable's into runtime JumpTables
pub fn transform_jump_table(
jt_offsets: SecondaryMap<ir::JumpTable, u32>,
jt_offsets: CraneliftSecondaryMap<ir::JumpTable, u32>,
) -> SecondaryMap<JumpTable, u32> {
let mut func_jt_offsets = SecondaryMap::with_capacity(jt_offsets.capacity());

Expand Down
5 changes: 1 addition & 4 deletions lib/wasmer-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,11 @@ readme = "README.md"
edition = "2018"

[dependencies]
# We use `cranelift-entity` here because it's a lightweight dependency and it contains
# some useful data structures
cranelift-entity = "0.70"
serde = { version = "1.0", features = ["derive"], optional = true, default-features = false }
thiserror = "1.0"

[features]
default = ["std", "enable-serde"]
std = ["serde/std"]
core = []
enable-serde = ["serde", "cranelift-entity/enable-serde"]
enable-serde = ["serde"]
7 changes: 7 additions & 0 deletions lib/wasmer-types/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# `wasmer-types` [![Build Status](https://github.com/wasmerio/wasmer/workflows/build/badge.svg?style=flat-square)](https://github.com/wasmerio/wasmer/actions?query=workflow%3Abuild) [![Join Wasmer Slack](https://img.shields.io/static/v1?label=Slack&message=join%20chat&color=brighgreen&style=flat-square)](https://slack.wasmer.io) [![MIT License](https://img.shields.io/github/license/wasmerio/wasmer.svg?style=flat-square)](https://github.com/wasmerio/wasmer/blob/master/LICENSE)

This crate provides the basic structures to use WebAssembly easily anywhere.

### Acknowledgments

This project borrowed some of the code for the entity structure from [cranelift-entity](https://crates.io/crates/cranelift-entity).
We decided to move it here to help on serialization/deserialization and also to ease the integration with other tools like `loupe`.

Please check [Wasmer ATTRIBUTIONS](https://github.com/wasmerio/wasmer/blob/master/ATTRIBUTIONS.md) to further see licenses and other attributions of the project.

0 comments on commit 3c7d194

Please sign in to comment.