summaryrefslogtreecommitdiffstats
path: root/third_party/libwebrtc/build/rust/tests
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/libwebrtc/build/rust/tests')
-rw-r--r--third_party/libwebrtc/build/rust/tests/BUILD.gn22
-rw-r--r--third_party/libwebrtc/build/rust/tests/test_cpp_exe_including_rust/BUILD.gn8
-rw-r--r--third_party/libwebrtc/build/rust/tests/test_cpp_exe_including_rust/main.cc11
-rw-r--r--third_party/libwebrtc/build/rust/tests/test_rust_exe/BUILD.gn12
-rw-r--r--third_party/libwebrtc/build/rust/tests/test_rust_exe/main.rs9
-rw-r--r--third_party/libwebrtc/build/rust/tests/test_rust_source_set/BUILD.gn42
-rw-r--r--third_party/libwebrtc/build/rust/tests/test_rust_source_set/main.rs21
7 files changed, 125 insertions, 0 deletions
diff --git a/third_party/libwebrtc/build/rust/tests/BUILD.gn b/third_party/libwebrtc/build/rust/tests/BUILD.gn
new file mode 100644
index 0000000000..87a299f21f
--- /dev/null
+++ b/third_party/libwebrtc/build/rust/tests/BUILD.gn
@@ -0,0 +1,22 @@
+# Copyright 2021 The Chromium 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/config/rust.gni")
+
+group("tests") {
+ # Build some minimal binaries to exercise the Rust toolchain
+ # only if that toolchain is enabled in gn args.
+ if (toolchain_has_rust) {
+ deps = [
+ "test_cpp_exe_including_rust",
+ "test_rust_source_set",
+ ]
+ if (build_rust_unit_tests) {
+ deps += [ "test_rust_source_set:test_rust_source_set_unittests" ]
+ }
+ if (rustc_can_link) {
+ deps += [ "test_rust_exe" ]
+ }
+ }
+}
diff --git a/third_party/libwebrtc/build/rust/tests/test_cpp_exe_including_rust/BUILD.gn b/third_party/libwebrtc/build/rust/tests/test_cpp_exe_including_rust/BUILD.gn
new file mode 100644
index 0000000000..a5bdb3dc6c
--- /dev/null
+++ b/third_party/libwebrtc/build/rust/tests/test_cpp_exe_including_rust/BUILD.gn
@@ -0,0 +1,8 @@
+# Copyright 2021 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+executable("test_cpp_exe_including_rust") {
+ sources = [ "main.cc" ]
+ deps = [ "//build/rust/tests/test_rust_source_set:test_rust_source_set_lib" ]
+}
diff --git a/third_party/libwebrtc/build/rust/tests/test_cpp_exe_including_rust/main.cc b/third_party/libwebrtc/build/rust/tests/test_cpp_exe_including_rust/main.cc
new file mode 100644
index 0000000000..c1de55af1c
--- /dev/null
+++ b/third_party/libwebrtc/build/rust/tests/test_cpp_exe_including_rust/main.cc
@@ -0,0 +1,11 @@
+// Copyright 2021 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Defined in Rust.
+extern "C" void say_hello_from_cpp();
+
+int main(int argc, char* argv[]) {
+ say_hello_from_cpp();
+ return 0;
+}
diff --git a/third_party/libwebrtc/build/rust/tests/test_rust_exe/BUILD.gn b/third_party/libwebrtc/build/rust/tests/test_rust_exe/BUILD.gn
new file mode 100644
index 0000000000..0ce2e4a507
--- /dev/null
+++ b/third_party/libwebrtc/build/rust/tests/test_rust_exe/BUILD.gn
@@ -0,0 +1,12 @@
+# Copyright 2021 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+executable("test_rust_exe") {
+ crate_root = "main.rs"
+ deps = [ "//build/rust/tests/test_rust_source_set" ]
+ rustflags = [
+ "--edition",
+ "2018",
+ ]
+}
diff --git a/third_party/libwebrtc/build/rust/tests/test_rust_exe/main.rs b/third_party/libwebrtc/build/rust/tests/test_rust_exe/main.rs
new file mode 100644
index 0000000000..c1072054b8
--- /dev/null
+++ b/third_party/libwebrtc/build/rust/tests/test_rust_exe/main.rs
@@ -0,0 +1,9 @@
+// Copyright 2021 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+use test_rust_source_set::say_hello;
+
+fn main() {
+ say_hello();
+}
diff --git a/third_party/libwebrtc/build/rust/tests/test_rust_source_set/BUILD.gn b/third_party/libwebrtc/build/rust/tests/test_rust_source_set/BUILD.gn
new file mode 100644
index 0000000000..0dc9c540e1
--- /dev/null
+++ b/third_party/libwebrtc/build/rust/tests/test_rust_source_set/BUILD.gn
@@ -0,0 +1,42 @@
+# Copyright 2021 The Chromium 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/config/compiler/compiler.gni")
+import("//build/config/rust.gni")
+
+# A future CL will provide a gn template to generate all the following
+# automatically. We anticipate calling that template "rust_source_set"
+# which is why this test component is named the way it is.
+
+# Dependent Rust targets should depend on this.
+rust_library("test_rust_source_set") {
+ crate_name = "test_rust_source_set"
+ crate_root = "main.rs"
+ rustflags = [
+ "--edition",
+ "2018",
+ ]
+}
+
+# Dependent C++ targets should depend on this,
+# rather than the rlib above
+group("test_rust_source_set_lib") {
+ deps = [
+ ":test_rust_source_set",
+ "//build/rust/std",
+ ]
+}
+
+if (build_rust_unit_tests) {
+ executable("test_rust_source_set_unittests") {
+ crate_root = "main.rs"
+ rustflags = [
+ "--cfg",
+ "feature=\"test\"",
+ "--test",
+ "--edition",
+ "2018",
+ ]
+ }
+}
diff --git a/third_party/libwebrtc/build/rust/tests/test_rust_source_set/main.rs b/third_party/libwebrtc/build/rust/tests/test_rust_source_set/main.rs
new file mode 100644
index 0000000000..f0db1a3065
--- /dev/null
+++ b/third_party/libwebrtc/build/rust/tests/test_rust_source_set/main.rs
@@ -0,0 +1,21 @@
+// Copyright 2021 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#[no_mangle]
+pub extern "C" fn say_hello_from_cpp() {
+ say_hello();
+}
+
+pub fn say_hello() {
+ println!("Hello, world - from a Rust library. Calculations suggest that 3+4={}", do_maths());
+}
+
+fn do_maths() -> i32 {
+ 3 + 4
+}
+
+#[test]
+fn test_hello() {
+ assert_eq!(7, do_maths());
+}