mirror of
https://gitee.com/openharmony/third_party_rust_cxx
synced 2024-11-23 07:10:29 +00:00
Specify consistent c++ standard between cxx and cxx-test-suite
This commit is contained in:
parent
907debe8b4
commit
de1cb777b2
10
Cargo.toml
10
Cargo.toml
@ -14,9 +14,10 @@ keywords = ["ffi"]
|
|||||||
categories = ["development-tools::ffi", "api-bindings"]
|
categories = ["development-tools::ffi", "api-bindings"]
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = [] # c++11
|
default = ["cxxbridge-flags/default"] # c++11
|
||||||
"c++14" = []
|
"c++14" = ["cxxbridge-flags/c++14"]
|
||||||
"c++17" = []
|
"c++17" = ["cxxbridge-flags/c++17"]
|
||||||
|
"c++20" = ["cxxbridge-flags/c++20"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
cxxbridge-macro = { version = "=0.3.6", path = "macro" }
|
cxxbridge-macro = { version = "=0.3.6", path = "macro" }
|
||||||
@ -24,6 +25,7 @@ link-cplusplus = "1.0"
|
|||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
cc = "1.0.49"
|
cc = "1.0.49"
|
||||||
|
cxxbridge-flags = { version = "=0.3.6", path = "flags", default-features = false }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
cxx-build = { version = "=0.3.6", path = "gen/build" }
|
cxx-build = { version = "=0.3.6", path = "gen/build" }
|
||||||
@ -32,7 +34,7 @@ rustversion = "1.0"
|
|||||||
trybuild = { version = "1.0.33", features = ["diff"] }
|
trybuild = { version = "1.0.33", features = ["diff"] }
|
||||||
|
|
||||||
[workspace]
|
[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]
|
[package.metadata.docs.rs]
|
||||||
targets = ["x86_64-unknown-linux-gnu"]
|
targets = ["x86_64-unknown-linux-gnu"]
|
||||||
|
8
build.rs
8
build.rs
@ -3,13 +3,7 @@ fn main() {
|
|||||||
.file("src/cxx.cc")
|
.file("src/cxx.cc")
|
||||||
.cpp(true)
|
.cpp(true)
|
||||||
.cpp_link_stdlib(None) // linked via link-cplusplus crate
|
.cpp_link_stdlib(None) // linked via link-cplusplus crate
|
||||||
.flag_if_supported(if cfg!(feature = "c++17") {
|
.flag_if_supported(cxxbridge_flags::STD)
|
||||||
"-std=c++17"
|
|
||||||
} else if cfg!(feature = "c++14") {
|
|
||||||
"-std=c++14"
|
|
||||||
} else {
|
|
||||||
"-std=c++11"
|
|
||||||
})
|
|
||||||
.compile("cxxbridge03");
|
.compile("cxxbridge03");
|
||||||
println!("cargo:rerun-if-changed=src/cxx.cc");
|
println!("cargo:rerun-if-changed=src/cxx.cc");
|
||||||
println!("cargo:rerun-if-changed=include/cxx.h");
|
println!("cargo:rerun-if-changed=include/cxx.h");
|
||||||
|
17
flags/Cargo.toml
Normal file
17
flags/Cargo.toml
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
[package]
|
||||||
|
name = "cxxbridge-flags"
|
||||||
|
version = "0.3.6"
|
||||||
|
authors = ["David Tolnay <dtolnay@gmail.com>"]
|
||||||
|
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
flags/src/impl.rs
Normal file
20
flags/src/impl.rs
Normal file
@ -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
flags/src/lib.rs
Normal file
7
flags/src/lib.rs
Normal file
@ -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::*;
|
@ -12,3 +12,4 @@ cxx = { path = "../.." }
|
|||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
cxx-build = { path = "../../gen/build" }
|
cxx-build = { path = "../../gen/build" }
|
||||||
|
cxxbridge-flags = { path = "../../flags" }
|
||||||
|
@ -6,6 +6,6 @@ fn main() {
|
|||||||
let sources = vec!["lib.rs", "module.rs"];
|
let sources = vec!["lib.rs", "module.rs"];
|
||||||
cxx_build::bridges(sources)
|
cxx_build::bridges(sources)
|
||||||
.file("tests.cc")
|
.file("tests.cc")
|
||||||
.flag_if_supported("-std=c++11")
|
.flag_if_supported(cxxbridge_flags::STD)
|
||||||
.compile("cxx-test-suite");
|
.compile("cxx-test-suite");
|
||||||
}
|
}
|
||||||
|
6
third-party/Cargo.lock
generated
vendored
6
third-party/Cargo.lock
generated
vendored
@ -70,6 +70,7 @@ dependencies = [
|
|||||||
"cc",
|
"cc",
|
||||||
"cxx-build",
|
"cxx-build",
|
||||||
"cxx-test-suite",
|
"cxx-test-suite",
|
||||||
|
"cxxbridge-flags",
|
||||||
"cxxbridge-macro",
|
"cxxbridge-macro",
|
||||||
"link-cplusplus",
|
"link-cplusplus",
|
||||||
"rustversion",
|
"rustversion",
|
||||||
@ -94,6 +95,7 @@ version = "0.0.0"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"cxx",
|
"cxx",
|
||||||
"cxx-build",
|
"cxx-build",
|
||||||
|
"cxxbridge-flags",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -116,6 +118,10 @@ dependencies = [
|
|||||||
"cxx-build",
|
"cxx-build",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cxxbridge-flags"
|
||||||
|
version = "0.3.6"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cxxbridge-macro"
|
name = "cxxbridge-macro"
|
||||||
version = "0.3.6"
|
version = "0.3.6"
|
||||||
|
Loading…
Reference in New Issue
Block a user