Combine demo into one root directory

This commit is contained in:
David Tolnay 2020-09-01 15:51:38 -07:00
parent 7273963a61
commit 37531b477e
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82
10 changed files with 49 additions and 53 deletions

View File

@ -9,7 +9,7 @@ description = "Safe interop between Rust and C++"
repository = "https://github.com/dtolnay/cxx"
documentation = "https://docs.rs/cxx"
readme = "README.md"
exclude = ["/demo-cxx", "/gen", "/syntax", "/third-party"]
exclude = ["/demo", "/gen", "/syntax", "/third-party"]
keywords = ["ffi"]
categories = ["development-tools::ffi", "api-bindings"]
@ -34,7 +34,7 @@ rustversion = "1.0"
trybuild = { version = "1.0.33", features = ["diff"] }
[workspace]
members = ["demo-rs", "flags", "gen/build", "gen/cmd", "gen/lib", "macro", "tests/ffi"]
members = ["demo", "flags", "gen/build", "gen/cmd", "gen/lib", "macro", "tests/ffi"]
[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]

View File

@ -1,17 +0,0 @@
cxx_library(
name = "demo-cxx",
srcs = ["demo.cc"],
compiler_flags = ["-std=c++14"],
visibility = ["PUBLIC"],
deps = [
":include",
"//demo-rs:include",
],
)
cxx_library(
name = "include",
exported_headers = ["demo.h"],
visibility = ["PUBLIC"],
deps = ["//:core"],
)

View File

@ -1,17 +0,0 @@
cc_library(
name = "demo-cxx",
srcs = ["demo.cc"],
copts = ["-std=c++14"],
visibility = ["//visibility:public"],
deps = [
":include",
"//demo-rs:include",
],
)
cc_library(
name = "include",
hdrs = ["demo.h"],
visibility = ["//visibility:public"],
deps = ["//:core"],
)

View File

@ -1,10 +1,10 @@
rust_binary(
name = "demo-rs",
srcs = glob(["src/**"]),
name = "demo",
srcs = glob(["src/**/*.rs"]),
deps = [
":demo-sys",
":gen",
"//:cxx",
"//demo-cxx:demo-cxx",
],
)
@ -12,8 +12,8 @@ cxx_library(
name = "gen",
srcs = [":gen-source"],
deps = [
":demo-include",
":include",
"//demo-cxx:include",
],
)
@ -38,5 +38,20 @@ cxx_library(
exported_headers = {
"src/main.rs.h": ":gen-header",
},
visibility = ["PUBLIC"],
)
cxx_library(
name = "demo-sys",
srcs = ["src/demo.cc"],
compiler_flags = ["-std=c++14"],
deps = [
":demo-include",
":include",
],
)
cxx_library(
name = "demo-include",
exported_headers = ["include/demo.h"],
deps = ["//:core"],
)

View File

@ -1,12 +1,12 @@
load("//tools/bazel:rust.bzl", "rust_binary", "rust_library")
rust_binary(
name = "demo-rs",
srcs = glob(["src/**"]),
name = "demo",
srcs = glob(["src/**/*.rs"]),
deps = [
":demo-sys",
":gen",
"//:cxx",
"//demo-cxx",
],
)
@ -14,8 +14,8 @@ cc_library(
name = "gen",
srcs = [":gen-source"],
deps = [
":demo-include",
":include",
"//demo-cxx:include",
],
)
@ -38,6 +38,21 @@ genrule(
cc_library(
name = "include",
hdrs = [":gen-header"],
include_prefix = "demo-rs/src",
visibility = ["//visibility:public"],
include_prefix = "demo/src",
)
cc_library(
name = "demo-sys",
srcs = ["src/demo.cc"],
copts = ["-std=c++14"],
deps = [
":demo-include",
":include",
],
)
cc_library(
name = "demo-include",
hdrs = ["include/demo.h"],
deps = ["//:core"],
)

View File

@ -1,10 +1,10 @@
fn main() {
cxx_build::bridge("src/main.rs")
.file("../demo-cxx/demo.cc")
.file("src/demo.cc")
.flag_if_supported("-std=c++14")
.compile("cxxbridge-demo");
println!("cargo:rerun-if-changed=src/main.rs");
println!("cargo:rerun-if-changed=../demo-cxx/demo.h");
println!("cargo:rerun-if-changed=../demo-cxx/demo.cc");
println!("cargo:rerun-if-changed=src/demo.cc");
println!("cargo:rerun-if-changed=include/demo.h");
}

View File

@ -1,5 +1,5 @@
#include "demo-cxx/demo.h"
#include "demo-rs/src/main.rs.h"
#include "demo/include/demo.h"
#include "demo/src/main.rs.h"
#include <iostream>
namespace org {

View File

@ -7,7 +7,7 @@ mod ffi {
}
extern "C" {
include!("demo-cxx/demo.h");
include!("demo/include/demo.h");
type ThingC;
fn make_demo(appname: &str) -> UniquePtr<ThingC>;