1
0
mirror of https://github.com/dart-lang/sdk synced 2024-07-08 12:06:26 +00:00
dart-sdk/build/rust/rust.gni
Liam Appelbe 2bafc322fd [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>
2020-08-18 23:55:31 +00:00

103 lines
2.7 KiB
Plaintext

# Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
# 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.
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/${host_os}-${host_cpu}/rust/bin/cargo"),
"build",
"--target-dir",
rebase_path(target_out_dir),
"--manifest-path",
manifest,
]
# 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" ]
}
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 = "//build/rust/run.py"
args = cmd
outputs = [ "${cargo_out_dir}/${output_file}" ]
public_configs = [ ":${target_name}_config" ]
}
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}" ]
}
}