mirror of
https://github.com/dart-lang/sdk
synced 2024-11-05 18:22:09 +00:00
0e84aceb7e
Since FFI doesn't support structs by value yet, this thin wrapper library just provides versions of the import/export name functions that return the name by pointer. Also, I've used these functions to allow looking up functions by name, and added a function that prints a module's imports and exports (which is handy for debugging). Change-Id: Iff386e0b843bd8ab3763c99d3dc445ffedb12d6a BUG: https://github.com/dart-lang/sdk/issues/37882 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/161765 Reviewed-by: Ryan Macnak <rmacnak@google.com> Commit-Queue: Liam Appelbe <liama@google.com>
104 lines
2.8 KiB
Text
104 lines
2.8 KiB
Text
# 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.
|
|
|
|
_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/${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 = "${_dart_root}/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 = [ target_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) {
|
|
public_deps = [ ":${target_name}_cargo" ]
|
|
sources = [ "${cargo_out_dir}/${output_file}" ]
|
|
outputs = [ "${target_out_dir}/${output_file}" ]
|
|
}
|
|
}
|