mirror of
https://github.com/denoland/deno.git
synced 2025-01-10 08:09:06 -05:00
Add rust_test to gn build, with working example.
This commit is contained in:
parent
a2dde56c59
commit
6bff970d69
4 changed files with 64 additions and 18 deletions
|
@ -42,9 +42,10 @@ install:
|
||||||
- gn args $BUILD_PATH --list
|
- gn args $BUILD_PATH --list
|
||||||
- ccache -s
|
- ccache -s
|
||||||
# Travis hangs without -j2 argument to ninja.
|
# Travis hangs without -j2 argument to ninja.
|
||||||
- ninja -j2 -C $BUILD_PATH mock_runtime_test deno_cc deno
|
- ninja -j2 -C $BUILD_PATH mock_runtime_test handlers_test deno_cc deno
|
||||||
script:
|
script:
|
||||||
- $BUILD_PATH/mock_runtime_test
|
- $BUILD_PATH/mock_runtime_test
|
||||||
|
- $BUILD_PATH/handlers_test
|
||||||
- $BUILD_PATH/deno_cc foo bar
|
- $BUILD_PATH/deno_cc foo bar
|
||||||
- $BUILD_PATH/deno meow
|
- $BUILD_PATH/deno meow
|
||||||
- ./tools/lint.sh
|
- ./tools/lint.sh
|
||||||
|
|
5
BUILD.gn
5
BUILD.gn
|
@ -34,6 +34,11 @@ rust_component("handlers") {
|
||||||
extern = [ ":libc" ]
|
extern = [ ":libc" ]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rust_test("handlers_test") {
|
||||||
|
source_root = "src/handlers.rs"
|
||||||
|
extern = [ ":libc" ]
|
||||||
|
}
|
||||||
|
|
||||||
executable("deno_cc") {
|
executable("deno_cc") {
|
||||||
sources = [
|
sources = [
|
||||||
"src/main.cc",
|
"src/main.cc",
|
||||||
|
|
|
@ -10,7 +10,11 @@ template("run_rustc") {
|
||||||
"source_root",
|
"source_root",
|
||||||
"deps",
|
"deps",
|
||||||
"extern",
|
"extern",
|
||||||
|
"is_test",
|
||||||
])
|
])
|
||||||
|
if (defined(invoker.testonly)) {
|
||||||
|
testonly = invoker.testonly
|
||||||
|
}
|
||||||
if (defined(invoker.crate_name)) {
|
if (defined(invoker.crate_name)) {
|
||||||
crate_name = invoker.crate_name
|
crate_name = invoker.crate_name
|
||||||
} else {
|
} else {
|
||||||
|
@ -21,7 +25,6 @@ template("run_rustc") {
|
||||||
source_root,
|
source_root,
|
||||||
]
|
]
|
||||||
outputs = []
|
outputs = []
|
||||||
depfile = "$target_out_dir/$target_name.d"
|
|
||||||
script = "//third_party/v8/tools/run.py"
|
script = "//third_party/v8/tools/run.py"
|
||||||
|
|
||||||
args = [
|
args = [
|
||||||
|
@ -29,10 +32,24 @@ template("run_rustc") {
|
||||||
rebase_path(source_root, root_build_dir),
|
rebase_path(source_root, root_build_dir),
|
||||||
"--crate-name=$crate_name",
|
"--crate-name=$crate_name",
|
||||||
"--crate-type=$crate_type",
|
"--crate-type=$crate_type",
|
||||||
"--emit=dep-info=" + rebase_path(depfile, root_build_dir),
|
|
||||||
]
|
]
|
||||||
|
|
||||||
# We only use staticlib for the special "empty" lib.
|
if (defined(is_test) && is_test) {
|
||||||
|
# Test outputs are executables which should be in root_out_dir.
|
||||||
|
output = "$root_out_dir/$crate_name"
|
||||||
|
args += [
|
||||||
|
"--test",
|
||||||
|
"-o",
|
||||||
|
rebase_path(output, root_build_dir),
|
||||||
|
]
|
||||||
|
outputs += [ output ]
|
||||||
|
} else {
|
||||||
|
# Non-test targets are handled differently.
|
||||||
|
|
||||||
|
# For unknown reasons emitting a depfile on tests doesn't work.
|
||||||
|
depfile = "$target_out_dir/$target_name.d"
|
||||||
|
args += [ "--emit=dep-info=" + rebase_path(depfile, root_build_dir) ]
|
||||||
|
|
||||||
if (crate_type == "staticlib") {
|
if (crate_type == "staticlib") {
|
||||||
staticlib = "$target_out_dir/$crate_name.a"
|
staticlib = "$target_out_dir/$crate_name.a"
|
||||||
outputs += [ staticlib ]
|
outputs += [ staticlib ]
|
||||||
|
@ -50,6 +67,7 @@ template("run_rustc") {
|
||||||
outputs += [ rlib ]
|
outputs += [ rlib ]
|
||||||
args += [ "--emit=link=" + rebase_path(rlib, root_build_dir) ]
|
args += [ "--emit=link=" + rebase_path(rlib, root_build_dir) ]
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (is_debug) {
|
if (is_debug) {
|
||||||
args += [ "-g" ]
|
args += [ "-g" ]
|
||||||
|
@ -99,6 +117,7 @@ template("rust_component") {
|
||||||
"extern",
|
"extern",
|
||||||
"cfg",
|
"cfg",
|
||||||
"source_root",
|
"source_root",
|
||||||
|
"testonly",
|
||||||
])
|
])
|
||||||
if (!defined(invoker.crate_type)) {
|
if (!defined(invoker.crate_type)) {
|
||||||
crate_type = "rlib"
|
crate_type = "rlib"
|
||||||
|
@ -113,6 +132,7 @@ template("rust_component") {
|
||||||
[
|
[
|
||||||
"libs",
|
"libs",
|
||||||
"deps",
|
"deps",
|
||||||
|
"testonly",
|
||||||
])
|
])
|
||||||
if (!defined(deps)) {
|
if (!defined(deps)) {
|
||||||
deps = []
|
deps = []
|
||||||
|
@ -151,3 +171,18 @@ template("rust_executable") {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template("rust_test") {
|
||||||
|
run_rustc(target_name) {
|
||||||
|
crate_name = target_name
|
||||||
|
crate_type = "bin"
|
||||||
|
testonly = true
|
||||||
|
is_test = true
|
||||||
|
forward_variables_from(invoker,
|
||||||
|
[
|
||||||
|
"extern",
|
||||||
|
"cfg",
|
||||||
|
"source_root",
|
||||||
|
])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -10,6 +10,11 @@ fn string_from_ptr(ptr: *const c_char) -> String {
|
||||||
String::from(cstr.to_str().unwrap())
|
String::from(cstr.to_str().unwrap())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_example() {
|
||||||
|
assert_eq!(2 + 2, 4);
|
||||||
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn handle_code_fetch(
|
pub extern "C" fn handle_code_fetch(
|
||||||
module_specifier: *const c_char,
|
module_specifier: *const c_char,
|
||||||
|
|
Loading…
Reference in a new issue