From 830ee60d28faeef4830e03d85d519a7600151b16 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Wed, 18 Apr 2018 17:39:43 -0700 Subject: [PATCH] Add no_std support in module, simplejit, and umbrella. --- README.rst | 29 +++++++++++++++++++---------- cranelift/test-no_std.sh | 7 ++++++- lib/codegen/Cargo.toml | 6 +++--- lib/codegen/src/context.rs | 1 + lib/module/Cargo.toml | 13 +++++++++++-- lib/simplejit/Cargo.toml | 13 +++++++++---- lib/umbrella/Cargo.toml | 9 +++++++-- 7 files changed, 56 insertions(+), 22 deletions(-) diff --git a/README.rst b/README.rst index 28f2250ace..1e519f2117 100644 --- a/README.rst +++ b/README.rst @@ -35,9 +35,9 @@ the System V AMD64 ABI calling convention used on many platforms, but does not yet support the Windows x64 calling convention. The performance of code produced by Cretonne is not yet impressive, though we have plans to fix that. -The core codegen crates have minimal dependencies, and do not require any host -floating-point support. Support for `no_std` mode in the core codegen crates is -`in development `_. +The core codegen crates have minimal dependencies, support +`no_std <#building-with-no-std>` mode, and do not require any host +floating-point support. Cretonne does not yet perform mitigations for Spectre or related security issues, though it may do so in the future. It does not currently make any @@ -93,22 +93,31 @@ installed. Building with `no_std` ---------------------- -To build cretonne without libstd, disable the `std` feature on `lib/cretonne`, -`lib/frontend`, `lib/native`, and `lib/wasm`, which is otherwise enabled by -default, and enable the `core` feature. +The following crates support `no_std`: + - `cretonne-entity` + - `cretonne-codegen` + - `cretonne-frontend` + - `cretonne-native` + - `cretonne-wasm` + - `cretonne-module` + - `cretonne-simplejit` + - `cretonne` -For example, to build `cretonne`: +To use `no_std` mode, disable the `std` feature and enable the `core` feature. +This currently requires nightly rust. + +For example, to build `cretonne-codegen`: .. code-block:: sh - cd lib/cretonne + cd lib/codegen cargo build --no-default-features --features core -Or, when using `cretonne` as a dependency (in Cargo.toml): +Or, when using `cretonne-codegen` as a dependency (in Cargo.toml): .. code-block:: - [dependency.cretonne] + [dependency.cretonne-codegen] ... default-features = false features = ["core"] diff --git a/cranelift/test-no_std.sh b/cranelift/test-no_std.sh index 800c712402..66a629eb57 100755 --- a/cranelift/test-no_std.sh +++ b/cranelift/test-no_std.sh @@ -15,14 +15,19 @@ function banner() { } # Test those packages which have no_std support. -LIBS="codegen frontend wasm native" +LIBS="codegen frontend wasm native module simplejit umbrella" cd "$topdir" for LIB in $LIBS do banner "Rust unit tests in $LIB" cd "lib/$LIB" + + # Test with just "core" enabled. cargo test --no-default-features --features core + + # Test with "core" and "std" enabled at the same time. cargo test --features core + cd "$topdir" done diff --git a/lib/codegen/Cargo.toml b/lib/codegen/Cargo.toml index 2a7854f6c1..0c5a1104ba 100644 --- a/lib/codegen/Cargo.toml +++ b/lib/codegen/Cargo.toml @@ -12,12 +12,12 @@ build = "build.rs" [dependencies] cretonne-entity = { path = "../entity", version = "0.5.1", default-features = false } +failure = { version = "0.1.1", default-features = false, features = ["derive"] } +failure_derive = { version = "0.1.1", default-features = false } # It is a goal of the cretonne-codegen crate to have minimal external dependencies. # Please don't add any unless they are essential to the task of creating binary # machine code. Integration tests that need external dependencies can be # accomodated in `tests`. -failure = { version = "0.1.1", default-features = false, features = ["derive"] } -failure_derive = { version = "0.1.1", default-features = false } [dependencies.hashmap_core] version = "0.1.1" @@ -28,7 +28,7 @@ optional = true # of some minimal std-like replacement libraries. At least one of these two # features to be enabled. default = ["std"] -std = [] +std = ["cretonne-entity/std"] core = ["hashmap_core"] [badges] diff --git a/lib/codegen/src/context.rs b/lib/codegen/src/context.rs index 95e78ff128..71b873b653 100644 --- a/lib/codegen/src/context.rs +++ b/lib/codegen/src/context.rs @@ -23,6 +23,7 @@ use preopt::do_preopt; use regalloc; use result::{CtonError, CtonResult}; use settings::{FlagsOrIsa, OptLevel}; +use std::vec::Vec; use simple_gvn::do_simple_gvn; use timing; use unreachable_code::eliminate_unreachable_code; diff --git a/lib/module/Cargo.toml b/lib/module/Cargo.toml index 42dc6ee916..f9d5728109 100644 --- a/lib/module/Cargo.toml +++ b/lib/module/Cargo.toml @@ -9,8 +9,17 @@ license = "Apache-2.0" readme = "README.md" [dependencies] -cretonne-codegen = { path = "../codegen", version = "0.5.1" } -cretonne-entity = { path = "../entity", version = "0.5.1" } +cretonne-codegen = { path = "../codegen", version = "0.5.1", default-features = false } +cretonne-entity = { path = "../entity", version = "0.5.1", default-features = false } + +[dependencies.hashmap_core] +version = "0.1.1" +optional = true + +[features] +default = ["std"] +std = ["cretonne-codegen/std", "cretonne-entity/std"] +core = ["hashmap_core", "cretonne-codegen/core"] [badges] maintenance = { status = "experimental" } diff --git a/lib/simplejit/Cargo.toml b/lib/simplejit/Cargo.toml index 0fdc16da32..7d5fbb4d23 100644 --- a/lib/simplejit/Cargo.toml +++ b/lib/simplejit/Cargo.toml @@ -9,13 +9,18 @@ license = "Apache-2.0" readme = "README.md" [dependencies] -cretonne-codegen = { path = "../codegen", version = "0.5.1" } -cretonne-module = { path = "../module", version = "0.5.1" } -cretonne-native = { path = "../native", version = "0.5.1" } +cretonne-codegen = { path = "../codegen", version = "0.5.1", default-features = false } +cretonne-module = { path = "../module", version = "0.5.1", default-features = false } +cretonne-native = { path = "../native", version = "0.5.1", default-features = false } region = "0.2.0" -libc = "0.2.40" +libc = { version = "0.2.40", default-features = false } errno = "0.2.3" +[features] +default = ["std"] +std = ["libc/use_std", "cretonne-codegen/std", "cretonne-module/std", "cretonne-native/std"] +core = ["cretonne-codegen/core", "cretonne-module/core", "cretonne-native/core"] + [badges] maintenance = { status = "experimental" } travis-ci = { repository = "Cretonne/cretonne" } diff --git a/lib/umbrella/Cargo.toml b/lib/umbrella/Cargo.toml index f7bdc002cd..6895955244 100644 --- a/lib/umbrella/Cargo.toml +++ b/lib/umbrella/Cargo.toml @@ -10,8 +10,13 @@ readme = "README.md" keywords = ["compile", "compiler", "jit"] [dependencies] -cretonne-codegen = { path = "../codegen", version = "0.5.1" } -cretonne-frontend = { path = "../frontend", version = "0.5.1" } +cretonne-codegen = { path = "../codegen", version = "0.5.1", default-features = false } +cretonne-frontend = { path = "../frontend", version = "0.5.1", default-features = false } + +[features] +default = ["std"] +std = ["cretonne-codegen/std", "cretonne-frontend/std"] +core = ["cretonne-codegen/core", "cretonne-frontend/core"] [badges] maintenance = { status = "experimental" }