aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore4
-rw-r--r--.travis.yml11
-rw-r--r--BUILD63
-rw-r--r--WORKSPACE32
-rw-r--r--build/rust.bzl19
-rw-r--r--demo-cxx/BUILD16
-rw-r--r--demo-rs/BUILD43
-rw-r--r--third-party/BUILD249
8 files changed, 437 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index b403b1d4..e7499e5b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,8 @@
/.buckd
+/bazel-bin
+/bazel-cxx
+/bazel-out
+/bazel-testlogs
/buck-out
/Cargo.lock
/expand.cc
diff --git a/.travis.yml b/.travis.yml
index 6352e8d6..d1fc0883 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -25,3 +25,14 @@ matrix:
script:
- buck build :cxx#check --verbose=0
- buck run demo-rs --verbose=0
+ - name: Bazel
+ rust: nightly
+ before_install:
+ - wget -O install.sh https://github.com/bazelbuild/bazel/releases/download/2.1.1/bazel-2.1.1-installer-linux-x86_64.sh
+ - chmod +x install.sh
+ - ./install.sh --user
+ before_script:
+ - cp third-party/Cargo.lock .
+ - cargo vendor --versioned-dirs --locked third-party/vendor
+ script:
+ - bazel run demo-rs:demo_rs --verbose_failures --noshow_progress
diff --git a/BUILD b/BUILD
new file mode 100644
index 00000000..b48c9307
--- /dev/null
+++ b/BUILD
@@ -0,0 +1,63 @@
+load("//:build/rust.bzl", "rust_binary", "rust_library")
+
+rust_library(
+ name = "cxx",
+ srcs = glob(["src/**/*.rs"]),
+ data = ["src/gen/include/cxxbridge.h"],
+ visibility = ["//visibility:public"],
+ deps = [
+ ":core_lib",
+ ":cxxbridge_macro",
+ "//third-party:anyhow",
+ "//third-party:cc",
+ "//third-party:codespan",
+ "//third-party:codespan_reporting",
+ "//third-party:link_cplusplus",
+ "//third-party:proc_macro2",
+ "//third-party:quote",
+ "//third-party:syn",
+ "//third-party:thiserror",
+ ],
+)
+
+rust_binary(
+ name = "codegen",
+ srcs = glob(["cmd/src/**/*.rs"]),
+ data = ["cmd/src/gen/include/cxxbridge.h"],
+ visibility = ["//visibility:public"],
+ deps = [
+ "//third-party:anyhow",
+ "//third-party:codespan",
+ "//third-party:codespan_reporting",
+ "//third-party:proc_macro2",
+ "//third-party:quote",
+ "//third-party:structopt",
+ "//third-party:syn",
+ "//third-party:thiserror",
+ ],
+)
+
+cc_library(
+ name = "core",
+ hdrs = ["include/cxxbridge.h"],
+ include_prefix = "cxxbridge",
+ strip_include_prefix = "include",
+ visibility = ["//visibility:public"],
+)
+
+cc_library(
+ name = "core_lib",
+ srcs = ["src/cxxbridge.cc"],
+ hdrs = ["include/cxxbridge.h"],
+)
+
+rust_library(
+ name = "cxxbridge_macro",
+ srcs = glob(["macro/src/**"]),
+ crate_type = "proc-macro",
+ deps = [
+ "//third-party:proc_macro2",
+ "//third-party:quote",
+ "//third-party:syn",
+ ],
+)
diff --git a/WORKSPACE b/WORKSPACE
new file mode 100644
index 00000000..26866e80
--- /dev/null
+++ b/WORKSPACE
@@ -0,0 +1,32 @@
+load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
+
+http_archive(
+ name = "io_bazel_rules_rust",
+ sha256 = "3d3faa85e49ebf4d26c40075549a17739d636360064b94a9d481b37ace0add82",
+ strip_prefix = "rules_rust-6e87304c834c30b9c9f585cad19f30e7045281d7",
+ # Master branch as of 2020-02-22
+ url = "https://github.com/bazelbuild/rules_rust/archive/6e87304c834c30b9c9f585cad19f30e7045281d7.tar.gz",
+)
+
+http_archive(
+ name = "bazel_skylib",
+ sha256 = "97e70364e9249702246c0e9444bccdc4b847bed1eb03c5a3ece4f83dfe6abc44",
+ urls = [
+ "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.0.2/bazel-skylib-1.0.2.tar.gz",
+ "https://github.com/bazelbuild/bazel-skylib/releases/download/1.0.2/bazel-skylib-1.0.2.tar.gz",
+ ],
+)
+
+load("@io_bazel_rules_rust//:workspace.bzl", "bazel_version")
+
+bazel_version(name = "bazel_version")
+
+load("@io_bazel_rules_rust//rust:repositories.bzl", "rust_repository_set")
+
+rust_repository_set(
+ name = "rust_1_42_beta",
+ exec_triple = "x86_64-unknown-linux-gnu",
+ extra_target_triples = [],
+ iso_date = "2020-02-08",
+ version = "beta",
+)
diff --git a/build/rust.bzl b/build/rust.bzl
new file mode 100644
index 00000000..c2dade74
--- /dev/null
+++ b/build/rust.bzl
@@ -0,0 +1,19 @@
+load(
+ "@io_bazel_rules_rust//rust:rust.bzl",
+ _rust_binary = "rust_binary",
+ _rust_library = "rust_library",
+)
+
+def rust_binary(edition = "2018", **kwargs):
+ _rust_binary(edition = edition, **kwargs)
+
+def third_party_rust_binary(rustc_flags = [], **kwargs):
+ rustc_flags = rustc_flags + ["--cap-lints=allow"]
+ rust_binary(rustc_flags = rustc_flags, **kwargs)
+
+def rust_library(edition = "2018", **kwargs):
+ _rust_library(edition = edition, **kwargs)
+
+def third_party_rust_library(rustc_flags = [], **kwargs):
+ rustc_flags = rustc_flags + ["--cap-lints=allow"]
+ rust_library(rustc_flags = rustc_flags, **kwargs)
diff --git a/demo-cxx/BUILD b/demo-cxx/BUILD
new file mode 100644
index 00000000..da97cfab
--- /dev/null
+++ b/demo-cxx/BUILD
@@ -0,0 +1,16 @@
+cc_library(
+ name = "demo-cxx",
+ srcs = ["demo.cc"],
+ visibility = ["//visibility:public"],
+ deps = [
+ ":include",
+ "//demo-rs:include",
+ ],
+)
+
+cc_library(
+ name = "include",
+ hdrs = ["demo.h"],
+ visibility = ["//visibility:public"],
+ deps = ["//:core"],
+)
diff --git a/demo-rs/BUILD b/demo-rs/BUILD
new file mode 100644
index 00000000..fb781b64
--- /dev/null
+++ b/demo-rs/BUILD
@@ -0,0 +1,43 @@
+load("//:build/rust.bzl", "rust_binary", "rust_library")
+
+rust_binary(
+ name = "demo_rs",
+ srcs = glob(["src/**"]),
+ deps = [
+ ":gen",
+ "//:cxx",
+ "//demo-cxx",
+ ],
+)
+
+cc_library(
+ name = "gen",
+ srcs = [":gen-source"],
+ deps = [
+ ":include",
+ "//demo-cxx:include",
+ ],
+)
+
+genrule(
+ name = "gen-header",
+ srcs = ["src/main.rs"],
+ outs = ["main.rs"],
+ cmd = "$(location //:codegen) --header $< > $@",
+ tools = ["//:codegen"],
+)
+
+genrule(
+ name = "gen-source",
+ srcs = ["src/main.rs"],
+ outs = ["gen-demo.cc"],
+ cmd = "$(location //:codegen) $< > $@",
+ tools = ["//:codegen"],
+)
+
+cc_library(
+ name = "include",
+ hdrs = [":gen-header"],
+ include_prefix = "demo-rs/src",
+ visibility = ["//visibility:public"],
+)
diff --git a/third-party/BUILD b/third-party/BUILD
new file mode 100644
index 00000000..11b4257f
--- /dev/null
+++ b/third-party/BUILD
@@ -0,0 +1,249 @@
+load(
+ "//:build/rust.bzl",
+ rust_binary = "third_party_rust_binary",
+ rust_library = "third_party_rust_library",
+)
+load("@bazel_tools//tools/build_defs/pkg:pkg.bzl", "pkg_tar")
+
+rust_library(
+ name = "anyhow",
+ srcs = glob(["vendor/anyhow-1.0.26/src/**"]),
+ crate_features = ["std"],
+ visibility = ["//visibility:public"],
+)
+
+rust_library(
+ name = "bitflags",
+ srcs = glob(["vendor/bitflags-1.2.1/src/**"]),
+)
+
+rust_library(
+ name = "cc",
+ srcs = glob(["vendor/cc-1.0.50/src/**"]),
+ visibility = ["//visibility:public"],
+)
+
+rust_library(
+ name = "clap",
+ srcs = glob(["vendor/clap-2.33.0/src/**"]),
+ edition = "2015",
+ deps = [
+ ":bitflags",
+ ":textwrap",
+ ":unicode_width",
+ ],
+)
+
+rust_library(
+ name = "codespan",
+ srcs = glob(["vendor/codespan-0.7.0/src/**"]),
+ visibility = ["//visibility:public"],
+ deps = [":unicode_segmentation"],
+)
+
+rust_library(
+ name = "codespan_reporting",
+ srcs = glob(["vendor/codespan-reporting-0.7.0/src/**"]),
+ visibility = ["//visibility:public"],
+ deps = [
+ ":codespan",
+ ":termcolor",
+ ":unicode_width",
+ ],
+)
+
+rust_library(
+ name = "heck",
+ srcs = glob(["vendor/heck-0.3.1/src/**"]),
+ edition = "2015",
+ deps = [":unicode_segmentation"],
+)
+
+rust_library(
+ name = "lazy_static",
+ srcs = glob(["vendor/lazy_static-1.4.0/src/**"]),
+)
+
+rust_library(
+ name = "link_cplusplus",
+ srcs = glob(["vendor/link-cplusplus-1.0.1/src/**"]),
+ visibility = ["//visibility:public"],
+)
+
+rust_library(
+ name = "proc_macro_error",
+ srcs = glob(["vendor/proc-macro-error-0.4.9/src/**"]),
+ rustc_flags = ["--cfg=use_fallback"],
+ deps = [
+ ":proc_macro2",
+ ":proc_macro_error_attr",
+ ":quote",
+ ":syn",
+ ],
+)
+
+rust_library(
+ name = "proc_macro_error_attr",
+ srcs = glob(["vendor/proc-macro-error-attr-0.4.9/src/**"]),
+ crate_type = "proc-macro",
+ deps = [
+ ":proc_macro2",
+ ":quote",
+ ":rustversion",
+ ":syn",
+ ":syn_mid",
+ ],
+)
+
+rust_library(
+ name = "proc_macro2",
+ srcs = glob(["vendor/proc-macro2-1.0.8/src/**"]),
+ crate_features = [
+ "proc-macro",
+ "span-locations",
+ ],
+ rustc_flags = [
+ "--cfg=span_locations",
+ "--cfg=use_proc_macro",
+ "--cfg=wrap_proc_macro",
+ ],
+ visibility = ["//visibility:public"],
+ deps = [":unicode_xid"],
+)
+
+rust_library(
+ name = "quote",
+ srcs = glob(["vendor/quote-1.0.2/src/**"]),
+ crate_features = ["proc-macro"],
+ visibility = ["//visibility:public"],
+ deps = [":proc_macro2"],
+)
+
+rust_library(
+ name = "rustversion",
+ srcs = glob(["vendor/rustversion-1.0.2/src/**"]),
+ crate_type = "proc-macro",
+ out_dir_tar = ":rustversion_buildscript_outdir",
+ deps = [
+ ":proc_macro2",
+ ":quote",
+ ":syn",
+ ],
+)
+
+rust_binary(
+ name = "rustversion_buildscript",
+ srcs = glob(["vendor/rustversion-1.0.2/build/**"]),
+ crate_root = "vendor/rustversion-1.0.2/build/build.rs",
+)
+
+pkg_tar(
+ name = "rustversion_buildscript_outdir",
+ srcs = [":rustversion_buildscript_run"],
+ extension = "tar.gz",
+)
+
+genrule(
+ name = "rustversion_buildscript_run",
+ outs = ["version.rs"],
+ cmd = "OUT_DIR=$(@D) $(location :rustversion_buildscript)",
+ tools = [":rustversion_buildscript"],
+)
+
+rust_library(
+ name = "structopt",
+ srcs = glob(["vendor/structopt-0.3.9/src/**"]),
+ visibility = ["//visibility:public"],
+ deps = [
+ ":clap",
+ ":lazy_static",
+ ":structopt_derive",
+ ],
+)
+
+rust_library(
+ name = "structopt_derive",
+ srcs = glob(["vendor/structopt-derive-0.4.2/src/**"]),
+ crate_type = "proc-macro",
+ deps = [
+ ":heck",
+ ":proc_macro2",
+ ":proc_macro_error",
+ ":quote",
+ ":syn",
+ ],
+)
+
+rust_library(
+ name = "syn",
+ srcs = glob(["vendor/syn-1.0.14/src/**"]),
+ crate_features = [
+ "clone-impls",
+ "derive",
+ "full",
+ "parsing",
+ "printing",
+ "proc-macro",
+ ],
+ visibility = ["//visibility:public"],
+ deps = [
+ ":proc_macro2",
+ ":quote",
+ ":unicode_xid",
+ ],
+)
+
+rust_library(
+ name = "syn_mid",
+ srcs = glob(["vendor/syn-mid-0.5.0/src/**"]),
+ deps = [
+ ":proc_macro2",
+ ":quote",
+ ":syn",
+ ],
+)
+
+rust_library(
+ name = "termcolor",
+ srcs = glob(["vendor/termcolor-1.1.0/src/**"]),
+)
+
+rust_library(
+ name = "textwrap",
+ srcs = glob(["vendor/textwrap-0.11.0/src/**"]),
+ deps = [":unicode_width"],
+)
+
+rust_library(
+ name = "thiserror",
+ srcs = glob(["vendor/thiserror-1.0.11/src/**"]),
+ visibility = ["//visibility:public"],
+ deps = [":thiserror_impl"],
+)
+
+rust_library(
+ name = "thiserror_impl",
+ srcs = glob(["vendor/thiserror-impl-1.0.11/src/**"]),
+ crate_type = "proc-macro",
+ deps = [
+ ":proc_macro2",
+ ":quote",
+ ":syn",
+ ],
+)
+
+rust_library(
+ name = "unicode_segmentation",
+ srcs = glob(["vendor/unicode-segmentation-1.6.0/src/**"]),
+ edition = "2015",
+)
+
+rust_library(
+ name = "unicode_width",
+ srcs = glob(["vendor/unicode-width-0.1.7/src/**"]),
+)
+
+rust_library(
+ name = "unicode_xid",
+ srcs = glob(["vendor/unicode-xid-0.2.0/src/**"]),
+)