Skip to content

Commit

Permalink
Merge pull request #1322 from dtolnay/std
Browse files Browse the repository at this point in the history
Set C++ standard version using cc::Build::std
  • Loading branch information
dtolnay authored Mar 6, 2024
2 parents 04b3a75 + afb4d75 commit 3930a42
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ cxxbridge-macro = { version = "=1.0.118", path = "macro" }
link-cplusplus = "1.0.9"

[build-dependencies]
cc = "1.0.79"
cc = "1.0.83"
cxxbridge-flags = { version = "=1.0.118", path = "flags", default-features = false }

[dev-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ fn main() {
.file(manifest_dir.join("src/cxx.cc"))
.cpp(true)
.cpp_link_stdlib(None) // linked via link-cplusplus crate
.flag_if_supported(cxxbridge_flags::STD)
.std(cxxbridge_flags::STD)
.warnings_into_errors(cfg!(deny_warnings))
.compile("cxxbridge1");

Expand Down
13 changes: 4 additions & 9 deletions flags/src/impl.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
#[allow(unused_assignments, unused_mut, unused_variables)]
pub const STD: &str = {
let mut flags = ["-std=c++11", "/std:c++11"];
let mut flag = "c++11";

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

#[cfg(feature = "c++17")]
(flags = ["-std=c++17", "/std:c++17"]);
(flag = "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 = "c++20");

flag
};
2 changes: 2 additions & 0 deletions flags/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
//! This crate is an implementation detail of the `cxx` and `cxx-build` crates,
//! and does not expose any public API.
#![allow(clippy::let_and_return)]

mod r#impl;

#[doc(hidden)]
Expand Down
2 changes: 1 addition & 1 deletion gen/build/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ parallel = ["cc/parallel"]
experimental-async-fn = []

[dependencies]
cc = "1.0.79"
cc = "1.0.83"
codespan-reporting = "0.11.1"
once_cell = "1.18"
proc-macro2 = { version = "1.0.74", default-features = false, features = ["span-locations"] }
Expand Down
2 changes: 1 addition & 1 deletion tests/ffi/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ fn main() {
let sources = vec!["lib.rs", "module.rs"];
let mut build = cxx_build::bridges(sources);
build.file("tests.cc");
build.flag_if_supported(cxxbridge_flags::STD);
build.std(cxxbridge_flags::STD);
build.warnings_into_errors(cfg!(deny_warnings));
if cfg!(not(target_env = "msvc")) {
build.define("CXX_TEST_INSTANTIATIONS", None);
Expand Down
2 changes: 1 addition & 1 deletion third-party/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ publish = false
path = "/dev/null"

[dependencies]
cc = "1.0.49"
cc = "1.0.83"
clap = { version = "4", default-features = false, features = ["error-context", "help", "std", "usage"] }
codespan-reporting = "0.11.1"
once_cell = "1.9"
Expand Down

0 comments on commit 3930a42

Please sign in to comment.