From 48f0d697638bc57992523a5812cd79782bc67654 Mon Sep 17 00:00:00 2001 From: Benjamin Bouvier Date: Mon, 11 Mar 2019 13:09:58 +0000 Subject: [PATCH] Bug 1532689: Use Cranelift features to include only architecture-specific support; r=froydnj This introduces features in the jsrust crate, so we can enable/disable compilation for a specific platform at compile-time. It also does only select the architecture targeted by the JIT, which should result in slightly lower compilation times on every platform, and lower binary sizes too. Differential Revision: https://phabricator.services.mozilla.com/D22280 --HG-- extra : moz-landing-system : lando --- js/src/rust/Cargo.toml | 6 ++++++ js/src/rust/moz.build | 13 ++++++++++++- js/src/rust/shared/Cargo.toml | 6 ++++++ js/src/wasm/cranelift/Cargo.toml | 12 +++++++++++- toolkit/library/gtest/rust/Cargo.toml | 4 ++++ toolkit/library/rust/Cargo.toml | 4 ++++ toolkit/library/rust/gkrust-features.mozbuild | 8 ++++++++ toolkit/library/rust/shared/Cargo.toml | 4 ++++ 8 files changed, 55 insertions(+), 2 deletions(-) diff --git a/js/src/rust/Cargo.toml b/js/src/rust/Cargo.toml index 4b36b28b68e5..9f59b83ef4c8 100644 --- a/js/src/rust/Cargo.toml +++ b/js/src/rust/Cargo.toml @@ -8,5 +8,11 @@ name = "jsrust" crate-type = ["staticlib"] path = "lib.rs" +[features] +cranelift_x86 = ['jsrust_shared/cranelift_x86'] +cranelift_arm32 = ['jsrust_shared/cranelift_arm32'] +cranelift_arm64 = ['jsrust_shared/cranelift_arm64'] +cranelift_none = ['jsrust_shared/cranelift_none'] + [dependencies] jsrust_shared = { path = "./shared" } diff --git a/js/src/rust/moz.build b/js/src/rust/moz.build index 792e54deff38..cb47e33f0019 100644 --- a/js/src/rust/moz.build +++ b/js/src/rust/moz.build @@ -4,7 +4,18 @@ # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. -RustLibrary('jsrust') +features = [] + +if CONFIG['JS_CODEGEN_X64'] or CONFIG['JS_CODEGEN_X86']: + features += ['cranelift_x86'] +elif CONFIG['JS_CODEGEN_ARM']: + features += ['cranelift_arm32'] +elif CONFIG['JS_CODEGEN_ARM64']: + features += ['cranelift_arm64'] +else: + features += ['cranelift_none'] + +RustLibrary('jsrust', features) CONFIGURE_SUBST_FILES += ['extra-bindgen-flags'] diff --git a/js/src/rust/shared/Cargo.toml b/js/src/rust/shared/Cargo.toml index 4edd8ce1db36..60867cb19be4 100644 --- a/js/src/rust/shared/Cargo.toml +++ b/js/src/rust/shared/Cargo.toml @@ -12,6 +12,12 @@ path = "lib.rs" baldrdash = { path = "../../wasm/cranelift" } mozilla-central-workspace-hack = { path = "../../../../build/workspace-hack" } +[features] +cranelift_x86 = ['baldrdash/cranelift_x86'] +cranelift_arm32 = ['baldrdash/cranelift_arm32'] +cranelift_arm64 = ['baldrdash/cranelift_arm64'] +cranelift_none = ['baldrdash/cranelift_none'] + # Uncomment this to enable perf support in release mode. #[profile.release] #debug = true diff --git a/js/src/wasm/cranelift/Cargo.toml b/js/src/wasm/cranelift/Cargo.toml index b48f5bfe6c4a..42f532c2bef5 100644 --- a/js/src/wasm/cranelift/Cargo.toml +++ b/js/src/wasm/cranelift/Cargo.toml @@ -8,7 +8,7 @@ crate-type = ["rlib"] name = "baldrdash" [dependencies] -cranelift-codegen = "0.29.0" +cranelift-codegen = { version = "0.29.0", default-features = false } cranelift-wasm = "0.29.0" target-lexicon = "0.2.0" log = { version = "0.4.6", default-features = false, features = ["release_max_level_info"] } @@ -17,6 +17,16 @@ env_logger = "0.5.6" [build-dependencies] bindgen = {version = "0.43", default-features = false} # disable `logging` to reduce code size +[features] +default = ['cranelift-codegen/std'] +cranelift_x86 = ['cranelift-codegen/x86'] +cranelift_arm32 = ['cranelift-codegen/arm32'] +cranelift_arm64 = ['cranelift-codegen/arm64'] + +# The "none" support is a lie (so far): Cranelift has to include support for +# one ISA at the moment, so request to include support for a small one: riscv. +cranelift_none = ['cranelift-codegen/riscv'] + # Uncomment this to enable perf support in release mode. #[profile.release] #debug = true diff --git a/toolkit/library/gtest/rust/Cargo.toml b/toolkit/library/gtest/rust/Cargo.toml index f03e4f02693f..857929a952dd 100644 --- a/toolkit/library/gtest/rust/Cargo.toml +++ b/toolkit/library/gtest/rust/Cargo.toml @@ -15,6 +15,10 @@ gecko_debug = ["gkrust-shared/gecko_debug"] simd-accel = ["gkrust-shared/simd-accel"] moz_memory = ["gkrust-shared/moz_memory"] spidermonkey_rust = ["gkrust-shared/spidermonkey_rust"] +cranelift_x86 = ["gkrust-shared/cranelift_x86"] +cranelift_arm32 = ["gkrust-shared/cranelift_arm32"] +cranelift_arm64 = ["gkrust-shared/cranelift_arm64"] +cranelift_none = ["gkrust-shared/cranelift_none"] gecko_profiler = ["gkrust-shared/gecko_profiler"] gecko_profiler_parse_elf = ["gkrust-shared/gecko_profiler_parse_elf"] diff --git a/toolkit/library/rust/Cargo.toml b/toolkit/library/rust/Cargo.toml index 7ff4adb794e3..34699683c404 100644 --- a/toolkit/library/rust/Cargo.toml +++ b/toolkit/library/rust/Cargo.toml @@ -15,6 +15,10 @@ gecko_debug = ["gkrust-shared/gecko_debug"] simd-accel = ["gkrust-shared/simd-accel"] moz_memory = ["gkrust-shared/moz_memory"] spidermonkey_rust = ["gkrust-shared/spidermonkey_rust"] +cranelift_x86 = ["gkrust-shared/cranelift_x86"] +cranelift_arm32 = ["gkrust-shared/cranelift_arm32"] +cranelift_arm64 = ["gkrust-shared/cranelift_arm64"] +cranelift_none = ["gkrust-shared/cranelift_none"] gecko_profiler = ["gkrust-shared/gecko_profiler"] gecko_profiler_parse_elf = ["gkrust-shared/gecko_profiler_parse_elf"] diff --git a/toolkit/library/rust/gkrust-features.mozbuild b/toolkit/library/rust/gkrust-features.mozbuild index c2c6e2895785..7afef34e3c81 100644 --- a/toolkit/library/rust/gkrust-features.mozbuild +++ b/toolkit/library/rust/gkrust-features.mozbuild @@ -28,6 +28,14 @@ if CONFIG['MOZ_MEMORY']: if CONFIG['ENABLE_WASM_CRANELIFT']: gkrust_features += ['spidermonkey_rust'] + if CONFIG['JS_CODEGEN_X86'] or CONFIG['JS_CODEGEN_X64']: + gkrust_features += ['cranelift_x86'] + elif CONFIG['JS_CODEGEN_ARM']: + gkrust_features += ['cranelift_arm32'] + elif CONFIG['JS_CODEGEN_ARM64']: + gkrust_features += ['cranelift_arm64'] + else: + gkrust_features += ['cranelift_none'] if CONFIG['MOZ_GECKO_PROFILER']: gkrust_features += ['gecko_profiler'] diff --git a/toolkit/library/rust/shared/Cargo.toml b/toolkit/library/rust/shared/Cargo.toml index c9dcff11de6e..777e65bc107c 100644 --- a/toolkit/library/rust/shared/Cargo.toml +++ b/toolkit/library/rust/shared/Cargo.toml @@ -47,6 +47,10 @@ gecko_debug = ["geckoservo/gecko_debug", "nsstring/gecko_debug"] simd-accel = ["encoding_c/simd-accel", "encoding_glue/simd-accel"] moz_memory = ["mp4parse_capi/mp4parse_fallible"] spidermonkey_rust = ["jsrust_shared"] +cranelift_x86 = ["jsrust_shared/cranelift_x86"] +cranelift_arm32 = ["jsrust_shared/cranelift_arm32"] +cranelift_arm64 = ["jsrust_shared/cranelift_arm64"] +cranelift_none = ["jsrust_shared/cranelift_none"] gecko_profiler = ["profiler_helper"] gecko_profiler_parse_elf = ["profiler_helper/parse_elf"]