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

Specify consistent c++ standard between cxx and cxx-test-suite #268

Merged
merged 1 commit into from
Aug 29, 2020
Merged
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
10 changes: 6 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,18 @@ keywords = ["ffi"]
categories = ["development-tools::ffi", "api-bindings"]

[features]
default = [] # c++11
"c++14" = []
"c++17" = []
default = ["cxxbridge-flags/default"] # c++11
"c++14" = ["cxxbridge-flags/c++14"]
"c++17" = ["cxxbridge-flags/c++17"]
"c++20" = ["cxxbridge-flags/c++20"]

[dependencies]
cxxbridge-macro = { version = "=0.3.6", path = "macro" }
link-cplusplus = "1.0"

[build-dependencies]
cc = "1.0.49"
cxxbridge-flags = { version = "=0.3.6", path = "flags", default-features = false }

[dev-dependencies]
cxx-build = { version = "=0.3.6", path = "gen/build" }
Expand All @@ -32,7 +34,7 @@ rustversion = "1.0"
trybuild = { version = "1.0.33", features = ["diff"] }

[workspace]
members = ["demo-rs", "gen/build", "gen/cmd", "macro", "tests/ffi"]
members = ["demo-rs", "flags", "gen/build", "gen/cmd", "macro", "tests/ffi"]

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]
8 changes: 1 addition & 7 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,7 @@ fn main() {
.file("src/cxx.cc")
.cpp(true)
.cpp_link_stdlib(None) // linked via link-cplusplus crate
.flag_if_supported(if cfg!(feature = "c++17") {
"-std=c++17"
} else if cfg!(feature = "c++14") {
"-std=c++14"
} else {
"-std=c++11"
})
.flag_if_supported(cxxbridge_flags::STD)
.compile("cxxbridge03");
println!("cargo:rerun-if-changed=src/cxx.cc");
println!("cargo:rerun-if-changed=include/cxx.h");
Expand Down
17 changes: 17 additions & 0 deletions flags/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[package]
name = "cxxbridge-flags"
version = "0.3.6"
authors = ["David Tolnay <[email protected]>"]
edition = "2018"
license = "MIT OR Apache-2.0"
description = "Compiler configuration of the `cxx` crate (implementation detail)"
repository = "https://github.com/dtolnay/cxx"

[features]
default = [] # c++11
"c++14" = []
"c++17" = []
"c++20" = []

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]
20 changes: 20 additions & 0 deletions flags/src/impl.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#[allow(unused_assignments, unused_mut, unused_variables)]
pub const STD: &str = {
let mut flags = ["-std=c++11", "/std:c++11"];

#[cfg(feature = "c++14")]
(flags = ["-std=c++14", "/std:c++14"]);

#[cfg(feature = "c++17")]
(flags = ["-std=c++17", "/std:c++17"]);

#[cfg(feature = "c++20")]
(flags = ["-std=c++20", "/std:c++20"]);

let [mut flag, msvc_flag] = flags;

#[cfg(target_env = "msvc")]
(flag = msvc_flag);

flag
};
7 changes: 7 additions & 0 deletions flags/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//! This crate is an implementation detail of the `cxx` and `cxx-build` crates,
//! and does not expose any public API.

mod r#impl;

#[doc(hidden)]
pub use r#impl::*;
1 change: 1 addition & 0 deletions tests/ffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ cxx = { path = "../.." }

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

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