Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cxxbuild set std.upstream #1

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ rust_library(
],
)

rust_library(
name = "cxxbridge-flags",
srcs = glob(["flags/src/*.rs"]),
)

rust_library(
name = "build",
srcs = glob(["gen/build/src/**/*.rs"]),
Expand All @@ -61,6 +66,7 @@ rust_library(
"//third-party:proc-macro2",
"//third-party:quote",
"//third-party:syn",
"//:cxxbridge-flags",
],
)

Expand Down
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,11 @@ For builds that are orchestrated by Cargo, you will use a build script that runs
CXX's C++ code generator and compiles the resulting C++ code along with any
other C++ code for your crate.

CXX create features, such as support of a different C++ standard, are
automatically set if using cxx_build. This ensures that your code gets
compiled with the same feature flags as the CXX bridge library code in
cxx.h|cc. See the CXX crate for available features.

The canonical build script is as follows. The indicated line returns a
[`cc::Build`] instance (from the usual widely used `cc` crate) on which you can
set up any additional source files and compiler flags as normal.
Expand All @@ -221,6 +226,11 @@ set up any additional source files and compiler flags as normal.
```toml
# Cargo.toml

[dependencies]
cxx = "0.4"
# To pick a different C++ standard:
# cxx = { version = "0.4", features = ["c++14"] }

[build-dependencies]
cxx-build = "0.4"
```
Expand All @@ -231,7 +241,6 @@ cxx-build = "0.4"
fn main() {
cxx_build::bridge("src/main.rs") // returns a cc::Build
.file("src/demo.cc")
.flag_if_supported("-std=c++11")
.compile("cxxbridge-demo");

println!("cargo:rerun-if-changed=src/main.rs");
Expand Down
3 changes: 2 additions & 1 deletion demo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ edition = "2018"
publish = false

[dependencies]
cxx = { path = ".." }
cxx = { path = "..", features= ["c++14"] }

[build-dependencies]
cxx-build = { path = "../gen/build" }

1 change: 0 additions & 1 deletion demo/build.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
fn main() {
cxx_build::bridge("src/main.rs")
.file("src/demo.cc")
.flag_if_supported("-std=c++14")
.compile("cxxbridge-demo");

println!("cargo:rerun-if-changed=src/main.rs");
Expand Down
1 change: 1 addition & 0 deletions gen/build/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ codespan-reporting = "0.9"
proc-macro2 = { version = "1.0.17", default-features = false, features = ["span-locations"] }
quote = { version = "1.0", default-features = false }
syn = { version = "1.0.20", default-features = false, features = ["parsing", "printing", "clone-impls", "full"] }
cxxbridge-flags = { version = "=0.4.7", path = "../../flags", default-features = false }

[dev-dependencies]
cxx-gen = { version = "0.4", path = "../lib" }
Expand Down
9 changes: 7 additions & 2 deletions gen/build/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
//! C++ code generator, set up any additional compiler flags depending on
//! the use case, and make the C++ compiler invocation.
//!
//! CXX create features, such as support of a different C++ standard, are
//! automatically set if using cxx_build. This ensures that your code gets
//! compiled with the same feature flags as the CXX bridge library code in
//! cxx.h|cc. See the CXX crate for available features.
//!
//! <br>
//!
//! # Example
Expand All @@ -16,7 +21,6 @@
//! fn main() {
//! cxx_build::bridge("src/main.rs")
//! .file("src/demo.cc")
//! .flag_if_supported("-std=c++11")
//! .compile("cxxbridge-demo");
//!
//! println!("cargo:rerun-if-changed=src/main.rs");
Expand Down Expand Up @@ -87,7 +91,6 @@ pub fn bridge(rust_source_file: impl AsRef<Path>) -> Build {
/// let source_files = vec!["src/main.rs", "src/path/to/other.rs"];
/// cxx_build::bridges(source_files)
/// .file("src/demo.cc")
/// .flag_if_supported("-std=c++11")
/// .compile("cxxbridge-demo");
/// ```
#[must_use]
Expand Down Expand Up @@ -129,6 +132,8 @@ fn build(rust_source_files: &mut dyn Iterator<Item = impl AsRef<Path>>) -> Resul
build.cpp(true);
build.cpp_link_stdlib(None); // linked via link-cplusplus crate
build.include(&include_dir);
// Set feature parameters, such as C++ std, for simpler usage
build.flag_if_supported(cxxbridge_flags::STD);
write_header(prj);
let crate_dir = symlink_crate(prj, &mut build);

Expand Down
11 changes: 10 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,11 @@
//! runs CXX's C++ code generator and compiles the resulting C++ code along with
//! any other C++ code for your crate.
//!
//! CXX create features, such as support of a different C++ standard, are
//! automatically set if using cxx_build. This ensures that your code gets
//! compiled with the same feature flags as the CXX bridge library code in
//! cxx.h|cc. See the CXX crate for available features.
//!
//! The canonical build script is as follows. The indicated line returns a
//! [`cc::Build`] instance (from the usual widely used `cc` crate) on which you
//! can set up any additional source files and compiler flags as normal.
Expand All @@ -227,6 +232,11 @@
//! ```toml
//! # Cargo.toml
//!
//! [dependencies]
//! cxx = "0.4"
//! # To pick a different C++ standard:
//! # cxx = { version = "0.4", features = ["c++14"] }
//!
//! [build-dependencies]
//! cxx-build = "0.4"
//! ```
Expand All @@ -237,7 +247,6 @@
//! fn main() {
//! cxx_build::bridge("src/main.rs") // returns a cc::Build
//! .file("src/demo.cc")
//! .flag_if_supported("-std=c++11")
//! .compile("cxxbridge-demo");
//!
//! println!("cargo:rerun-if-changed=src/main.rs");
Expand Down
1 change: 0 additions & 1 deletion tests/ffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,3 @@ cxx = { path = "../.." }

[build-dependencies]
cxx-build = { path = "../../gen/build" }
cxxbridge-flags = { path = "../../flags" }
1 change: 0 additions & 1 deletion tests/ffi/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@ fn main() {
let sources = vec!["lib.rs", "module.rs"];
cxx_build::bridges(sources)
.file("tests.cc")
.flag_if_supported(cxxbridge_flags::STD)
.compile("cxx-test-suite");
}
2 changes: 1 addition & 1 deletion third-party/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.