diff --git a/.travis.yml b/.travis.yml index d1fc0883..6d7f255d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,6 +25,7 @@ matrix: script: - buck build :cxx#check --verbose=0 - buck run demo-rs --verbose=0 + - buck test ... --verbose=0 - name: Bazel rust: nightly before_install: @@ -36,3 +37,4 @@ matrix: - cargo vendor --versioned-dirs --locked third-party/vendor script: - bazel run demo-rs:demo_rs --verbose_failures --noshow_progress + - bazel test ... --verbose_failures --noshow_progress diff --git a/build/rust.bzl b/build/rust.bzl index c2dade74..3ef4d917 100644 --- a/build/rust.bzl +++ b/build/rust.bzl @@ -2,6 +2,7 @@ load( "@io_bazel_rules_rust//rust:rust.bzl", _rust_binary = "rust_binary", _rust_library = "rust_library", + _rust_test = "rust_test", ) def rust_binary(edition = "2018", **kwargs): @@ -17,3 +18,6 @@ def rust_library(edition = "2018", **kwargs): def third_party_rust_library(rustc_flags = [], **kwargs): rustc_flags = rustc_flags + ["--cap-lints=allow"] rust_library(rustc_flags = rustc_flags, **kwargs) + +def rust_test(edition = "2018", **kwargs): + _rust_test(edition = edition, **kwargs) diff --git a/tests/BUCK b/tests/BUCK new file mode 100644 index 00000000..81f74de4 --- /dev/null +++ b/tests/BUCK @@ -0,0 +1,42 @@ +rust_test( + name = "test", + srcs = ["test.rs"], + deps = [":ffi"], +) + +rust_library( + name = "ffi", + srcs = ["ffi/lib.rs"], + crate = "cxx_test_suite", + deps = [ + ":impl", + "//:cxx", + ], +) + +cxx_library( + name = "impl", + srcs = [ + "ffi/tests.cc", + ":gen-source", + ], + headers = { + "ffi/lib.rs": ":gen-header", + "ffi/tests.h": "ffi/tests.h", + }, + deps = ["//:core"], +) + +genrule( + name = "gen-header", + srcs = ["ffi/lib.rs"], + cmd = "$(exe //:codegen) --header ${SRCS} > ${OUT}", + out = "gen.h", +) + +genrule( + name = "gen-source", + srcs = ["ffi/lib.rs"], + cmd = "$(exe //:codegen) ${SRCS} > ${OUT}", + out = "gen.cc", +) diff --git a/tests/BUILD b/tests/BUILD new file mode 100644 index 00000000..a88cde5e --- /dev/null +++ b/tests/BUILD @@ -0,0 +1,51 @@ +load("//:build/rust.bzl", "rust_library", "rust_test") + +rust_test( + name = "test", + srcs = ["test.rs"], + deps = [":cxx_test_suite"], +) + +rust_library( + name = "cxx_test_suite", + srcs = ["ffi/lib.rs"], + deps = [ + ":impl", + "//:cxx", + ], +) + +cc_library( + name = "impl", + srcs = [ + "ffi/tests.cc", + ":gen-source", + ], + hdrs = ["ffi/tests.h"], + deps = [ + ":include", + "//:core", + ], +) + +genrule( + name = "gen-header", + srcs = ["ffi/lib.rs"], + outs = ["lib.rs"], + cmd = "$(location //:codegen) --header $< > $@", + tools = ["//:codegen"], +) + +genrule( + name = "gen-source", + srcs = ["ffi/lib.rs"], + outs = ["gen.cc"], + cmd = "$(location //:codegen) $< > $@", + tools = ["//:codegen"], +) + +cc_library( + name = "include", + hdrs = [":gen-header"], + include_prefix = "tests/ffi", +)