diff --git a/build/rust/rustc_artifact.gni b/build/rust/rustc_artifact.gni index ec9cb51737641f38095bc601489fe35e922a157f..16c90084b0ec4f26b530879085829be448c0d96b 100644 --- a/build/rust/rustc_artifact.gni +++ b/build/rust/rustc_artifact.gni @@ -448,6 +448,15 @@ template("rustc_artifact") { args += [ "--with-unit-tests" ] } + if (defined(invoker.non_rust_deps)) { + foreach(dep, invoker.non_rust_deps) { + args += [ + "--lib-dir", + rebase_path(get_label_info(dep, "target_out_dir")), + ] + } + } + args += dep_info_paths outputs = [ output_file, diff --git a/examples/BUILD.gn b/examples/BUILD.gn index 23141b9b050bcb3c13028c469e727098783173d6..2223a6de7153d1120ce0a104eaa716195163b165 100644 --- a/examples/BUILD.gn +++ b/examples/BUILD.gn @@ -17,5 +17,6 @@ group("tests") { testonly = true deps = [ "hello_world:tests", + "rust_static_linking:static_linking_tests", ] } diff --git a/examples/rust_static_linking/BUILD.gn b/examples/rust_static_linking/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..f8f4f2dbb7afbc295011b39411e97981a597eb16 --- /dev/null +++ b/examples/rust_static_linking/BUILD.gn @@ -0,0 +1,34 @@ +# Copyright 2019 The Fuchsia Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +import("//build/package.gni") +import("//build/rust/rustc_library.gni") + +rustc_library("static_linking") { + name = "static_linking" + with_unit_tests = true + version = "0.1.0" + edition = "2018" + non_rust_deps = [ + ":static", + ] +} + +static_library("static") { + sources = [ + "static.c", + ] +} + +package("static_linking_tests") { + testonly = true + deps = [ + ":static_linking", + ] + tests = [ + { + name = "static_linking_lib_test" + }, + ] +} diff --git a/examples/rust_static_linking/src/lib.rs b/examples/rust_static_linking/src/lib.rs new file mode 100644 index 0000000000000000000000000000000000000000..9989dc74fb055c901d335aaaa1052e1e766afa0f --- /dev/null +++ b/examples/rust_static_linking/src/lib.rs @@ -0,0 +1,18 @@ +// Copyright 2019 The Fuchsia Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#[link(name = "static", kind = "static")] +extern "C" { + pub fn returns_two() -> u32; +} + +#[cfg(test)] +mod tests { + use super::returns_two; + + #[test] + fn linking_works() { + assert_eq!(unsafe { returns_two() }, 2); + } +} diff --git a/examples/rust_static_linking/static.c b/examples/rust_static_linking/static.c new file mode 100644 index 0000000000000000000000000000000000000000..60a9ee42cc921176c7bec9ef090254d70b78efed --- /dev/null +++ b/examples/rust_static_linking/static.c @@ -0,0 +1,9 @@ +// Copyright 2019 The Fuchsia Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include <stdint.h> + +uint32_t returns_two() { + return 2; +}