diff --git a/.bazelrc b/.bazelrc index 6ffa81e54..5e3ff76a0 100644 --- a/.bazelrc +++ b/.bazelrc @@ -1 +1,2 @@ -build --@rules_rust//:extra_rustc_flags=-Clink-arg=-fuse-ld=lld +build --enable_platform_specific_config +build:linux --@rules_rust//:extra_rustc_flags=-Clink-arg=-fuse-ld=lld diff --git a/.buckconfig b/.buckconfig index 5c6c995ad..570a844eb 100644 --- a/.buckconfig +++ b/.buckconfig @@ -13,7 +13,7 @@ cxxflags = -std=c++11 [rust] - default_edition = 2018 + default_edition = required rustc_flags = \ -Clink-arg=-fuse-ld=lld \ -Crelocation-model=dynamic-no-pic \ diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d934ced98..a1c49fac1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,14 +16,11 @@ jobs: - rust: nightly - rust: beta - rust: stable - - rust: 1.54.0 + - rust: 1.56.1 - rust: 1.48.0 - name: macOS rust: nightly os: macos - - name: Windows (gnu) - rust: nightly-x86_64-pc-windows-gnu - os: windows - name: Windows (msvc) rust: nightly-x86_64-pc-windows-msvc os: windows @@ -35,7 +32,7 @@ jobs: - name: Enable symlinks (windows) if: matrix.os == 'windows' run: git config --global core.symlinks true - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - uses: dtolnay/rust-toolchain@master with: toolchain: ${{matrix.rust}} @@ -67,7 +64,7 @@ jobs: runs-on: ubuntu-latest if: github.event_name != 'pull_request' steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - uses: dtolnay/rust-toolchain@stable - uses: actions/setup-java@v1 with: @@ -94,10 +91,10 @@ jobs: runs-on: ubuntu-latest if: github.event_name != 'pull_request' steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Install Bazel run: | - wget -q -O install.sh https://github.com/bazelbuild/bazel/releases/download/4.2.2/bazel-4.2.2-installer-linux-x86_64.sh + wget -q -O install.sh https://github.com/bazelbuild/bazel/releases/download/5.1.1/bazel-5.1.1-installer-linux-x86_64.sh chmod +x install.sh ./install.sh --user echo $HOME/bin >> $GITHUB_PATH @@ -111,7 +108,7 @@ jobs: runs-on: ubuntu-latest if: github.event_name != 'pull_request' steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - uses: dtolnay/rust-toolchain@clippy - run: cargo clippy --workspace --tests -- -Dclippy::all @@ -120,7 +117,7 @@ jobs: runs-on: ubuntu-latest if: github.event_name != 'pull_request' steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Install clang-tidy run: sudo apt-get install clang-tidy-11 - name: Run clang-tidy @@ -131,6 +128,6 @@ jobs: runs-on: ubuntu-latest if: github.event_name != 'pull_request' steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - uses: dtolnay/install@cargo-outdated - - run: cargo outdated --exit-code 1 + - run: cargo outdated --workspace --exit-code 1 diff --git a/.github/workflows/site.yml b/.github/workflows/site.yml index d6b0ca6d0..e5f4ac473 100644 --- a/.github/workflows/site.yml +++ b/.github/workflows/site.yml @@ -12,8 +12,10 @@ jobs: deploy: name: Deploy runs-on: ubuntu-latest + permissions: + contents: write steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Get mdBook run: | diff --git a/BUCK b/BUCK index ff61bfd95..d8cf619ec 100644 --- a/BUCK +++ b/BUCK @@ -1,6 +1,7 @@ rust_library( name = "cxx", srcs = glob(["src/**"]), + edition = "2018", features = [ "alloc", "std", @@ -16,6 +17,7 @@ rust_binary( name = "codegen", srcs = glob(["gen/cmd/src/**"]), crate = "cxxbridge", + edition = "2018", visibility = ["PUBLIC"], deps = [ "//third-party:clap", @@ -41,6 +43,7 @@ rust_library( name = "macro", srcs = glob(["macro/src/**"]), crate = "cxxbridge_macro", + edition = "2018", proc_macro = True, deps = [ "//third-party:proc-macro2", @@ -52,6 +55,7 @@ rust_library( rust_library( name = "build", srcs = glob(["gen/build/src/**"]), + edition = "2018", visibility = ["PUBLIC"], deps = [ "//third-party:cc", @@ -67,6 +71,7 @@ rust_library( rust_library( name = "lib", srcs = glob(["gen/lib/src/**"]), + edition = "2018", visibility = ["PUBLIC"], deps = [ "//third-party:cc", diff --git a/BUILD b/BUILD index 43a1a5872..4a46cb530 100644 --- a/BUILD +++ b/BUILD @@ -8,6 +8,7 @@ rust_library( "alloc", "std", ], + edition = "2018", proc_macro_deps = [ ":cxxbridge-macro", ], @@ -19,6 +20,7 @@ rust_binary( name = "codegen", srcs = glob(["gen/cmd/src/**/*.rs"]), data = ["gen/cmd/src/gen/include/cxx.h"], + edition = "2018", visibility = ["//visibility:public"], deps = [ "//third-party:clap", @@ -46,6 +48,7 @@ cc_library( rust_proc_macro( name = "cxxbridge-macro", srcs = glob(["macro/src/**"]), + edition = "2018", deps = [ "//third-party:proc-macro2", "//third-party:quote", @@ -57,6 +60,7 @@ rust_library( name = "build", srcs = glob(["gen/build/src/**/*.rs"]), data = ["gen/build/src/gen/include/cxx.h"], + edition = "2018", visibility = ["//visibility:public"], deps = [ "//third-party:cc", @@ -73,6 +77,7 @@ rust_library( name = "lib", srcs = glob(["gen/lib/src/**/*.rs"]), data = ["gen/lib/src/gen/include/cxx.h"], + edition = "2018", visibility = ["//visibility:public"], deps = [ "//third-party:cc", diff --git a/Cargo.toml b/Cargo.toml index 420501583..76dd885a3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cxx" -version = "1.0.63" # remember to update html_root_url +version = "1.0.71" # remember to update html_root_url authors = ["David Tolnay "] edition = "2018" rust-version = "1.48" @@ -24,15 +24,15 @@ alloc = [] std = ["alloc"] [dependencies] -cxxbridge-macro = { version = "=1.0.63", path = "macro" } +cxxbridge-macro = { version = "=1.0.71", path = "macro" } link-cplusplus = "1.0" [build-dependencies] cc = "1.0.49" -cxxbridge-flags = { version = "=1.0.63", path = "flags", default-features = false } +cxxbridge-flags = { version = "=1.0.71", path = "flags", default-features = false } [dev-dependencies] -cxx-build = { version = "=1.0.63", path = "gen/build" } +cxx-build = { version = "=1.0.71", path = "gen/build" } cxx-gen = { version = "0.7", path = "gen/lib" } cxx-test-suite = { version = "0", path = "tests/ffi" } rustversion = "1.0" diff --git a/README.md b/README.md index 7dd4ded91..d00d8ac91 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ CXX — safe FFI between Rust and C++ [github](https://github.com/dtolnay/cxx) [crates.io](https://crates.io/crates/cxx) -[docs.rs](https://docs.rs/cxx) +[docs.rs](https://docs.rs/cxx) [build status](https://github.com/dtolnay/cxx/actions?query=branch%3Amaster) This library provides a **safe** mechanism for calling C++ code from Rust and diff --git a/WORKSPACE b/WORKSPACE index fba62aa36..793bf14d1 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -4,20 +4,21 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") http_archive( name = "rules_rust", - sha256 = "29fee78077bd8c6477bc895a47e6c759f92df0735ed60587e1da7b51f53d26eb", - strip_prefix = "rules_rust-23a4631cad819003642b1a148e458fe4ed2c54e1", + sha256 = "617082067629939c0a22f587811a3e822a50a203119a90380e21f5aec3373da9", + strip_prefix = "rules_rust-e07881fa22a5f0d16230d8b23bbff2bf358823b8", urls = [ - # Main branch as of 2021-12-07 - "https://github.com/bazelbuild/rules_rust/archive/23a4631cad819003642b1a148e458fe4ed2c54e1.tar.gz", + # Main branch as of 2022-04-27 + "https://github.com/bazelbuild/rules_rust/archive/e07881fa22a5f0d16230d8b23bbff2bf358823b8.tar.gz", ], ) -load("@rules_rust//rust:repositories.bzl", "rust_repositories") +load("@rules_rust//rust:repositories.bzl", "rules_rust_dependencies", "rust_register_toolchains") -RUST_VERSION = "1.57.0" +RUST_VERSION = "1.60.0" -rust_repositories( - edition = "2018", +rules_rust_dependencies() + +rust_register_toolchains( version = RUST_VERSION, ) @@ -25,6 +26,6 @@ load("//tools/bazel:vendor.bzl", "vendor") vendor( name = "third-party", - lockfile = "//third-party:Cargo.lock", cargo_version = RUST_VERSION, + lockfile = "//third-party:Cargo.lock", ) diff --git a/book/diagram/.gitignore b/book/diagram/.gitignore index 81631c695..27572bd3b 100644 --- a/book/diagram/.gitignore +++ b/book/diagram/.gitignore @@ -1,2 +1,7 @@ -/bin -/build +*.aux +*.fdb_latexmk +*.fls +*.log +*.pdf +*.png +*.svg diff --git a/book/diagram/Makefile b/book/diagram/Makefile index 161da3493..1723a9b9f 100644 --- a/book/diagram/Makefile +++ b/book/diagram/Makefile @@ -1,12 +1,8 @@ -all: overview.svg +overview.svg: overview.pdf + pdf2svg $< $@ -build/bin/svgbob: - cargo install --git https://github.com/ivanceras/svgbob --rev df01674c47350665158ececa476e63f51c58a9c7 --root build +overview.pdf: overview.tex + latexmk $< -%.svg: %.ascii build/bin/svgbob - build/bin/svgbob $< > $@ - -clean: - rm -f *.svg - -.PHONY: all clean +overview.png: overview.svg + svgexport $< $@ 3x diff --git a/book/diagram/overview.ascii b/book/diagram/overview.ascii deleted file mode 100644 index dd1c4b93b..000000000 --- a/book/diagram/overview.ascii +++ /dev/null @@ -1,13 +0,0 @@ - .-----------------------------. - | #[cxx::bridge] mod | - | description of boundary | - '--------------+--------------' - | - | - "Macro expansion" | "Code generation" - +---------------+---------------+ - Safe | | - straightforward v v Straightforward - "Rust APIs".----------------. "Hidden C ABI".---------------. "C++ APIs" -Rust <----------->| "Rust bindings"|<~~~~~~~~~~~~~>| "C++ bindings"|<-----------> "C++" -code '----------------' '---------------' code diff --git a/book/diagram/overview.svg b/book/diagram/overview.svg deleted file mode 100644 index e51546682..000000000 --- a/book/diagram/overview.svg +++ /dev/null @@ -1,132 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - Rust bindings - - C++ bindings - #[cxx::bridge] - mod - description - of - boundary - - - Safe - straightforward - Straightforward - - - - - - - Rust - code - code - Macro expansion - Code generation - Rust APIs - Hidden C ABI - C++ APIs - C++ - - - - - - - - - - - - - diff --git a/book/diagram/overview.tex b/book/diagram/overview.tex new file mode 100644 index 000000000..a613bb751 --- /dev/null +++ b/book/diagram/overview.tex @@ -0,0 +1,45 @@ +\documentclass{standalone} +\usepackage{makecell} +\usepackage{pgfplots} +\usepackage{sansmath} +\usetikzlibrary{arrows.meta} +\pgfplotsset{compat=1.16} +\begin{document} +\pagecolor{white} +\begin{tikzpicture}[ + x=1cm, + y=-.6cm, + every node/.append style={ + line width=1.5pt, + font=\Large\sansmath\sffamily, + }, + every path/.append style={ + >={Latex[length=10pt,width=8pt]}, + line width=1.5pt, + }, + execute at end node={\vphantom{bg}}, +] +\node[draw, rounded corners=5, inner xsep=30pt, inner ysep=2pt] + (bridge) at (0, .25) {\makecell{\texttt{\#\hspace{-1pt}[}cxx::bridge\texttt{]} mod\\[-4pt]description of boundary}}; +\node[draw, rounded corners, inner xsep=10pt, inner ysep=6pt, text depth=1pt] + (rust-bindings) at (-3.5, 6.5) {Rust bindings}; +\node[draw, rounded corners, inner xsep=10pt, inner ysep=6pt, text depth=1pt] + (cpp-bindings) at (3.5, 6.5) {C\texttt{++} bindings}; +\node[inner xsep=4pt, inner ysep=-0pt] + (rust-code) at (-9, 6.5) {\makecell[r]{\\[-8pt]Rust\\[-4pt]code}}; +\node[inner xsep=4pt, inner ysep=-0pt] + (cpp-code) at (9, 6.5) {\makecell[l]{\\[-8pt]C\texttt{++}\\[-4pt]code}}; +\draw (bridge) -- (0, 4); +\draw[<->] (rust-bindings) |- (0, 4) -| (cpp-bindings); +\draw[<->] (rust-code) -- (rust-bindings); +\draw[<->, dash pattern=on 8pt off 6pt] (rust-bindings) -- (cpp-bindings); +\draw[<->] (cpp-bindings) -- (cpp-code); +\draw (-.75, 4) node[anchor=south east] {Macro expansion}; +\draw (.75, 4) node[anchor=south west] {Code generation}; +\draw (0, 6.5) node[anchor=south, inner ysep=4pt] {Hidden C ABI}; +\draw (-6.75, 6.5) node[anchor=south, inner ysep=1pt] {\makecell{Safe\\[-4pt]straightforward\\[-4pt]Rust APIs}}; +\draw (6.75, 6.5) node[anchor=south, inner ysep=1pt] {\makecell{Straightforward\\[-4pt]C\texttt{++} APIs}}; +\pgfresetboundingbox\path + (-9.5, 0) -- (rust-bindings.south)+(0, .3) -- (9.5, 0) -- (bridge.north); +\end{tikzpicture} +\end{document} diff --git a/book/src/cxx.png b/book/src/cxx.png index aeb7ca9bf..07118aafb 100644 Binary files a/book/src/cxx.png and b/book/src/cxx.png differ diff --git a/book/src/index.md b/book/src/index.md index 7b03e7e15..7add044c3 100644 --- a/book/src/index.md +++ b/book/src/index.md @@ -1,5 +1,5 @@
-githubcrates-iodocs-rs +githubcrates-iodocs-rs
# CXX — safe interop between Rust and C++ @@ -11,7 +11,7 @@ boundary effectively within this regime. CXX fills in the low level stuff so that you get a safe binding, preventing the pitfalls of doing a foreign function interface over unsafe C-style signatures. -
+
diff --git a/book/src/overview.svg b/book/src/overview.svg index 659054710..df4fcf49e 100644 --- a/book/src/overview.svg +++ b/book/src/overview.svg @@ -1,99 +1,444 @@ - - - - - - - - - - - - - - - - - - - - - - Rust bindings - - C++ bindings - #[cxx::bridge] mod - description of boundary - - - - - Safe - straightforward - Straightforward - - - - - - - - - - Rust - code - code - Macro expansion - Code generation - Rust APIs - Hidden C ABI - C++ APIs - C++ - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/demo/BUCK b/demo/BUCK index 43b83aad4..cb7dc52d5 100644 --- a/demo/BUCK +++ b/demo/BUCK @@ -3,6 +3,7 @@ load("//tools/buck:rust_cxx_bridge.bzl", "rust_cxx_bridge") rust_binary( name = "demo", srcs = glob(["src/**/*.rs"]), + edition = "2018", deps = [ ":blobstore-sys", ":bridge", diff --git a/demo/BUILD b/demo/BUILD index 0c940d134..3f598fe25 100644 --- a/demo/BUILD +++ b/demo/BUILD @@ -5,6 +5,7 @@ load("//tools/bazel:rust_cxx_bridge.bzl", "rust_cxx_bridge") rust_binary( name = "demo", srcs = glob(["src/**/*.rs"]), + edition = "2018", deps = [ ":blobstore-sys", ":bridge", diff --git a/flags/Cargo.toml b/flags/Cargo.toml index ee7c78b7f..acce1e56f 100644 --- a/flags/Cargo.toml +++ b/flags/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cxxbridge-flags" -version = "1.0.63" +version = "1.0.71" authors = ["David Tolnay "] edition = "2018" rust-version = "1.48" diff --git a/gen/build/Cargo.toml b/gen/build/Cargo.toml index 20aafca3f..a91164ffe 100644 --- a/gen/build/Cargo.toml +++ b/gen/build/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cxx-build" -version = "1.0.63" +version = "1.0.71" authors = ["David Tolnay "] edition = "2018" rust-version = "1.48" @@ -21,10 +21,10 @@ experimental-async-fn = [] cc = "1.0.49" codespan-reporting = "0.11" once_cell = "1.9" -proc-macro2 = { version = "1.0.26", default-features = false, features = ["span-locations"] } +proc-macro2 = { version = "1.0.39", default-features = false, features = ["span-locations"] } quote = { version = "1.0", default-features = false } scratch = "1.0" -syn = { version = "1.0.70", default-features = false, features = ["parsing", "printing", "clone-impls", "full"] } +syn = { version = "1.0.95", default-features = false, features = ["parsing", "printing", "clone-impls", "full"] } [dev-dependencies] cxx-gen = { version = "0.7", path = "../lib" } diff --git a/gen/build/src/cargo.rs b/gen/build/src/cargo.rs index 7a105ae68..cbaa58a44 100644 --- a/gen/build/src/cargo.rs +++ b/gen/build/src/cargo.rs @@ -18,27 +18,28 @@ impl CfgEvaluator for CargoEnvCfgEvaluator { fn eval(&self, name: &str, query_value: Option<&str>) -> CfgResult { let env = ENV.get_or_init(CargoEnv::load); if name == "feature" { - if let Some(query_value) = query_value { + return if let Some(query_value) = query_value { CfgResult::from(env.features.contains(Lookup::new(query_value))) } else { let msg = "expected `feature = \"...\"`".to_owned(); CfgResult::Undetermined { msg } - } - } else if name == "test" && query_value.is_none() { + }; + } + if name == "test" && query_value.is_none() { let msg = "cfg(test) is not supported because Cargo runs your build script only once across the lib and test build of the same crate".to_owned(); - CfgResult::Undetermined { msg } - } else { - match env.cfgs.get(Lookup::new(name)) { - Some(cargo_value) => { - if let Some(query_value) = query_value { - CfgResult::from(cargo_value.split(',').any(|value| value == query_value)) - } else { - CfgResult::True - } - } - None => CfgResult::False, - } + return CfgResult::Undetermined { msg }; + } + if let Some(cargo_value) = env.cfgs.get(Lookup::new(name)) { + return if let Some(query_value) = query_value { + CfgResult::from(cargo_value.split(',').any(|value| value == query_value)) + } else { + CfgResult::True + }; + } + if name == "debug_assertions" && query_value.is_none() { + return CfgResult::from(cfg!(debug_assertions)); } + CfgResult::False } } diff --git a/gen/build/src/lib.rs b/gen/build/src/lib.rs index bdb43a159..7272a396c 100644 --- a/gen/build/src/lib.rs +++ b/gen/build/src/lib.rs @@ -48,9 +48,11 @@ #![allow( clippy::cast_sign_loss, clippy::default_trait_access, + clippy::derive_partial_eq_without_eq, clippy::doc_markdown, clippy::drop_copy, clippy::enum_glob_use, + clippy::explicit_auto_deref, clippy::if_same_then_else, clippy::inherent_to_string, clippy::items_after_statements, @@ -67,6 +69,7 @@ clippy::or_fun_call, clippy::redundant_else, clippy::shadow_unrelated, + clippy::significant_drop_in_scrutinee, clippy::similar_names, clippy::single_match_else, clippy::struct_excessive_bools, diff --git a/gen/cmd/Cargo.toml b/gen/cmd/Cargo.toml index 7d94b2dc9..1d7fa8b2c 100644 --- a/gen/cmd/Cargo.toml +++ b/gen/cmd/Cargo.toml @@ -1,9 +1,9 @@ [package] name = "cxxbridge-cmd" -version = "1.0.63" +version = "1.0.71" authors = ["David Tolnay "] edition = "2018" -rust-version = "1.54" +rust-version = "1.56" license = "MIT OR Apache-2.0" description = "C++ code generator for integrating `cxx` crate into a non-Cargo build." repository = "https://github.com/dtolnay/cxx" @@ -21,11 +21,11 @@ path = "src/main.rs" experimental-async-fn = [] [dependencies] -clap = { version = "3.0", default-features = false, features = ["std", "suggestions"] } +clap = { version = "3.2", default-features = false, features = ["std", "suggestions"] } codespan-reporting = "0.11" -proc-macro2 = { version = "1.0.26", default-features = false, features = ["span-locations"] } +proc-macro2 = { version = "1.0.39", default-features = false, features = ["span-locations"] } quote = { version = "1.0", default-features = false } -syn = { version = "1.0.70", default-features = false, features = ["parsing", "printing", "clone-impls", "full"] } +syn = { version = "1.0.95", default-features = false, features = ["parsing", "printing", "clone-impls", "full"] } [package.metadata.docs.rs] targets = ["x86_64-unknown-linux-gnu"] diff --git a/gen/cmd/src/app.rs b/gen/cmd/src/app.rs index 0a8486600..a1adb387d 100644 --- a/gen/cmd/src/app.rs +++ b/gen/cmd/src/app.rs @@ -6,10 +6,11 @@ use super::{Opt, Output}; use crate::cfg::{self, CfgValue}; use crate::gen::include::Include; use crate::syntax::IncludeKind; -use clap::{App, AppSettings, Arg}; +use clap::builder::{ArgAction, ValueParser}; +use clap::{Arg, Command}; use std::collections::{BTreeMap as Map, BTreeSet as Set}; -use std::ffi::OsStr; use std::path::PathBuf; +use std::sync::{Arc, Mutex, PoisonError}; use syn::parse::Parser; const USAGE: &str = "\ @@ -33,11 +34,11 @@ OPTIONS: {options}\ "; -fn app() -> App<'static> { - let mut app = App::new("cxxbridge") +fn app() -> Command<'static> { + let mut app = Command::new("cxxbridge") .override_usage(USAGE) .help_template(TEMPLATE) - .setting(AppSettings::NextLineHelp) + .next_line_help(true) .arg(arg_input()) .arg(arg_cxx_impl_annotations()) .arg(arg_header()) @@ -63,11 +64,13 @@ const CFG: &str = "cfg"; pub(super) fn from_args() -> Opt { let matches = app().get_matches(); - let input = matches.value_of_os(INPUT).map(PathBuf::from); - let cxx_impl_annotations = matches.value_of(CXX_IMPL_ANNOTATIONS).map(str::to_owned); - let header = matches.is_present(HEADER); + let input = matches.get_one::(INPUT).cloned(); + let cxx_impl_annotations = matches + .get_one::(CXX_IMPL_ANNOTATIONS) + .map(String::clone); + let header = matches.contains_id(HEADER); let include = matches - .values_of(INCLUDE) + .get_many::(INCLUDE) .unwrap_or_default() .map(|include| { if include.starts_with('<') && include.ends_with('>') { @@ -85,11 +88,11 @@ pub(super) fn from_args() -> Opt { .collect(); let mut outputs = Vec::new(); - for path in matches.values_of_os(OUTPUT).unwrap_or_default() { - outputs.push(if path == "-" { + for path in matches.get_many::(OUTPUT).unwrap_or_default() { + outputs.push(if path.as_os_str() == "-" { Output::Stdout } else { - Output::File(PathBuf::from(path)) + Output::File(path.clone()) }); } if outputs.is_empty() { @@ -97,7 +100,7 @@ pub(super) fn from_args() -> Opt { } let mut cfg = Map::new(); - for arg in matches.values_of(CFG).unwrap_or_default() { + for arg in matches.get_many::(CFG).unwrap_or_default() { let (name, value) = cfg::parse.parse_str(arg).unwrap(); cfg.entry(name).or_insert_with(Set::new).insert(value); } @@ -112,19 +115,11 @@ pub(super) fn from_args() -> Opt { } } -fn validate_utf8(arg: &OsStr) -> Result<(), &'static str> { - if arg.to_str().is_some() { - Ok(()) - } else { - Err("invalid utf-8 sequence") - } -} - fn arg_input() -> Arg<'static> { Arg::new(INPUT) .help("Input Rust source file containing #[cxx::bridge].") .required_unless_present(HEADER) - .allow_invalid_utf8(true) + .value_parser(ValueParser::path_buf()) } fn arg_cxx_impl_annotations() -> Arg<'static> { @@ -138,8 +133,7 @@ these C++ functions in another."; .long(CXX_IMPL_ANNOTATIONS) .takes_value(true) .value_name("annotation") - .allow_invalid_utf8(true) - .validator_os(validate_utf8) + .value_parser(ValueParser::string()) .help(HELP) } @@ -159,9 +153,8 @@ into the generated C++ code as #include lines."; .long(INCLUDE) .short('i') .takes_value(true) - .multiple_occurrences(true) - .allow_invalid_utf8(true) - .validator_os(validate_utf8) + .action(ArgAction::Append) + .value_parser(ValueParser::string()) .help(HELP) } @@ -173,9 +166,8 @@ not specified."; .long(OUTPUT) .short('o') .takes_value(true) - .multiple_occurrences(true) - .allow_invalid_utf8(true) - .validator_os(validate_utf8) + .action(ArgAction::Append) + .value_parser(ValueParser::path_buf()) .help(HELP) } @@ -183,22 +175,23 @@ fn arg_cfg() -> Arg<'static> { const HELP: &str = "\ Compilation configuration matching what will be used to build the Rust side of the bridge."; - let mut bool_cfgs = Map::::new(); + let bool_cfgs = Arc::new(Mutex::new(Map::::new())); Arg::new(CFG) .long(CFG) .takes_value(true) .value_name("name=\"value\" | name[=true] | name=false") - .multiple_occurrences(true) - .validator(move |arg| match cfg::parse.parse_str(arg) { - Ok((_, CfgValue::Str(_))) => Ok(()), + .action(ArgAction::Append) + .value_parser(move |arg: &str| match cfg::parse.parse_str(arg) { + Ok((_, CfgValue::Str(_))) => Ok(arg.to_owned()), Ok((name, CfgValue::Bool(value))) => { + let mut bool_cfgs = bool_cfgs.lock().unwrap_or_else(PoisonError::into_inner); if let Some(&prev) = bool_cfgs.get(&name) { if prev != value { return Err(format!("cannot have both {0}=false and {0}=true", name)); } } bool_cfgs.insert(name, value); - Ok(()) + Ok(arg.to_owned()) } Err(_) => Err("expected name=\"value\", name=true, or name=false".to_owned()), }) diff --git a/gen/cmd/src/main.rs b/gen/cmd/src/main.rs index e375d524e..4d5edfd15 100644 --- a/gen/cmd/src/main.rs +++ b/gen/cmd/src/main.rs @@ -2,6 +2,7 @@ clippy::cast_sign_loss, clippy::cognitive_complexity, clippy::default_trait_access, + clippy::derive_partial_eq_without_eq, clippy::enum_glob_use, clippy::if_same_then_else, clippy::inherent_to_string, diff --git a/gen/lib/Cargo.toml b/gen/lib/Cargo.toml index 4f045250f..b470eb210 100644 --- a/gen/lib/Cargo.toml +++ b/gen/lib/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cxx-gen" -version = "0.7.63" +version = "0.7.71" authors = ["Adrian Taylor "] edition = "2018" rust-version = "1.48" @@ -13,9 +13,9 @@ categories = ["development-tools::ffi"] [dependencies] codespan-reporting = "0.11" -proc-macro2 = { version = "1.0.26", default-features = false, features = ["span-locations"] } +proc-macro2 = { version = "1.0.39", default-features = false, features = ["span-locations"] } quote = { version = "1.0", default-features = false } -syn = { version = "1.0.70", default-features = false, features = ["parsing", "printing", "clone-impls", "full"] } +syn = { version = "1.0.95", default-features = false, features = ["parsing", "printing", "clone-impls", "full"] } [package.metadata.docs.rs] targets = ["x86_64-unknown-linux-gnu"] diff --git a/gen/lib/src/lib.rs b/gen/lib/src/lib.rs index 8e052f7ba..47cfa18d6 100644 --- a/gen/lib/src/lib.rs +++ b/gen/lib/src/lib.rs @@ -12,6 +12,7 @@ #![allow( clippy::cast_sign_loss, clippy::default_trait_access, + clippy::derive_partial_eq_without_eq, clippy::enum_glob_use, clippy::if_same_then_else, clippy::inherent_to_string, diff --git a/gen/src/builtin.rs b/gen/src/builtin.rs index 7ac9209cd..7ee91c564 100644 --- a/gen/src/builtin.rs +++ b/gen/src/builtin.rs @@ -28,6 +28,7 @@ pub struct Builtins<'a> { pub rust_slice_repr: bool, pub exception: bool, pub relocatable: bool, + pub relocatable_or_array: bool, pub friend_impl: bool, pub is_complete: bool, pub destroy: bool, @@ -113,6 +114,11 @@ pub(super) fn write(out: &mut OutFile) { include.sys_types = true; } + if builtin.relocatable_or_array { + include.cstddef = true; + builtin.relocatable = true; + } + if builtin.relocatable { include.type_traits = true; } @@ -357,6 +363,17 @@ pub(super) fn write(out: &mut OutFile) { writeln!(out, "}};"); } + if builtin.relocatable_or_array { + out.next_section(); + writeln!(out, "template "); + writeln!(out, "struct IsRelocatableOrArray : IsRelocatable {{}};"); + writeln!(out, "template "); + writeln!( + out, + "struct IsRelocatableOrArray : IsRelocatableOrArray {{}};", + ); + } + out.end_block(Block::AnonymousNamespace); out.end_block(Block::InlineNamespace("cxxbridge1")); diff --git a/gen/src/write.rs b/gen/src/write.rs index c2d79c0e5..0a2705ed1 100644 --- a/gen/src/write.rs +++ b/gen/src/write.rs @@ -470,7 +470,25 @@ fn check_trivial_extern_type(out: &mut OutFile, alias: &TypeAlias, reasons: &[Tr let id = alias.name.to_fully_qualified(); out.builtin.relocatable = true; writeln!(out, "static_assert("); - writeln!(out, " ::rust::IsRelocatable<{}>::value,", id); + if reasons + .iter() + .all(|r| matches!(r, TrivialReason::StructField(_))) + { + // If the type is only used as a struct field and not as by-value + // function argument or any other use, then C array of trivially + // relocatable type is also permissible. + // + // --- means something sane: + // struct T { char buf[N]; }; + // + // --- means something totally different: + // void f(char buf[N]); + // + out.builtin.relocatable_or_array = true; + writeln!(out, " ::rust::IsRelocatableOrArray<{}>::value,", id); + } else { + writeln!(out, " ::rust::IsRelocatable<{}>::value,", id); + } writeln!( out, " \"type {} should be trivially move constructible and trivially destructible in C++ to be used as {} in Rust\");", @@ -1776,6 +1794,18 @@ fn write_shared_ptr(out: &mut OutFile, key: NamedImplKey) { writeln!(out, "}}"); } begin_function_definition(out); + writeln!( + out, + "void cxxbridge1$shared_ptr${}$from_unmanaged(::std::shared_ptr<{}>* ptr, void* data) noexcept {{", + instance, inner, + ); + writeln!( + out, + "new (ptr) std::shared_ptr<{}>(static_cast<{}*>(data));", + inner, inner + ); + writeln!(out, "}}"); + begin_function_definition(out); writeln!( out, "void cxxbridge1$shared_ptr${}$clone(const ::std::shared_ptr<{}>& self, ::std::shared_ptr<{}> *ptr) noexcept {{", diff --git a/macro/Cargo.toml b/macro/Cargo.toml index d565f6b03..546b5147c 100644 --- a/macro/Cargo.toml +++ b/macro/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cxxbridge-macro" -version = "1.0.63" +version = "1.0.71" authors = ["David Tolnay "] edition = "2018" rust-version = "1.48" @@ -21,9 +21,9 @@ experimental-async-fn = [] experimental-enum-variants-from-header = ["clang-ast", "flate2", "memmap", "serde", "serde_json"] [dependencies] -proc-macro2 = "1.0" +proc-macro2 = "1.0.39" quote = "1.0.4" -syn = { version = "1.0.70", features = ["full"] } +syn = { version = "1.0.95", features = ["full"] } # optional dependencies: clang-ast = { version = "0.1", optional = true } diff --git a/macro/src/expand.rs b/macro/src/expand.rs index 8b0a08185..5859304c0 100644 --- a/macro/src/expand.rs +++ b/macro/src/expand.rs @@ -172,12 +172,13 @@ fn expand_struct(strct: &Struct) -> TokenStream { quote! { #doc - #attrs #derives + #attrs #[repr(C)] #struct_def unsafe impl #generics ::cxx::ExternType for #ident #generics { + #[allow(unused_attributes)] // incorrect lint #[doc(hidden)] type Id = #type_id; type Kind = ::cxx::kind::Trivial; @@ -341,8 +342,8 @@ fn expand_enum(enm: &Enum) -> TokenStream { quote! { #doc - #attrs #derives + #attrs #[repr(transparent)] #enum_def @@ -352,6 +353,7 @@ fn expand_enum(enm: &Enum) -> TokenStream { } unsafe impl ::cxx::ExternType for #ident { + #[allow(unused_attributes)] // incorrect lint #[doc(hidden)] type Id = #type_id; type Kind = ::cxx::kind::Trivial; @@ -393,6 +395,7 @@ fn expand_cxx_type(ety: &ExternType) -> TokenStream { #extern_type_def unsafe impl #generics ::cxx::ExternType for #ident #generics { + #[allow(unused_attributes)] // incorrect lint #[doc(hidden)] type Id = #type_id; type Kind = ::cxx::kind::Opaque; @@ -784,6 +787,7 @@ fn expand_function_pointer_trampoline( prevent_unwind_label, None, Some(&efn.generics), + &efn.attrs, body_span, ); let var = &var.rust; @@ -829,6 +833,7 @@ fn expand_rust_type_impl(ety: &ExternType) -> TokenStream { let span = derive.span; impls.extend(quote_spanned! {span=> unsafe impl #generics ::cxx::ExternType for #ident #generics { + #[allow(unused_attributes)] // incorrect lint #[doc(hidden)] type Id = #type_id; type Kind = ::cxx::kind::Opaque; @@ -933,6 +938,7 @@ fn expand_rust_function_shim(efn: &ExternFn, types: &Types) -> TokenStream { prevent_unwind_label, invoke, None, + &efn.attrs, body_span, ) } @@ -945,6 +951,7 @@ fn expand_rust_function_shim_impl( prevent_unwind_label: String, invoke: Option<&Ident>, outer_generics: Option<&Generics>, + attrs: &OtherAttrs, body_span: Span, ) -> TokenStream { let generics = outer_generics.unwrap_or(&sig.generics); @@ -1119,6 +1126,7 @@ fn expand_rust_function_shim_impl( }; quote_spanned! {span=> + #attrs #[doc(hidden)] #[export_name = #link_name] unsafe extern "C" fn #local_name #generics(#(#all_args,)* #outparam #pointer) #ret { @@ -1385,7 +1393,6 @@ fn expand_unique_ptr( let can_construct_from_value = types.is_maybe_trivial(ident); let new_method = if can_construct_from_value { Some(quote! { - #[doc(hidden)] fn __new(value: Self) -> ::cxx::core::mem::MaybeUninit<*mut ::cxx::core::ffi::c_void> { extern "C" { #[link_name = #link_uninit] @@ -1406,11 +1413,9 @@ fn expand_unique_ptr( quote_spanned! {end_span=> #unsafe_token impl #impl_generics ::cxx::private::UniquePtrTarget for #ident #ty_generics { - #[doc(hidden)] fn __typename(f: &mut ::cxx::core::fmt::Formatter<'_>) -> ::cxx::core::fmt::Result { f.write_str(#name) } - #[doc(hidden)] fn __null() -> ::cxx::core::mem::MaybeUninit<*mut ::cxx::core::ffi::c_void> { extern "C" { #[link_name = #link_null] @@ -1421,7 +1426,6 @@ fn expand_unique_ptr( repr } #new_method - #[doc(hidden)] unsafe fn __raw(raw: *mut Self) -> ::cxx::core::mem::MaybeUninit<*mut ::cxx::core::ffi::c_void> { extern "C" { #[link_name = #link_raw] @@ -1431,7 +1435,6 @@ fn expand_unique_ptr( __raw(&mut repr, raw.cast()); repr } - #[doc(hidden)] unsafe fn __get(repr: ::cxx::core::mem::MaybeUninit<*mut ::cxx::core::ffi::c_void>) -> *const Self { extern "C" { #[link_name = #link_get] @@ -1439,7 +1442,6 @@ fn expand_unique_ptr( } __get(&repr).cast() } - #[doc(hidden)] unsafe fn __release(mut repr: ::cxx::core::mem::MaybeUninit<*mut ::cxx::core::ffi::c_void>) -> *mut Self { extern "C" { #[link_name = #link_release] @@ -1447,7 +1449,6 @@ fn expand_unique_ptr( } __release(&mut repr).cast() } - #[doc(hidden)] unsafe fn __drop(mut repr: ::cxx::core::mem::MaybeUninit<*mut ::cxx::core::ffi::c_void>) { extern "C" { #[link_name = #link_drop] @@ -1470,6 +1471,7 @@ fn expand_shared_ptr( let prefix = format!("cxxbridge1$shared_ptr${}$", resolve.name.to_symbol()); let link_null = format!("{}null", prefix); let link_uninit = format!("{}uninit", prefix); + let link_from_unmanaged = format!("{}from_unmanaged", prefix); let link_clone = format!("{}clone", prefix); let link_get = format!("{}get", prefix); let link_drop = format!("{}drop", prefix); @@ -1479,7 +1481,6 @@ fn expand_shared_ptr( let can_construct_from_value = types.is_maybe_trivial(ident); let new_method = if can_construct_from_value { Some(quote! { - #[doc(hidden)] unsafe fn __new(value: Self, new: *mut ::cxx::core::ffi::c_void) { extern "C" { #[link_name = #link_uninit] @@ -1498,11 +1499,9 @@ fn expand_shared_ptr( quote_spanned! {end_span=> #unsafe_token impl #impl_generics ::cxx::private::SharedPtrTarget for #ident #ty_generics { - #[doc(hidden)] fn __typename(f: &mut ::cxx::core::fmt::Formatter<'_>) -> ::cxx::core::fmt::Result { f.write_str(#name) } - #[doc(hidden)] unsafe fn __null(new: *mut ::cxx::core::ffi::c_void) { extern "C" { #[link_name = #link_null] @@ -1511,7 +1510,13 @@ fn expand_shared_ptr( __null(new); } #new_method - #[doc(hidden)] + unsafe fn __from_unmanaged(value: *mut Self, new: *mut ::cxx::core::ffi::c_void) { + extern "C" { + #[link_name = #link_from_unmanaged] + fn __from_unmanaged(new: *const ::cxx::core::ffi::c_void, value: *mut ::cxx::core::ffi::c_void); + } + __from_unmanaged(new, value as *mut ::cxx::core::ffi::c_void); + } unsafe fn __clone(this: *const ::cxx::core::ffi::c_void, new: *mut ::cxx::core::ffi::c_void) { extern "C" { #[link_name = #link_clone] @@ -1519,7 +1524,6 @@ fn expand_shared_ptr( } __clone(this, new); } - #[doc(hidden)] unsafe fn __get(this: *const ::cxx::core::ffi::c_void) -> *const Self { extern "C" { #[link_name = #link_get] @@ -1527,7 +1531,6 @@ fn expand_shared_ptr( } __get(this).cast() } - #[doc(hidden)] unsafe fn __drop(this: *mut ::cxx::core::ffi::c_void) { extern "C" { #[link_name = #link_drop] @@ -1558,11 +1561,9 @@ fn expand_weak_ptr(key: NamedImplKey, types: &Types, explicit_impl: Option<&Impl quote_spanned! {end_span=> #unsafe_token impl #impl_generics ::cxx::private::WeakPtrTarget for #ident #ty_generics { - #[doc(hidden)] fn __typename(f: &mut ::cxx::core::fmt::Formatter<'_>) -> ::cxx::core::fmt::Result { f.write_str(#name) } - #[doc(hidden)] unsafe fn __null(new: *mut ::cxx::core::ffi::c_void) { extern "C" { #[link_name = #link_null] @@ -1570,7 +1571,6 @@ fn expand_weak_ptr(key: NamedImplKey, types: &Types, explicit_impl: Option<&Impl } __null(new); } - #[doc(hidden)] unsafe fn __clone(this: *const ::cxx::core::ffi::c_void, new: *mut ::cxx::core::ffi::c_void) { extern "C" { #[link_name = #link_clone] @@ -1578,7 +1578,6 @@ fn expand_weak_ptr(key: NamedImplKey, types: &Types, explicit_impl: Option<&Impl } __clone(this, new); } - #[doc(hidden)] unsafe fn __downgrade(shared: *const ::cxx::core::ffi::c_void, weak: *mut ::cxx::core::ffi::c_void) { extern "C" { #[link_name = #link_downgrade] @@ -1586,7 +1585,6 @@ fn expand_weak_ptr(key: NamedImplKey, types: &Types, explicit_impl: Option<&Impl } __downgrade(shared, weak); } - #[doc(hidden)] unsafe fn __upgrade(weak: *const ::cxx::core::ffi::c_void, shared: *mut ::cxx::core::ffi::c_void) { extern "C" { #[link_name = #link_upgrade] @@ -1594,7 +1592,6 @@ fn expand_weak_ptr(key: NamedImplKey, types: &Types, explicit_impl: Option<&Impl } __upgrade(weak, shared); } - #[doc(hidden)] unsafe fn __drop(this: *mut ::cxx::core::ffi::c_void) { extern "C" { #[link_name = #link_drop] @@ -1638,7 +1635,6 @@ fn expand_cxx_vector( let can_pass_element_by_value = types.is_maybe_trivial(elem); let by_value_methods = if can_pass_element_by_value { Some(quote_spanned! {end_span=> - #[doc(hidden)] unsafe fn __push_back( this: ::cxx::core::pin::Pin<&mut ::cxx::CxxVector>, value: &mut ::cxx::core::mem::ManuallyDrop, @@ -1652,7 +1648,6 @@ fn expand_cxx_vector( } __push_back(this, value as *mut ::cxx::core::mem::ManuallyDrop as *mut ::cxx::core::ffi::c_void); } - #[doc(hidden)] unsafe fn __pop_back( this: ::cxx::core::pin::Pin<&mut ::cxx::CxxVector>, out: &mut ::cxx::core::mem::MaybeUninit, @@ -1673,11 +1668,9 @@ fn expand_cxx_vector( quote_spanned! {end_span=> #unsafe_token impl #impl_generics ::cxx::private::VectorElement for #elem #ty_generics { - #[doc(hidden)] fn __typename(f: &mut ::cxx::core::fmt::Formatter<'_>) -> ::cxx::core::fmt::Result { f.write_str(#name) } - #[doc(hidden)] fn __vector_size(v: &::cxx::CxxVector) -> usize { extern "C" { #[link_name = #link_size] @@ -1685,7 +1678,6 @@ fn expand_cxx_vector( } unsafe { __vector_size(v) } } - #[doc(hidden)] unsafe fn __get_unchecked(v: *mut ::cxx::CxxVector, pos: usize) -> *mut Self { extern "C" { #[link_name = #link_get_unchecked] @@ -1697,7 +1689,6 @@ fn expand_cxx_vector( __get_unchecked(v, pos) as *mut Self } #by_value_methods - #[doc(hidden)] fn __unique_ptr_null() -> ::cxx::core::mem::MaybeUninit<*mut ::cxx::core::ffi::c_void> { extern "C" { #[link_name = #link_unique_ptr_null] @@ -1707,7 +1698,6 @@ fn expand_cxx_vector( unsafe { __unique_ptr_null(&mut repr) } repr } - #[doc(hidden)] unsafe fn __unique_ptr_raw(raw: *mut ::cxx::CxxVector) -> ::cxx::core::mem::MaybeUninit<*mut ::cxx::core::ffi::c_void> { extern "C" { #[link_name = #link_unique_ptr_raw] @@ -1717,7 +1707,6 @@ fn expand_cxx_vector( __unique_ptr_raw(&mut repr, raw); repr } - #[doc(hidden)] unsafe fn __unique_ptr_get(repr: ::cxx::core::mem::MaybeUninit<*mut ::cxx::core::ffi::c_void>) -> *const ::cxx::CxxVector { extern "C" { #[link_name = #link_unique_ptr_get] @@ -1725,7 +1714,6 @@ fn expand_cxx_vector( } __unique_ptr_get(&repr) } - #[doc(hidden)] unsafe fn __unique_ptr_release(mut repr: ::cxx::core::mem::MaybeUninit<*mut ::cxx::core::ffi::c_void>) -> *mut ::cxx::CxxVector { extern "C" { #[link_name = #link_unique_ptr_release] @@ -1733,7 +1721,6 @@ fn expand_cxx_vector( } __unique_ptr_release(&mut repr) } - #[doc(hidden)] unsafe fn __unique_ptr_drop(mut repr: ::cxx::core::mem::MaybeUninit<*mut ::cxx::core::ffi::c_void>) { extern "C" { #[link_name = #link_unique_ptr_drop] diff --git a/macro/src/lib.rs b/macro/src/lib.rs index e48d1a3a3..138e3a299 100644 --- a/macro/src/lib.rs +++ b/macro/src/lib.rs @@ -1,6 +1,7 @@ #![allow( clippy::cast_sign_loss, clippy::default_trait_access, + clippy::derive_partial_eq_without_eq, clippy::doc_markdown, clippy::enum_glob_use, clippy::if_same_then_else, diff --git a/macro/src/load.rs b/macro/src/load.rs index baf88413f..a9958aee8 100644 --- a/macro/src/load.rs +++ b/macro/src/load.rs @@ -59,10 +59,10 @@ pub fn load(cx: &mut Errors, apis: &mut [Api]) { let is_gzipped = memmap.get(..2) == Some(b"\x1f\x8b"); if is_gzipped { gunzipped = Vec::new(); - let decode_result = GzDecoder::new(&mut gunzipped).write_all(&memmap); + let decode_result = GzDecoder::new(&mut gunzipped).write_all(memmap); decode_result.map(|_| gunzipped.as_slice()) } else { - Ok(&memmap as &[u8]) + Ok(memmap as &[u8]) } } Err(error) => Err(error), @@ -143,7 +143,7 @@ fn traverse<'a>( }; let repr = translate_qual_type( cx, - &enm, + enm, fixed_underlying_type .desugared_qual_type .as_ref() diff --git a/src/cxx.cc b/src/cxx.cc index 1601a05ab..cc7375743 100644 --- a/src/cxx.cc +++ b/src/cxx.cc @@ -666,6 +666,10 @@ static_assert(sizeof(std::string) <= kMaxExpectedWordsInString * sizeof(void *), std::shared_ptr *ptr) noexcept { \ new (ptr) std::shared_ptr(); \ } \ + void cxxbridge1$std$shared_ptr$##RUST_TYPE##$from_unmanaged( \ + std::shared_ptr *ptr, void* data) noexcept { \ + new (ptr) std::shared_ptr(static_cast(data)); \ + } \ CXX_TYPE *cxxbridge1$std$shared_ptr$##RUST_TYPE##$uninit( \ std::shared_ptr *ptr) noexcept { \ CXX_TYPE *uninit = \ diff --git a/src/cxx_vector.rs b/src/cxx_vector.rs index d1fa23a2f..abf9297a8 100644 --- a/src/cxx_vector.rs +++ b/src/cxx_vector.rs @@ -368,7 +368,6 @@ pub unsafe trait VectorElement: Sized { macro_rules! vector_element_by_value_methods { (opaque, $segment:expr, $ty:ty) => {}; (trivial, $segment:expr, $ty:ty) => { - #[doc(hidden)] unsafe fn __push_back(v: Pin<&mut CxxVector<$ty>>, value: &mut ManuallyDrop<$ty>) { extern "C" { attr! { @@ -378,7 +377,6 @@ macro_rules! vector_element_by_value_methods { } unsafe { __push_back(v, value) } } - #[doc(hidden)] unsafe fn __pop_back(v: Pin<&mut CxxVector<$ty>>, out: &mut MaybeUninit<$ty>) { extern "C" { attr! { @@ -397,11 +395,9 @@ macro_rules! impl_vector_element { const_assert_eq!(1, mem::align_of::>()); unsafe impl VectorElement for $ty { - #[doc(hidden)] fn __typename(f: &mut fmt::Formatter) -> fmt::Result { f.write_str($name) } - #[doc(hidden)] fn __vector_size(v: &CxxVector<$ty>) -> usize { extern "C" { attr! { @@ -411,7 +407,6 @@ macro_rules! impl_vector_element { } unsafe { __vector_size(v) } } - #[doc(hidden)] unsafe fn __get_unchecked(v: *mut CxxVector<$ty>, pos: usize) -> *mut $ty { extern "C" { attr! { @@ -422,7 +417,6 @@ macro_rules! impl_vector_element { unsafe { __get_unchecked(v, pos) } } vector_element_by_value_methods!($kind, $segment, $ty); - #[doc(hidden)] fn __unique_ptr_null() -> MaybeUninit<*mut c_void> { extern "C" { attr! { @@ -434,7 +428,6 @@ macro_rules! impl_vector_element { unsafe { __unique_ptr_null(&mut repr) } repr } - #[doc(hidden)] unsafe fn __unique_ptr_raw(raw: *mut CxxVector) -> MaybeUninit<*mut c_void> { extern "C" { attr! { @@ -446,7 +439,6 @@ macro_rules! impl_vector_element { unsafe { __unique_ptr_raw(&mut repr, raw) } repr } - #[doc(hidden)] unsafe fn __unique_ptr_get(repr: MaybeUninit<*mut c_void>) -> *const CxxVector { extern "C" { attr! { @@ -456,7 +448,6 @@ macro_rules! impl_vector_element { } unsafe { __unique_ptr_get(&repr) } } - #[doc(hidden)] unsafe fn __unique_ptr_release(mut repr: MaybeUninit<*mut c_void>) -> *mut CxxVector { extern "C" { attr! { @@ -466,7 +457,6 @@ macro_rules! impl_vector_element { } unsafe { __unique_ptr_release(&mut repr) } } - #[doc(hidden)] unsafe fn __unique_ptr_drop(mut repr: MaybeUninit<*mut c_void>) { extern "C" { attr! { diff --git a/src/extern_type.rs b/src/extern_type.rs index b42045b90..d131ae127 100644 --- a/src/extern_type.rs +++ b/src/extern_type.rs @@ -191,6 +191,7 @@ macro_rules! impl_extern_type { $($( $(#[$($attr)*])* unsafe impl ExternType for $ty { + #[allow(unused_attributes)] // incorrect lint; this doc(hidden) attr *is* respected by rustdoc #[doc(hidden)] type Id = crate::type_id!($cxxpath); type Kind = $kind; diff --git a/src/lib.rs b/src/lib.rs index f73073dea..4f009ad41 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,7 +2,7 @@ //! //! [github]: https://img.shields.io/badge/github-8da0cb?style=for-the-badge&labelColor=555555&logo=github //! [crates-io]: https://img.shields.io/badge/crates.io-fc8d62?style=for-the-badge&labelColor=555555&logo=rust -//! [docs-rs]: https://img.shields.io/badge/docs.rs-66c2a5?style=for-the-badge&labelColor=555555&logoColor=white&logo=data:image/svg+xml;base64,PHN2ZyByb2xlPSJpbWciIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgdmlld0JveD0iMCAwIDUxMiA1MTIiPjxwYXRoIGZpbGw9IiNmNWY1ZjUiIGQ9Ik00ODguNiAyNTAuMkwzOTIgMjE0VjEwNS41YzAtMTUtOS4zLTI4LjQtMjMuNC0zMy43bC0xMDAtMzcuNWMtOC4xLTMuMS0xNy4xLTMuMS0yNS4zIDBsLTEwMCAzNy41Yy0xNC4xIDUuMy0yMy40IDE4LjctMjMuNCAzMy43VjIxNGwtOTYuNiAzNi4yQzkuMyAyNTUuNSAwIDI2OC45IDAgMjgzLjlWMzk0YzAgMTMuNiA3LjcgMjYuMSAxOS45IDMyLjJsMTAwIDUwYzEwLjEgNS4xIDIyLjEgNS4xIDMyLjIgMGwxMDMuOS01MiAxMDMuOSA1MmMxMC4xIDUuMSAyMi4xIDUuMSAzMi4yIDBsMTAwLTUwYzEyLjItNi4xIDE5LjktMTguNiAxOS45LTMyLjJWMjgzLjljMC0xNS05LjMtMjguNC0yMy40LTMzLjd6TTM1OCAyMTQuOGwtODUgMzEuOXYtNjguMmw4NS0zN3Y3My4zek0xNTQgMTA0LjFsMTAyLTM4LjIgMTAyIDM4LjJ2LjZsLTEwMiA0MS40LTEwMi00MS40di0uNnptODQgMjkxLjFsLTg1IDQyLjV2LTc5LjFsODUtMzguOHY3NS40em0wLTExMmwtMTAyIDQxLjQtMTAyLTQxLjR2LS42bDEwMi0zOC4yIDEwMiAzOC4ydi42em0yNDAgMTEybC04NSA0Mi41di03OS4xbDg1LTM4Ljh2NzUuNHptMC0xMTJsLTEwMiA0MS40LTEwMi00MS40di0uNmwxMDItMzguMiAxMDIgMzguMnYuNnoiPjwvcGF0aD48L3N2Zz4K +//! [docs-rs]: https://img.shields.io/badge/docs.rs-66c2a5?style=for-the-badge&labelColor=555555&logo=docs.rs //! //!
//! @@ -364,7 +364,7 @@ //! #![no_std] -#![doc(html_root_url = "https://docs.rs/cxx/1.0.63")] +#![doc(html_root_url = "https://docs.rs/cxx/1.0.71")] #![deny(improper_ctypes, improper_ctypes_definitions, missing_docs)] #![cfg_attr(not(no_unsafe_op_in_unsafe_fn_lint), deny(unsafe_op_in_unsafe_fn))] #![cfg_attr(no_unsafe_op_in_unsafe_fn_lint, allow(unused_unsafe))] @@ -389,6 +389,7 @@ clippy::or_fun_call, clippy::ptr_arg, clippy::toplevel_ref_arg, + clippy::transmute_undefined_repr, // clippy bug: https://github.com/rust-lang/rust-clippy/issues/8417 clippy::useless_let_if_seq, clippy::wrong_self_convention )] diff --git a/src/shared_ptr.rs b/src/shared_ptr.rs index 317773d42..a215ad001 100644 --- a/src/shared_ptr.rs +++ b/src/shared_ptr.rs @@ -48,6 +48,24 @@ where } } + /// Create a shared pointer from an already-allocated object + /// Corresponds to constructor (3) of [std::shared\_ptr](https://en.cppreference.com/w/cpp/memory/shared_ptr/shared_ptr) + /// + /// The SharedPtr gains ownership of the pointer and will call std::default_delete on it when the refcount goes to zero. + /// The data will not be moved, so any pointers to this data elsewhere in the program continue to be valid + /// + /// # Safety + /// + /// Value must either be null or point to a valid instance of T + pub unsafe fn from_unmanaged(value: *mut T) -> Self { + let mut shared_ptr = MaybeUninit::>::uninit(); + let new = shared_ptr.as_mut_ptr().cast(); + unsafe { + T::__from_unmanaged(value, new); + shared_ptr.assume_init() + } + } + /// Checks whether the SharedPtr does not own an object. /// /// This is the opposite of [std::shared_ptr\::operator bool](https://en.cppreference.com/w/cpp/memory/shared_ptr/operator_bool). @@ -194,6 +212,8 @@ pub unsafe trait SharedPtrTarget { unreachable!() } #[doc(hidden)] + unsafe fn __from_unmanaged(value: *mut Self, new: *mut c_void); + #[doc(hidden)] unsafe fn __clone(this: *const c_void, new: *mut c_void); #[doc(hidden)] unsafe fn __get(this: *const c_void) -> *const Self; @@ -204,11 +224,9 @@ pub unsafe trait SharedPtrTarget { macro_rules! impl_shared_ptr_target { ($segment:expr, $name:expr, $ty:ty) => { unsafe impl SharedPtrTarget for $ty { - #[doc(hidden)] fn __typename(f: &mut fmt::Formatter) -> fmt::Result { f.write_str($name) } - #[doc(hidden)] unsafe fn __null(new: *mut c_void) { extern "C" { attr! { @@ -218,7 +236,6 @@ macro_rules! impl_shared_ptr_target { } unsafe { __null(new) } } - #[doc(hidden)] unsafe fn __new(value: Self, new: *mut c_void) { extern "C" { attr! { @@ -228,7 +245,15 @@ macro_rules! impl_shared_ptr_target { } unsafe { __uninit(new).cast::<$ty>().write(value) } } - #[doc(hidden)] + unsafe fn __from_unmanaged(value: *mut Self, new: *mut c_void) { + extern "C" { + attr! { + #[link_name = concat!("cxxbridge1$std$shared_ptr$", $segment, "$from_unmanaged")] + fn __from_unmanaged(new: *mut c_void, value: *mut c_void); + } + } + unsafe { __from_unmanaged(new, value as *mut c_void) } + } unsafe fn __clone(this: *const c_void, new: *mut c_void) { extern "C" { attr! { @@ -238,7 +263,6 @@ macro_rules! impl_shared_ptr_target { } unsafe { __clone(this, new) } } - #[doc(hidden)] unsafe fn __get(this: *const c_void) -> *const Self { extern "C" { attr! { @@ -248,7 +272,6 @@ macro_rules! impl_shared_ptr_target { } unsafe { __get(this) }.cast() } - #[doc(hidden)] unsafe fn __drop(this: *mut c_void) { extern "C" { attr! { diff --git a/src/unique_ptr.rs b/src/unique_ptr.rs index 63a1ca78c..6debe6c65 100644 --- a/src/unique_ptr.rs +++ b/src/unique_ptr.rs @@ -1,8 +1,9 @@ use crate::cxx_vector::{CxxVector, VectorElement}; use crate::fmt::display; use crate::kind::Trivial; +use crate::memory::SharedPtrTarget; use crate::string::CxxString; -use crate::ExternType; +use crate::{ExternType, SharedPtr}; use core::ffi::c_void; use core::fmt::{self, Debug, Display}; use core::marker::PhantomData; @@ -107,6 +108,15 @@ where ty: PhantomData, } } + + /// Convert this UniquePtr to a SharedPtr, analogous to constructor (13) for [std::shared\_ptr](https://en.cppreference.com/w/cpp/memory/shared_ptr/shared_ptr) + pub fn to_shared(self) -> SharedPtr where T: SharedPtrTarget { + unsafe { SharedPtr::from_unmanaged(self.into_raw()) } + } +} + +impl UniquePtr +where T: UniquePtrTarget + SharedPtrTarget { } unsafe impl Send for UniquePtr where T: Send + UniquePtrTarget {} @@ -225,6 +235,7 @@ pub unsafe trait UniquePtrTarget { unsafe fn __release(repr: MaybeUninit<*mut c_void>) -> *mut Self; #[doc(hidden)] unsafe fn __drop(repr: MaybeUninit<*mut c_void>); + } extern "C" { @@ -241,11 +252,9 @@ extern "C" { } unsafe impl UniquePtrTarget for CxxString { - #[doc(hidden)] fn __typename(f: &mut fmt::Formatter) -> fmt::Result { f.write_str("CxxString") } - #[doc(hidden)] fn __null() -> MaybeUninit<*mut c_void> { let mut repr = MaybeUninit::uninit(); unsafe { @@ -253,21 +262,17 @@ unsafe impl UniquePtrTarget for CxxString { } repr } - #[doc(hidden)] unsafe fn __raw(raw: *mut Self) -> MaybeUninit<*mut c_void> { let mut repr = MaybeUninit::uninit(); unsafe { unique_ptr_std_string_raw(&mut repr, raw) } repr } - #[doc(hidden)] unsafe fn __get(repr: MaybeUninit<*mut c_void>) -> *const Self { unsafe { unique_ptr_std_string_get(&repr) } } - #[doc(hidden)] unsafe fn __release(mut repr: MaybeUninit<*mut c_void>) -> *mut Self { unsafe { unique_ptr_std_string_release(&mut repr) } } - #[doc(hidden)] unsafe fn __drop(mut repr: MaybeUninit<*mut c_void>) { unsafe { unique_ptr_std_string_drop(&mut repr) } } @@ -277,27 +282,21 @@ unsafe impl UniquePtrTarget for CxxVector where T: VectorElement, { - #[doc(hidden)] fn __typename(f: &mut fmt::Formatter) -> fmt::Result { write!(f, "CxxVector<{}>", display(T::__typename)) } - #[doc(hidden)] fn __null() -> MaybeUninit<*mut c_void> { T::__unique_ptr_null() } - #[doc(hidden)] unsafe fn __raw(raw: *mut Self) -> MaybeUninit<*mut c_void> { unsafe { T::__unique_ptr_raw(raw) } } - #[doc(hidden)] unsafe fn __get(repr: MaybeUninit<*mut c_void>) -> *const Self { unsafe { T::__unique_ptr_get(repr) } } - #[doc(hidden)] unsafe fn __release(repr: MaybeUninit<*mut c_void>) -> *mut Self { unsafe { T::__unique_ptr_release(repr) } } - #[doc(hidden)] unsafe fn __drop(repr: MaybeUninit<*mut c_void>) { unsafe { T::__unique_ptr_drop(repr) } } diff --git a/src/weak_ptr.rs b/src/weak_ptr.rs index 8a9f1a687..e9320f374 100644 --- a/src/weak_ptr.rs +++ b/src/weak_ptr.rs @@ -114,11 +114,9 @@ pub unsafe trait WeakPtrTarget { macro_rules! impl_weak_ptr_target { ($segment:expr, $name:expr, $ty:ty) => { unsafe impl WeakPtrTarget for $ty { - #[doc(hidden)] fn __typename(f: &mut fmt::Formatter) -> fmt::Result { f.write_str($name) } - #[doc(hidden)] unsafe fn __null(new: *mut c_void) { extern "C" { attr! { @@ -128,7 +126,6 @@ macro_rules! impl_weak_ptr_target { } unsafe { __null(new) } } - #[doc(hidden)] unsafe fn __clone(this: *const c_void, new: *mut c_void) { extern "C" { attr! { @@ -138,7 +135,6 @@ macro_rules! impl_weak_ptr_target { } unsafe { __clone(this, new) } } - #[doc(hidden)] unsafe fn __downgrade(shared: *const c_void, weak: *mut c_void) { extern "C" { attr! { @@ -148,7 +144,6 @@ macro_rules! impl_weak_ptr_target { } unsafe { __downgrade(shared, weak) } } - #[doc(hidden)] unsafe fn __upgrade(weak: *const c_void, shared: *mut c_void) { extern "C" { attr! { @@ -158,7 +153,6 @@ macro_rules! impl_weak_ptr_target { } unsafe { __upgrade(weak, shared) } } - #[doc(hidden)] unsafe fn __drop(this: *mut c_void) { extern "C" { attr! { diff --git a/syntax/attrs.rs b/syntax/attrs.rs index cb40295b9..46d010e0a 100644 --- a/syntax/attrs.rs +++ b/syntax/attrs.rs @@ -268,12 +268,17 @@ fn parse_rust_name_attribute(input: ParseStream) -> Result { } } +#[derive(Clone)] pub struct OtherAttrs(Vec); impl OtherAttrs { pub fn none() -> Self { OtherAttrs(Vec::new()) } + + pub fn extend(&mut self, other: Self) { + self.0.extend(other.0); + } } impl ToTokens for OtherAttrs { diff --git a/syntax/parse.rs b/syntax/parse.rs index dee24c2fa..1754c6006 100644 --- a/syntax/parse.rs +++ b/syntax/parse.rs @@ -360,7 +360,7 @@ fn parse_foreign_mod( let mut cfg = CfgExpr::Unconditional; let mut namespace = namespace.clone(); - attrs::parse( + let attrs = attrs::parse( cx, foreign_mod.attrs, attrs::Parser { @@ -374,11 +374,11 @@ fn parse_foreign_mod( for foreign in foreign_mod.items { match foreign { ForeignItem::Type(foreign) => { - let ety = parse_extern_type(cx, foreign, lang, trusted, &cfg, &namespace); + let ety = parse_extern_type(cx, foreign, lang, trusted, &cfg, &namespace, &attrs); items.push(ety); } ForeignItem::Fn(foreign) => { - match parse_extern_fn(cx, foreign, lang, trusted, &cfg, &namespace) { + match parse_extern_fn(cx, foreign, lang, trusted, &cfg, &namespace, &attrs) { Ok(efn) => items.push(efn), Err(err) => cx.push(err), } @@ -393,7 +393,7 @@ fn parse_foreign_mod( } } ForeignItem::Verbatim(tokens) => { - match parse_extern_verbatim(cx, tokens, lang, trusted, &cfg, &namespace) { + match parse_extern_verbatim(cx, tokens, lang, trusted, &cfg, &namespace, &attrs) { Ok(api) => items.push(api), Err(err) => cx.push(err), } @@ -463,6 +463,7 @@ fn parse_extern_type( trusted: bool, extern_block_cfg: &CfgExpr, namespace: &Namespace, + attrs: &OtherAttrs, ) -> Api { let mut cfg = extern_block_cfg.clone(); let mut doc = Doc::new(); @@ -470,7 +471,8 @@ fn parse_extern_type( let mut namespace = namespace.clone(); let mut cxx_name = None; let mut rust_name = None; - let attrs = attrs::parse( + let mut attrs = attrs.clone(); + attrs.extend(attrs::parse( cx, foreign_type.attrs, attrs::Parser { @@ -482,7 +484,7 @@ fn parse_extern_type( rust_name: Some(&mut rust_name), ..Default::default() }, - ); + )); let type_token = foreign_type.type_token; let visibility = visibility_pub(&foreign_type.vis, type_token.span); @@ -523,13 +525,15 @@ fn parse_extern_fn( trusted: bool, extern_block_cfg: &CfgExpr, namespace: &Namespace, + attrs: &OtherAttrs, ) -> Result { let mut cfg = extern_block_cfg.clone(); let mut doc = Doc::new(); let mut namespace = namespace.clone(); let mut cxx_name = None; let mut rust_name = None; - let attrs = attrs::parse( + let mut attrs = attrs.clone(); + attrs.extend(attrs::parse( cx, mem::take(&mut foreign_fn.attrs), attrs::Parser { @@ -540,7 +544,7 @@ fn parse_extern_fn( rust_name: Some(&mut rust_name), ..Default::default() }, - ); + )); let generics = &foreign_fn.sig.generics; if generics.where_clause.is_some() @@ -708,20 +712,22 @@ fn parse_extern_verbatim( trusted: bool, extern_block_cfg: &CfgExpr, namespace: &Namespace, + attrs: &OtherAttrs, ) -> Result { |input: ParseStream| -> Result { - let attrs = input.call(Attribute::parse_outer)?; + let unparsed_attrs = input.call(Attribute::parse_outer)?; let visibility: Visibility = input.parse()?; if input.peek(Token![type]) { parse_extern_verbatim_type( cx, - attrs, + unparsed_attrs, visibility, input, lang, trusted, extern_block_cfg, namespace, + attrs, ) } else if input.peek(Token![fn]) { parse_extern_verbatim_fn(input) @@ -738,13 +744,14 @@ fn parse_extern_verbatim( fn parse_extern_verbatim_type( cx: &mut Errors, - attrs: Vec, + unparsed_attrs: Vec, visibility: Visibility, input: ParseStream, lang: Lang, trusted: bool, extern_block_cfg: &CfgExpr, namespace: &Namespace, + attrs: &OtherAttrs, ) -> Result { let type_token: Token![type] = input.parse()?; let ident: Ident = input.parse()?; @@ -791,7 +798,7 @@ fn parse_extern_verbatim_type( // type Alias = crate::path::to::Type; parse_type_alias( cx, - attrs, + unparsed_attrs, visibility, type_token, ident, @@ -800,12 +807,13 @@ fn parse_extern_verbatim_type( lang, extern_block_cfg, namespace, + attrs, ) } else if lookahead.peek(Token![:]) || lookahead.peek(Token![;]) { // type Opaque: Bound2 + Bound2; parse_extern_type_bounded( cx, - attrs, + unparsed_attrs, visibility, type_token, ident, @@ -815,6 +823,7 @@ fn parse_extern_verbatim_type( trusted, extern_block_cfg, namespace, + attrs, ) } else { Err(lookahead.error()) @@ -829,7 +838,7 @@ fn parse_extern_verbatim_fn(input: ParseStream) -> Result { fn parse_type_alias( cx: &mut Errors, - attrs: Vec, + unparsed_attrs: Vec, visibility: Visibility, type_token: Token![type], ident: Ident, @@ -838,6 +847,7 @@ fn parse_type_alias( lang: Lang, extern_block_cfg: &CfgExpr, namespace: &Namespace, + attrs: &OtherAttrs, ) -> Result { let eq_token: Token![=] = input.parse()?; let ty: RustType = input.parse()?; @@ -849,9 +859,10 @@ fn parse_type_alias( let mut namespace = namespace.clone(); let mut cxx_name = None; let mut rust_name = None; - let attrs = attrs::parse( + let mut attrs = attrs.clone(); + attrs.extend(attrs::parse( cx, - attrs, + unparsed_attrs, attrs::Parser { cfg: Some(&mut cfg), doc: Some(&mut doc), @@ -861,7 +872,7 @@ fn parse_type_alias( rust_name: Some(&mut rust_name), ..Default::default() }, - ); + )); if lang == Lang::Rust { let span = quote!(#type_token #semi_token); @@ -889,7 +900,7 @@ fn parse_type_alias( fn parse_extern_type_bounded( cx: &mut Errors, - attrs: Vec, + unparsed_attrs: Vec, visibility: Visibility, type_token: Token![type], ident: Ident, @@ -899,6 +910,7 @@ fn parse_extern_type_bounded( trusted: bool, extern_block_cfg: &CfgExpr, namespace: &Namespace, + attrs: &OtherAttrs, ) -> Result { let mut bounds = Vec::new(); let colon_token: Option = input.parse()?; @@ -939,9 +951,10 @@ fn parse_extern_type_bounded( let mut namespace = namespace.clone(); let mut cxx_name = None; let mut rust_name = None; - let attrs = attrs::parse( + let mut attrs = attrs.clone(); + attrs.extend(attrs::parse( cx, - attrs, + unparsed_attrs, attrs::Parser { cfg: Some(&mut cfg), doc: Some(&mut doc), @@ -951,7 +964,7 @@ fn parse_extern_type_bounded( rust_name: Some(&mut rust_name), ..Default::default() }, - ); + )); let visibility = visibility_pub(&visibility, type_token.span); let name = pair(namespace, &ident, cxx_name, rust_name); diff --git a/tests/BUCK b/tests/BUCK index d131ddb99..d45accd74 100644 --- a/tests/BUCK +++ b/tests/BUCK @@ -3,6 +3,7 @@ load("//tools/buck:rust_cxx_bridge.bzl", "rust_cxx_bridge") rust_test( name = "test", srcs = ["test.rs"], + edition = "2018", deps = [ ":ffi", "//:cxx", @@ -17,6 +18,7 @@ rust_library( "ffi/module.rs", ], crate = "cxx_test_suite", + edition = "2018", deps = [ ":impl", "//:cxx", diff --git a/tests/BUILD b/tests/BUILD index 4803e13b4..3c25d9633 100644 --- a/tests/BUILD +++ b/tests/BUILD @@ -6,6 +6,7 @@ rust_test( name = "test", size = "small", srcs = ["test.rs"], + edition = "2018", deps = [ ":cxx_test_suite", "//:cxx", @@ -19,6 +20,7 @@ rust_library( "ffi/lib.rs", "ffi/module.rs", ], + edition = "2018", deps = [ ":impl", "//:cxx", diff --git a/tests/compiletest.rs b/tests/compiletest.rs index d2b516f5c..cd58514f1 100644 --- a/tests/compiletest.rs +++ b/tests/compiletest.rs @@ -1,5 +1,7 @@ +#[allow(unused_attributes)] #[rustversion::attr(not(nightly), ignore)] #[cfg_attr(skip_ui_tests, ignore)] +#[cfg_attr(miri, ignore)] #[test] fn ui() { let t = trybuild::TestCases::new(); diff --git a/tests/ffi/lib.rs b/tests/ffi/lib.rs index d58c8eba7..c3174bbca 100644 --- a/tests/ffi/lib.rs +++ b/tests/ffi/lib.rs @@ -1,5 +1,6 @@ #![allow( clippy::boxed_local, + clippy::derive_partial_eq_without_eq, clippy::just_underscores_and_digits, clippy::let_underscore_drop, clippy::missing_safety_doc, @@ -15,7 +16,7 @@ pub mod cast; pub mod module; -use cxx::{CxxString, CxxVector, SharedPtr, UniquePtr}; +use cxx::{type_id, CxxString, CxxVector, ExternType, SharedPtr, UniquePtr}; use std::fmt::{self, Display}; use std::mem::MaybeUninit; use std::os::raw::c_char; @@ -80,6 +81,7 @@ pub mod ffi { pub struct Array { a: [i32; 4], + b: Buffer, } #[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] @@ -248,6 +250,10 @@ pub mod ffi { CVal2, } + extern "C++" { + type Buffer = crate::Buffer; + } + extern "Rust" { type R; @@ -412,6 +418,15 @@ impl ffi::Array { } } +#[derive(Default)] +#[repr(C)] +pub struct Buffer([c_char; 12]); + +unsafe impl ExternType for Buffer { + type Id = type_id!("tests::Buffer"); + type Kind = cxx::kind::Trivial; +} + #[derive(Debug)] struct Error; diff --git a/tests/ffi/tests.h b/tests/ffi/tests.h index e508a3f58..10cb37ae5 100644 --- a/tests/ffi/tests.h +++ b/tests/ffi/tests.h @@ -84,6 +84,8 @@ struct Borrow { const std::string &s; }; +typedef char Buffer[12]; + size_t c_return_primitive(); Shared c_return_shared(); ::A::AShared c_return_ns_shared(); diff --git a/tests/test.rs b/tests/test.rs index 13ce3456c..24d330bad 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -261,7 +261,10 @@ fn test_c_method_calls() { assert_eq!(2023, *ffi::Shared { z: 2023 }.c_method_mut_on_shared()); let val = 42; - let mut array = ffi::Array { a: [0, 0, 0, 0] }; + let mut array = ffi::Array { + a: [0, 0, 0, 0], + b: ffi::Buffer::default(), + }; array.c_set_array(val); assert_eq!(array.a.len() as i32 * val, array.r_get_array_sum()); } @@ -280,6 +283,31 @@ fn test_shared_ptr_weak_ptr() { assert!(weak_ptr.upgrade().is_null()); } +#[test] +fn test_unique_to_shared_ptr_string() { + let unique = ffi::c_return_unique_ptr_string(); + let ptr = &*unique as *const _; + let shared = unique.to_shared(); + assert_eq!(&*shared as *const _, ptr); + assert_eq!(&*shared, "2020"); +} + +#[test] +fn test_unique_to_shared_ptr_cpp_type() { + let unique = ffi::c_return_unique_ptr(); + let ptr = &*unique as *const _; + let shared = unique.to_shared(); + assert_eq!(&*shared as *const _, ptr); +} + +#[test] +fn test_unique_to_shared_ptr_null() { + let unique = cxx::UniquePtr::::null(); + assert!(unique.is_null()); + let shared = unique.to_shared(); + assert!(shared.is_null()); +} + #[test] fn test_c_ns_method_calls() { let unique_ptr = ffi2::ns_c_return_unique_ptr_ns(); diff --git a/tests/ui/deny_elided_lifetimes.stderr b/tests/ui/deny_elided_lifetimes.stderr index 8b965af36..857bb5b7f 100644 --- a/tests/ui/deny_elided_lifetimes.stderr +++ b/tests/ui/deny_elided_lifetimes.stderr @@ -2,14 +2,14 @@ error: hidden lifetime parameters in types are deprecated --> tests/ui/deny_elided_lifetimes.rs:21:50 | 21 | fn lifetime_elided(s: &i32) -> UniquePtr; - | ^^^ expected named lifetime parameter + | ^^^ expected lifetime parameter | note: the lint level is defined here --> tests/ui/deny_elided_lifetimes.rs:1:9 | 1 | #![deny(elided_lifetimes_in_paths)] | ^^^^^^^^^^^^^^^^^^^^^^^^^ -help: consider using the `'_` lifetime +help: indicate the anonymous lifetime | 21 | fn lifetime_elided(s: &i32) -> UniquePtr>; - | ~~~~~~~ + | ++++ diff --git a/tests/ui/deny_missing_docs.stderr b/tests/ui/deny_missing_docs.stderr index 8f4c191dc..54ab987b4 100644 --- a/tests/ui/deny_missing_docs.stderr +++ b/tests/ui/deny_missing_docs.stderr @@ -38,10 +38,10 @@ error: missing documentation for a type alias --> tests/ui/deny_missing_docs.rs:49:9 | 49 | pub type UndocumentedTypeAlias = crate::bindgen::UndocumentedTypeAlias; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: missing documentation for a function --> tests/ui/deny_missing_docs.rs:54:9 | 54 | pub fn undocumented_foreign_fn() -> u8; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/enum_match_without_wildcard.stderr b/tests/ui/enum_match_without_wildcard.stderr index 033c2c9f1..3a7b32051 100644 --- a/tests/ui/enum_match_without_wildcard.stderr +++ b/tests/ui/enum_match_without_wildcard.stderr @@ -1,11 +1,17 @@ error[E0004]: non-exhaustive patterns: `A { repr: 2_u8..=u8::MAX }` not covered --> tests/ui/enum_match_without_wildcard.rs:12:11 | -3 | enum A { - | ------ `ffi::A` defined here -... 12 | match a { | ^ pattern `A { repr: 2_u8..=u8::MAX }` not covered | - = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms +note: `ffi::A` defined here + --> tests/ui/enum_match_without_wildcard.rs:3:10 + | +3 | enum A { + | ^ = note: the matched value is of type `ffi::A` +help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown + | +14 ~ ffi::A::FieldB => 2021, +15 ~ A { repr: 2_u8..=u8::MAX } => todo!(), + | diff --git a/tests/ui/nonlocal_rust_type.stderr b/tests/ui/nonlocal_rust_type.stderr index dc510d894..dee91955f 100644 --- a/tests/ui/nonlocal_rust_type.stderr +++ b/tests/ui/nonlocal_rust_type.stderr @@ -1,4 +1,4 @@ -error[E0117]: only traits defined in the current crate can be implemented for arbitrary types +error[E0117]: only traits defined in the current crate can be implemented for types defined outside of the crate --> tests/ui/nonlocal_rust_type.rs:10:9 | 10 | type OptBuilder<'a>; @@ -9,7 +9,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ar | = note: define and implement a trait or new type instead -error[E0117]: only traits defined in the current crate can be implemented for arbitrary types +error[E0117]: only traits defined in the current crate can be implemented for types defined outside of the crate --> tests/ui/nonlocal_rust_type.rs:14:13 | 14 | rs: Box>, diff --git a/tests/ui/unique_ptr_twice.stderr b/tests/ui/unique_ptr_twice.stderr index a3ed0d611..1315e0644 100644 --- a/tests/ui/unique_ptr_twice.stderr +++ b/tests/ui/unique_ptr_twice.stderr @@ -2,7 +2,7 @@ error[E0119]: conflicting implementations of trait `cxx::memory::UniquePtrTarget --> tests/ui/unique_ptr_twice.rs:16:5 | 7 | impl UniquePtr {} - | ----------------- first implementation here + | ---------------- first implementation here ... 16 | impl UniquePtr {} - | ^^^^^^^^^^^^^^^^^ conflicting implementation for `here::C` + | ^^^^^^^^^^^^^^^^ conflicting implementation for `here::C` diff --git a/tests/ui/unpin_impl.rs b/tests/ui/unpin_impl.rs deleted file mode 100644 index 129fcb11d..000000000 --- a/tests/ui/unpin_impl.rs +++ /dev/null @@ -1,10 +0,0 @@ -#[cxx::bridge] -mod ffi { - extern "C++" { - type Opaque; - } -} - -impl Unpin for ffi::Opaque {} - -fn main() {} diff --git a/tests/ui/unpin_impl.stderr b/tests/ui/unpin_impl.stderr deleted file mode 100644 index afe5a8066..000000000 --- a/tests/ui/unpin_impl.stderr +++ /dev/null @@ -1,18 +0,0 @@ -error[E0282]: type annotations needed - --> tests/ui/unpin_impl.rs:4:14 - | -4 | type Opaque; - | ^^^^^^ cannot infer type - -error[E0283]: type annotations needed - --> tests/ui/unpin_impl.rs:1:1 - | -1 | #[cxx::bridge] - | ^^^^^^^^^^^^^^ cannot infer type - | -note: multiple `impl`s satisfying `ffi::Opaque: __AmbiguousIfImpl<_>` found - --> tests/ui/unpin_impl.rs:1:1 - | -1 | #[cxx::bridge] - | ^^^^^^^^^^^^^^ - = note: this error originates in the attribute macro `cxx::bridge` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui/unsupported_elided.stderr b/tests/ui/unsupported_elided.stderr index e9ea87b06..2fa0d0591 100644 --- a/tests/ui/unsupported_elided.stderr +++ b/tests/ui/unsupported_elided.stderr @@ -2,9 +2,13 @@ error[E0726]: implicit elided lifetime not allowed here --> tests/ui/unsupported_elided.rs:6:14 | 6 | type T; - | ^- help: indicate the anonymous lifetime: `<'_>` + | ^ expected lifetime parameter | = note: assuming a `'static` lifetime... +help: indicate the anonymous lifetime + | +6 | type T<'_>; + | ++++ error[E0106]: missing lifetime specifier --> tests/ui/unsupported_elided.rs:8:24 diff --git a/third-party/BUCK b/third-party/BUCK index ffc078d07..85397f861 100644 --- a/third-party/BUCK +++ b/third-party/BUCK @@ -5,30 +5,43 @@ load("//tools/buck:rust_library.bzl", "rust_library") rust_library( name = "bitflags", srcs = glob(["vendor/bitflags-1.3.2/src/**"]), + edition = "2018", ) rust_library( name = "cc", - srcs = glob(["vendor/cc-1.0.72/src/**"]), + srcs = glob(["vendor/cc-1.0.73/src/**"]), + edition = "2018", visibility = ["PUBLIC"], ) rust_library( name = "clap", - srcs = glob(["vendor/clap-3.0.10/src/**"]), + srcs = glob(["vendor/clap-3.2.8/src/**"]), + edition = "2021", features = ["std"], visibility = ["PUBLIC"], deps = [ ":bitflags", + ":clap_lex", ":indexmap", - ":os_str_bytes", ":textwrap", ], ) +rust_library( + name = "clap_lex", + srcs = glob(["vendor/clap_lex-0.2.4/src/**"]), + edition = "2021", + deps = [ + ":os_str_bytes", + ], +) + rust_library( name = "codespan-reporting", srcs = glob(["vendor/codespan-reporting-0.11.1/src/**"]), + edition = "2018", visibility = ["PUBLIC"], deps = [ ":termcolor", @@ -38,28 +51,24 @@ rust_library( rust_library( name = "hashbrown", - srcs = glob(["vendor/hashbrown-0.11.2/src/**"]), + srcs = glob(["vendor/hashbrown-0.12.1/src/**"]), + edition = "2021", features = ["raw"], ) rust_library( name = "indexmap", - srcs = glob(["vendor/indexmap-1.8.0/src/**"]), + srcs = glob(["vendor/indexmap-1.9.1/src/**"]), + edition = "2021", features = ["std"], rustc_flags = ["--cfg=has_std"], deps = [":hashbrown"], ) -rust_library( - name = "memchr", - srcs = glob(["vendor/memchr-2.4.1/src/**"]), - crate_root = "vendor/memchr-2.4.1/src/lib.rs", - features = ["std"], -) - rust_library( name = "once_cell", - srcs = glob(["vendor/once_cell-1.9.0/src/**"]), + srcs = glob(["vendor/once_cell-1.13.0/src/**"]), + edition = "2018", features = [ "alloc", "std", @@ -69,29 +78,31 @@ rust_library( rust_library( name = "os_str_bytes", - srcs = glob(["vendor/os_str_bytes-6.0.0/src/**"]), + srcs = glob(["vendor/os_str_bytes-6.1.0/src/**"]), + edition = "2018", features = [ - "memchr", "raw_os_str", ], - deps = [":memchr"], ) rust_library( name = "proc-macro2", - srcs = glob(["vendor/proc-macro2-1.0.36/src/**"]), - build_script = "vendor/proc-macro2-1.0.36/build.rs", + srcs = glob(["vendor/proc-macro2-1.0.40/src/**"]), + build_script = "vendor/proc-macro2-1.0.40/build.rs", + edition = "2018", features = [ "proc-macro", "span-locations", ], visibility = ["PUBLIC"], - deps = [":unicode-xid"], + deps = [":unicode-ident"], ) rust_library( name = "quote", - srcs = glob(["vendor/quote-1.0.14/src/**"]), + srcs = glob(["vendor/quote-1.0.20/src/**"]), + build_script = "vendor/quote-1.0.20/build.rs", + edition = "2018", features = ["proc-macro"], visibility = ["PUBLIC"], deps = [":proc-macro2"], @@ -100,14 +111,16 @@ rust_library( rust_library( name = "scratch", srcs = glob(["vendor/scratch-1.0.1/src/**"]), + edition = "2018", env = {"OUT_DIR": ""}, visibility = ["PUBLIC"], ) rust_library( name = "syn", - srcs = glob(["vendor/syn-1.0.85/src/**"]), - build_script = "vendor/syn-1.0.85/build.rs", + srcs = glob(["vendor/syn-1.0.98/src/**"]), + build_script = "vendor/syn-1.0.98/build.rs", + edition = "2018", features = [ "clone-impls", "derive", @@ -120,27 +133,31 @@ rust_library( deps = [ ":proc-macro2", ":quote", - ":unicode-xid", + ":unicode-ident", ], ) rust_library( name = "termcolor", - srcs = glob(["vendor/termcolor-1.1.2/src/**"]), + srcs = glob(["vendor/termcolor-1.1.3/src/**"]), + edition = "2018", ) rust_library( name = "textwrap", - srcs = glob(["vendor/textwrap-0.14.2/src/**"]), + srcs = glob(["vendor/textwrap-0.15.0/src/**"]), + edition = "2018", deps = [":unicode-width"], ) rust_library( - name = "unicode-width", - srcs = glob(["vendor/unicode-width-0.1.9/src/**"]), + name = "unicode-ident", + srcs = glob(["vendor/unicode-ident-1.0.1/src/**"]), + edition = "2018", ) rust_library( - name = "unicode-xid", - srcs = glob(["vendor/unicode-xid-0.2.2/src/**"]), + name = "unicode-width", + srcs = glob(["vendor/unicode-width-0.1.9/src/**"]), + edition = "2018", ) diff --git a/third-party/BUILD b/third-party/BUILD index d83083618..aa79da3d0 100644 --- a/third-party/BUILD +++ b/third-party/BUILD @@ -8,30 +8,43 @@ load( rust_library( name = "bitflags", srcs = glob(["vendor/bitflags-1.3.2/src/**"]), + edition = "2018", ) rust_library( name = "cc", - srcs = glob(["vendor/cc-1.0.72/src/**"]), + srcs = glob(["vendor/cc-1.0.73/src/**"]), + edition = "2018", visibility = ["//visibility:public"], ) rust_library( name = "clap", - srcs = glob(["vendor/clap-3.0.10/src/**"]), + srcs = glob(["vendor/clap-3.2.8/src/**"]), crate_features = ["std"], + edition = "2021", visibility = ["//visibility:public"], deps = [ ":bitflags", + ":clap_lex", ":indexmap", - ":os_str_bytes", ":textwrap", ], ) +rust_library( + name = "clap_lex", + srcs = glob(["vendor/clap_lex-0.2.4/src/**"]), + edition = "2021", + deps = [ + ":os_str_bytes", + ], +) + rust_library( name = "codespan-reporting", srcs = glob(["vendor/codespan-reporting-0.11.1/src/**"]), + edition = "2018", visibility = ["//visibility:public"], deps = [ ":termcolor", @@ -41,86 +54,97 @@ rust_library( rust_library( name = "hashbrown", - srcs = glob(["vendor/hashbrown-0.11.2/src/**"]), + srcs = glob(["vendor/hashbrown-0.12.1/src/**"]), crate_features = ["raw"], + edition = "2021", ) rust_library( name = "indexmap", - srcs = glob(["vendor/indexmap-1.8.0/src/**"]), + srcs = glob(["vendor/indexmap-1.9.1/src/**"]), crate_features = ["std"], + edition = "2021", rustc_flags = ["--cfg=has_std"], deps = [":hashbrown"], ) -rust_library( - name = "memchr", - srcs = glob(["vendor/memchr-2.4.1/src/**/*.rs"]), - crate_features = ["std"], -) - rust_library( name = "once_cell", - srcs = glob(["vendor/once_cell-1.9.0/src/**"]), + srcs = glob(["vendor/once_cell-1.13.0/src/**"]), crate_features = [ "alloc", "std", ], + edition = "2018", visibility = ["//visibility:public"], ) rust_library( name = "os_str_bytes", - srcs = glob(["vendor/os_str_bytes-6.0.0/src/**"]), + srcs = glob(["vendor/os_str_bytes-6.1.0/src/**"]), crate_features = [ - "memchr", "raw_os_str", ], - deps = [":memchr"], + edition = "2018", ) rust_library( name = "proc-macro2", - srcs = glob(["vendor/proc-macro2-1.0.36/src/**"]), + srcs = glob(["vendor/proc-macro2-1.0.40/src/**"]), crate_features = [ "proc-macro", "span-locations", ], + edition = "2018", visibility = ["//visibility:public"], deps = [ ":proc-macro2@build", - ":unicode-xid", + ":unicode-ident", ], ) cargo_build_script( name = "proc-macro2@build", - srcs = ["vendor/proc-macro2-1.0.36/build.rs"], + srcs = ["vendor/proc-macro2-1.0.40/build.rs"], crate_features = [ "proc-macro", "span-locations", ], crate_name = "build", + edition = "2018", ) rust_library( name = "quote", - srcs = glob(["vendor/quote-1.0.14/src/**"]), + srcs = glob(["vendor/quote-1.0.20/src/**"]), crate_features = ["proc-macro"], + edition = "2018", visibility = ["//visibility:public"], - deps = [":proc-macro2"], + deps = [ + ":proc-macro2", + ":quote@build", + ], +) + +cargo_build_script( + name = "quote@build", + srcs = ["vendor/quote-1.0.20/build.rs"], + crate_features = ["proc-macro"], + crate_name = "build", + edition = "2018", ) rust_library( name = "scratch", srcs = glob(["vendor/scratch-1.0.1/src/**"]), + edition = "2018", rustc_env = {"OUT_DIR": ""}, visibility = ["//visibility:public"], ) rust_library( name = "syn", - srcs = glob(["vendor/syn-1.0.85/src/**"]), + srcs = glob(["vendor/syn-1.0.98/src/**"]), crate_features = [ "clone-impls", "derive", @@ -129,18 +153,19 @@ rust_library( "printing", "proc-macro", ], + edition = "2018", visibility = ["//visibility:public"], deps = [ ":proc-macro2", ":quote", ":syn@build", - ":unicode-xid", + ":unicode-ident", ], ) cargo_build_script( name = "syn@build", - srcs = ["vendor/syn-1.0.85/build.rs"], + srcs = ["vendor/syn-1.0.98/build.rs"], crate_features = [ "clone-impls", "derive", @@ -150,25 +175,30 @@ cargo_build_script( "proc-macro", ], crate_name = "build", + edition = "2018", ) rust_library( name = "termcolor", - srcs = glob(["vendor/termcolor-1.1.2/src/**"]), + srcs = glob(["vendor/termcolor-1.1.3/src/**"]), + edition = "2018", ) rust_library( name = "textwrap", - srcs = glob(["vendor/textwrap-0.14.2/src/**"]), + srcs = glob(["vendor/textwrap-0.15.0/src/**"]), + edition = "2018", deps = [":unicode-width"], ) rust_library( - name = "unicode-width", - srcs = glob(["vendor/unicode-width-0.1.9/src/**"]), + name = "unicode-ident", + srcs = glob(["vendor/unicode-ident-1.0.1/src/**"]), + edition = "2018", ) rust_library( - name = "unicode-xid", - srcs = glob(["vendor/unicode-xid-0.2.2/src/**"]), + name = "unicode-width", + srcs = glob(["vendor/unicode-width-0.1.9/src/**"]), + edition = "2018", ) diff --git a/third-party/Cargo.lock b/third-party/Cargo.lock index 5b741be41..725100655 100644 --- a/third-party/Cargo.lock +++ b/third-party/Cargo.lock @@ -10,9 +10,9 @@ checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" [[package]] name = "autocfg" -version = "1.0.1" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "bitflags" @@ -22,9 +22,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "cc" -version = "1.0.72" +version = "1.0.73" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22a9137b95ea06864e018375b72adfb7db6e6f68cfc8df5a04d00288050485ee" +checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11" dependencies = [ "jobserver", ] @@ -37,26 +37,35 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "clang-ast" -version = "0.1.6" +version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eed6681036a96f9855a75b08a9f14199e212017508a967d1d1e868f575f7d8e9" +checksum = "d9c380e0de48337007dfc91b09eb75f567f5f08209437857fbaabbaf2e77e830" dependencies = [ "serde", ] [[package]] name = "clap" -version = "3.0.10" +version = "3.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a30c3bf9ff12dfe5dae53f0a96e0febcd18420d1c0e7fad77796d9d5c4b5375" +checksum = "190814073e85d238f31ff738fcb0bf6910cedeb73376c87cd69291028966fd83" dependencies = [ "bitflags", + "clap_lex", "indexmap", - "os_str_bytes", "strsim", "textwrap", ] +[[package]] +name = "clap_lex" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5" +dependencies = [ + "os_str_bytes", +] + [[package]] name = "codespan-reporting" version = "0.11.1" @@ -69,16 +78,16 @@ dependencies = [ [[package]] name = "crc32fast" -version = "1.3.0" +version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "738c290dfaea84fc1ca15ad9c168d083b05a714e1efddd8edaab678dc28d2836" +checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d" dependencies = [ "cfg-if", ] [[package]] name = "cxx" -version = "1.0.63" +version = "1.0.71" dependencies = [ "cc", "cxx-build", @@ -93,7 +102,7 @@ dependencies = [ [[package]] name = "cxx-build" -version = "1.0.63" +version = "1.0.71" dependencies = [ "cc", "codespan-reporting", @@ -108,7 +117,7 @@ dependencies = [ [[package]] name = "cxx-gen" -version = "0.7.63" +version = "0.7.71" dependencies = [ "codespan-reporting", "proc-macro2", @@ -127,7 +136,7 @@ dependencies = [ [[package]] name = "cxxbridge-cmd" -version = "1.0.63" +version = "1.0.71" dependencies = [ "clap", "codespan-reporting", @@ -138,11 +147,11 @@ dependencies = [ [[package]] name = "cxxbridge-flags" -version = "1.0.63" +version = "1.0.71" [[package]] name = "cxxbridge-macro" -version = "1.0.63" +version = "1.0.71" dependencies = [ "clang-ast", "cxx", @@ -165,19 +174,17 @@ dependencies = [ [[package]] name = "dissimilar" -version = "1.0.3" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31ad93652f40969dead8d4bf897a41e9462095152eb21c56e5830537e41179dd" +checksum = "8c97b9233581d84b8e1e689cdd3a47b6f69770084fc246e86a7f78b0d9c1d4a5" [[package]] name = "flate2" -version = "1.0.22" +version = "1.0.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e6988e897c1c9c485f43b47a529cef42fde0547f9d8d41a7062518f1d8fc53f" +checksum = "f82b0f4c27ad9f8bfd1f3208d882da2b09c301bc1c828fd3a00d0216d2fbbff6" dependencies = [ - "cfg-if", "crc32fast", - "libc", "miniz_oxide", ] @@ -189,15 +196,15 @@ checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" [[package]] name = "hashbrown" -version = "0.11.2" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" +checksum = "db0d4cf898abf0081f964436dc980e96670a0f36863e4b83aaacdb65c9d7ccc3" [[package]] name = "indexmap" -version = "1.8.0" +version = "1.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "282a6247722caba404c065016bbfa522806e51714c34f5dfc3e4a3a46fcb4223" +checksum = "10a35a97730320ffe8e2d410b5d3b69279b98d2c14bdb8b70ea89ecf7888d41e" dependencies = [ "autocfg", "hashbrown", @@ -205,9 +212,9 @@ dependencies = [ [[package]] name = "itoa" -version = "1.0.1" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1aab8fc367588b89dcee83ab0fd66b72b50b72fa1904d7095045ace2b0c81c35" +checksum = "112c678d4050afce233f4f2852bb2eb519230b3cf12f33585275537d7e41578d" [[package]] name = "jobserver" @@ -220,9 +227,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.112" +version = "0.2.126" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b03d17f364a3a042d5e5d46b053bbbf82c92c9430c592dd4c064dc6ee997125" +checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836" [[package]] name = "link-cplusplus" @@ -233,12 +240,6 @@ dependencies = [ "cc", ] -[[package]] -name = "memchr" -version = "2.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a" - [[package]] name = "memmap" version = "0.7.0" @@ -251,64 +252,60 @@ dependencies = [ [[package]] name = "miniz_oxide" -version = "0.4.4" +version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a92518e98c078586bc6c934028adcca4c92a53d6a958196de835170a01d84e4b" +checksum = "6f5c75688da582b8ffc1f1799e9db273f32133c49e048f614d22ec3256773ccc" dependencies = [ "adler", - "autocfg", ] [[package]] name = "once_cell" -version = "1.9.0" +version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da32515d9f6e6e489d7bc9d84c71b060db7247dc035bbe44eac88cf87486d8d5" +checksum = "18a6dbe30758c9f83eb00cbea4ac95966305f5a7772f3f42ebfc7fc7eddbd8e1" [[package]] name = "os_str_bytes" -version = "6.0.0" +version = "6.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e22443d1643a904602595ba1cd8f7d896afe56d26712531c5ff73a15b2fbf64" -dependencies = [ - "memchr", -] +checksum = "21326818e99cfe6ce1e524c2a805c189a99b5ae555a35d19f9a284b427d86afa" [[package]] name = "pkg-config" -version = "0.3.24" +version = "0.3.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58893f751c9b0412871a09abd62ecd2a00298c6c83befa223ef98c52aef40cbe" +checksum = "1df8c4ec4b0627e53bdf214615ad287367e482558cf84b109250b37464dc03ae" [[package]] name = "proc-macro2" -version = "1.0.36" +version = "1.0.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7342d5883fbccae1cc37a2353b09c87c9b0f3afd73f5fb9bba687a1f733b029" +checksum = "dd96a1e8ed2596c337f8eae5f24924ec83f5ad5ab21ea8e455d3566c69fbcaf7" dependencies = [ - "unicode-xid", + "unicode-ident", ] [[package]] name = "quote" -version = "1.0.14" +version = "1.0.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "47aa80447ce4daf1717500037052af176af5d38cc3e571d9ec1c7353fc10c87d" +checksum = "3bcdf212e9776fbcb2d23ab029360416bb1706b1aea2d1a5ba002727cbcab804" dependencies = [ "proc-macro2", ] [[package]] name = "rustversion" -version = "1.0.6" +version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2cc38e8fa666e2de3c4aba7edeb5ffc5246c1c2ed0e3d17e560aeeba736b23f" +checksum = "a0a5f7c728f5d284929a1cccb5bc19884422bfe6ef4d6c409da2c41838983fcf" [[package]] name = "ryu" -version = "1.0.9" +version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73b4b750c782965c211b42f022f59af1fbceabdd026623714f104152f1ec149f" +checksum = "f3f6f92acf49d1b98f7a81226834412ada05458b7364277387724a237f062695" [[package]] name = "scratch" @@ -318,18 +315,18 @@ checksum = "96311ef4a16462c757bb6a39152c40f58f31cd2602a40fceb937e2bc34e6cbab" [[package]] name = "serde" -version = "1.0.133" +version = "1.0.138" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97565067517b60e2d1ea8b268e59ce036de907ac523ad83a0475da04e818989a" +checksum = "1578c6245786b9d168c5447eeacfb96856573ca56c9d68fdcf394be134882a47" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.133" +version = "1.0.138" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed201699328568d8d08208fdd080e3ff594e6c422e438b6705905da01005d537" +checksum = "023e9b1467aef8a10fb88f25611870ada9800ef7e22afce356bb0d2387b6f27c" dependencies = [ "proc-macro2", "quote", @@ -338,9 +335,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.75" +version = "1.0.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c059c05b48c5c0067d4b4b2b4f0732dd65feb52daf7e0ea09cd87e7dadc1af79" +checksum = "82c2c1fdcd807d1098552c5b9a36e425e42e9fbd7c6a37a8425f390f781f7fa7" dependencies = [ "itoa", "ryu", @@ -355,65 +352,66 @@ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] name = "syn" -version = "1.0.85" +version = "1.0.98" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a684ac3dcd8913827e18cd09a68384ee66c1de24157e3c556c9ab16d85695fb7" +checksum = "c50aef8a904de4c23c788f104b7dddc7d6f79c647c7c8ce4cc8f73eb0ca773dd" dependencies = [ "proc-macro2", "quote", - "unicode-xid", + "unicode-ident", ] [[package]] name = "termcolor" -version = "1.1.2" +version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dfed899f0eb03f32ee8c6a0aabdb8a7949659e3466561fc0adf54e26d88c5f4" +checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755" dependencies = [ "winapi-util", ] [[package]] name = "textwrap" -version = "0.14.2" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0066c8d12af8b5acd21e00547c3797fde4e8677254a7ee429176ccebbe93dd80" +checksum = "b1141d4d61095b28419e22cb0bbf02755f5e54e0526f97f1e3d1d160e60885fb" [[package]] name = "toml" -version = "0.5.8" +version = "0.5.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a31142970826733df8241ef35dc040ef98c679ab14d7c3e54d827099b3acecaa" +checksum = "8d82e1a7758622a465f8cee077614c73484dac5b836c02ff6a40d5d1010324d7" dependencies = [ "serde", ] [[package]] name = "trybuild" -version = "1.0.54" +version = "1.0.63" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f04343ff86b62ca40bd5dca986aadf4f10c152a9ebe9a869e456b60fa85afd3f" +checksum = "764b9e244b482a9b81bde596aa37aa6f1347bf8007adab25e59f901b32b4e0a0" dependencies = [ "dissimilar", "glob", "once_cell", "serde", + "serde_derive", "serde_json", "termcolor", "toml", ] [[package]] -name = "unicode-width" -version = "0.1.9" +name = "unicode-ident" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973" +checksum = "5bd2fe26506023ed7b5e1e315add59d6f584c621d037f9368fea9cfb988f368c" [[package]] -name = "unicode-xid" -version = "0.2.2" +name = "unicode-width" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" +checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973" [[package]] name = "winapi" diff --git a/tools/bazel/vendor.bzl b/tools/bazel/vendor.bzl index 284705e59..b4dd253ee 100644 --- a/tools/bazel/vendor.bzl +++ b/tools/bazel/vendor.bzl @@ -2,8 +2,9 @@ of a crate in the current workspace. """ -load("@rules_rust//rust:repositories.bzl", "load_arbitrary_tool") load("@rules_rust//rust:defs.bzl", "rust_common") +load("@rules_rust//rust:repositories.bzl", "load_arbitrary_tool") +load("@rules_rust//rust/platform:triple.bzl", "get_host_triple") def _impl(repository_ctx): # Link cxx repository into @third-party. @@ -20,12 +21,8 @@ def _impl(repository_ctx): # Figure out which version of cargo to use. if repository_ctx.attr.target_triple: target_triple = repository_ctx.attr.target_triple - elif "mac" in repository_ctx.os.name: - target_triple = "x86_64-apple-darwin" - elif "windows" in repository_ctx.os.name: - target_triple = "x86_64-pc-windows-msvc" else: - target_triple = "x86_64-unknown-linux-gnu" + target_triple = get_host_triple(repository_ctx).str # Download cargo. load_arbitrary_tool( @@ -78,7 +75,6 @@ vendor = repository_rule( attrs = { "cargo_version": attr.string( doc = "The version of cargo to use", - default = rust_common.default_version, ), "cargo_iso_date": attr.string( doc = "The date of the tool (or None, if the version is a specific version)", diff --git a/tools/buck/rust_library.bzl b/tools/buck/rust_library.bzl index 67ec2ac7e..4c85614d6 100644 --- a/tools/buck/rust_library.bzl +++ b/tools/buck/rust_library.bzl @@ -3,6 +3,7 @@ load("//tools/buck:genrule.bzl", "genrule") def rust_library( name, srcs, + edition, features = [], rustc_flags = [], build_script = None, @@ -13,6 +14,7 @@ def rust_library( srcs = srcs + [build_script], crate = "build", crate_root = build_script, + edition = edition, features = features, rustc_flags = rustc_flags, ) @@ -28,6 +30,7 @@ def rust_library( native.rust_library( name = name, srcs = srcs, + edition = edition, features = features, rustc_flags = rustc_flags, **kwargs