Reland "[vm/wasm] Boilerplate for package:wasm"
This is a reland of 2bafc322fd
Original change's description:
> [vm/wasm] Boilerplate for package:wasm
>
> So far this just builds the wasmer library, copies it into the sdk
> directory, loads the library, and allows you to compile WASM modules.
> You can't actually do anything with the modules yet.
>
> Bug: https://github.com/dart-lang/sdk/issues/37882
> Change-Id: I7d7cfe5721bbe38a6afe76f326518e714d236ed4
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/158367
> Commit-Queue: Liam Appelbe <liama@google.com>
> Reviewed-by: Ryan Macnak <rmacnak@google.com>
Bug: https://github.com/dart-lang/sdk/issues/37882
Change-Id: I8056df1e301acde2772ba2273148faa53d03173e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/159321
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Liam Appelbe <liama@google.com>
This commit is contained in:
committed by
commit-bot@chromium.org
parent
085076337b
commit
0f14261176
+76
-13
@@ -2,40 +2,103 @@
|
||||
# for details. All rights reserved. Use of this source code is governed by a
|
||||
# BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
_dart_root = get_path_info("../..", "abspath")
|
||||
|
||||
template("rust_library") {
|
||||
manifest = rebase_path("Cargo.toml")
|
||||
if (defined(invoker.manifest)) {
|
||||
manifest = invoker.manifest
|
||||
}
|
||||
|
||||
debug = defined(invoker.debug) && invoker.debug
|
||||
shared = defined(invoker.shared) && invoker.shared
|
||||
|
||||
cmd = [
|
||||
rebase_path("//buildtools/${current_os}-${current_cpu}/rust/bin/cargo"),
|
||||
rebase_path("//buildtools/${host_os}-${host_cpu}/rust/bin/cargo"),
|
||||
"build",
|
||||
"--target-dir",
|
||||
rebase_path(target_out_dir),
|
||||
"--manifest-path",
|
||||
manifest,
|
||||
]
|
||||
output = "$target_out_dir/lib${invoker.lib_name}.a"
|
||||
debug = defined(invoker.debug) && invoker.debug
|
||||
|
||||
if (!debug) {
|
||||
# For cross compilation, figure out the target triple. You can get a full list
|
||||
# of the targets that rust supports like this: rustc --print target-list
|
||||
cargo_out_dir = target_out_dir
|
||||
if (is_linux) {
|
||||
rust_os = "unknown-linux-gnu"
|
||||
} else if (is_mac) {
|
||||
rust_os = "apple-darwin"
|
||||
} else if (is_win) {
|
||||
rust_os = "pc-windows-gnu"
|
||||
} else if (is_android) {
|
||||
rust_os = "linux-android"
|
||||
} else if (is_fuchsia) {
|
||||
rust_os = "fuchsia"
|
||||
}
|
||||
if (defined(rust_os)) {
|
||||
if (current_cpu == "x86") {
|
||||
rust_target = "i686-${rust_os}"
|
||||
} else if (current_cpu == "x64") {
|
||||
rust_target = "x86_64-${rust_os}"
|
||||
} else if (current_cpu == "arm") {
|
||||
rust_target = "arm-${rust_os}eabi"
|
||||
} else if (current_cpu == "arm64") {
|
||||
rust_target = "aarch64-${rust_os}"
|
||||
}
|
||||
}
|
||||
if (defined(rust_target)) {
|
||||
cmd += [
|
||||
"--target",
|
||||
rust_target,
|
||||
]
|
||||
cargo_out_dir += "/${rust_target}"
|
||||
}
|
||||
|
||||
if (debug) {
|
||||
cargo_out_dir += "/debug"
|
||||
} else {
|
||||
cargo_out_dir += "/release"
|
||||
cmd += [ "--release" ]
|
||||
}
|
||||
|
||||
action(target_name) {
|
||||
script = "//build/rust/run.py"
|
||||
output_file = ""
|
||||
if (shared) {
|
||||
if (is_win) {
|
||||
output_file = "${invoker.lib_name}.dll"
|
||||
} else if (is_mac) {
|
||||
output_file = "lib${invoker.lib_name}.dylib"
|
||||
} else {
|
||||
output_file = "lib${invoker.lib_name}.so"
|
||||
}
|
||||
} else {
|
||||
if (is_win) {
|
||||
output_file = "${invoker.lib_name}.lib"
|
||||
}else {
|
||||
output_file = "lib${invoker.lib_name}.a"
|
||||
}
|
||||
}
|
||||
|
||||
action("${target_name}_cargo") {
|
||||
script = "${_dart_root}/build/rust/run.py"
|
||||
args = cmd
|
||||
outputs = [ output ]
|
||||
outputs = [ "${cargo_out_dir}/${output_file}" ]
|
||||
public_configs = [ ":${target_name}_config" ]
|
||||
}
|
||||
|
||||
config("${target_name}_config") {
|
||||
libs = [ "wasmer" ]
|
||||
if (debug) {
|
||||
lib_dirs = [ "$target_out_dir/debug" ]
|
||||
} else {
|
||||
lib_dirs = [ "$target_out_dir/release" ]
|
||||
config("${target_name}_cargo_config") {
|
||||
if (!shared) {
|
||||
libs = [ invoker.lib_name ]
|
||||
lib_dirs = [ out_dir ]
|
||||
}
|
||||
}
|
||||
|
||||
# Cargo leaves the library in cargo_out_dir, which varies based on the target.
|
||||
# So we need to copy it to target_out_dir to make it easier for dependees to
|
||||
# locate the library.
|
||||
copy(target_name) {
|
||||
deps = [ ":${target_name}_cargo" ]
|
||||
sources = [ "${cargo_out_dir}/${output_file}" ]
|
||||
outputs = [ "${target_out_dir}/${output_file}" ]
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user