diff options
author | Andrew Walbran <qwandor@google.com> | 2023-01-11 11:58:20 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2023-01-11 11:58:20 +0000 |
commit | 90369c8322fab0903ee7385f5e75c0df6e0f73a5 (patch) | |
tree | edb871f12951b9c65b2661b21d38f9109ab3c313 | |
parent | 0909095df84785c028bb70769f8e0ea421ce1895 (diff) | |
parent | d31079a3e06e145772e25a917b7c2147cabefced (diff) | |
download | cxx-90369c8322fab0903ee7385f5e75c0df6e0f73a5.tar.gz |
Update to 1.0.85. am: 12c0b318be am: 875cdfece6 am: d31079a3e0
Original change: https://android-review.googlesource.com/c/platform/external/rust/cxx/+/2376028
Change-Id: I167bbdb0e6f1f6c003cfc77e38355212c6cc4eb0
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
72 files changed, 1277 insertions, 890 deletions
diff --git a/.bazelignore b/.bazelignore index 2f7896d1..c42dab31 100644 --- a/.bazelignore +++ b/.bazelignore @@ -1 +1,2 @@ target/ +tools/buck/buck2/ diff --git a/.buckconfig b/.buckconfig index 570a844e..045974f7 100644 --- a/.buckconfig +++ b/.buckconfig @@ -1,23 +1,17 @@ -[project] - # We use some symlinks in the source tree, but they get eliminated by `cargo - # publish` and `cargo vendor` so this allow_symlinks setting should not be - # required downstream. - allow_symlinks = allow - - # Hide BUCK files under target/package/ from `buck build ...`. Otherwise: - # $ buck build ... - # //target/package/cxx-0.3.0/tests:ffi references non-existing file or directory 'target/package/cxx-0.3.0/tests/ffi/lib.rs' - ignore = target +[repositories] +repo = . +prelude = tools/buck/prelude +toolchains = tools/buck/toolchains +ovr_config = tools/buck/prelude +buck = none +fbcode = none +fbsource = none -[cxx] - cxxflags = -std=c++11 - -[rust] - default_edition = required - rustc_flags = \ - -Clink-arg=-fuse-ld=lld \ - -Crelocation-model=dynamic-no-pic \ - --cap-lints=allow +[project] +# Hide BUCK files under target/package/ from `buck build ...`. Otherwise: +# $ buck build ... +# //target/package/cxx-0.3.0/tests:ffi references non-existing file or directory 'target/package/cxx-0.3.0/tests/ffi/lib.rs' +ignore = target -[defaults.rust_library] - type = check +[parser] +target_platform_detector_spec = target://...->ovr_config//platforms:default diff --git a/.buckversion b/.buckversion deleted file mode 100644 index b25fa3fc..00000000 --- a/.buckversion +++ /dev/null @@ -1 +0,0 @@ -last diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000..f9f0dca7 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +third-party/BUCK linguist-generated diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 59ccfc63..93feb348 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,8 +19,7 @@ jobs: - rust: nightly - rust: beta - rust: stable - - rust: 1.57.0 - - rust: 1.56.0 + - rust: 1.60.0 - name: macOS rust: nightly os: macos @@ -31,6 +30,7 @@ jobs: env: CXXFLAGS: ${{matrix.flags}} RUSTFLAGS: --cfg deny_warnings -Dwarnings + timeout-minutes: 45 steps: - name: Enable symlinks (windows) if: matrix.os == 'windows' @@ -48,7 +48,7 @@ jobs: # builds. run: | echo RUSTFLAGS=$RUSTFLAGS >> $GITHUB_ENV - echo ::set-output name=exclude::--exclude cxx-test-suite ${{matrix.rust == '1.56.0' && '--exclude cxxbridge-cmd' || ''}} + echo exclude=--exclude cxx-test-suite >> $GITHUB_OUTPUT env: RUSTFLAGS: ${{env.RUSTFLAGS}} ${{matrix.os && github.event_name != 'schedule' && '--cfg skip_ui_tests' || ''}} id: testsuite @@ -66,33 +66,31 @@ jobs: name: Buck runs-on: ubuntu-latest if: github.event_name != 'pull_request' + timeout-minutes: 45 steps: - uses: actions/checkout@v3 - - uses: dtolnay/rust-toolchain@stable - - uses: actions/setup-java@v1 with: - java-version: 11 - java-package: jre - - name: Install Buck - run: | - mkdir bin - wget -q -O bin/buck https://jitpack.io/com/github/facebook/buck/a5f0342ae3/buck-a5f0342ae3-java11.pex # dev branch from 2020.10.11 - chmod +x bin/buck - echo bin >> $GITHUB_PATH + submodules: true + - uses: dtolnay/rust-toolchain@stable + - uses: dtolnay/install@reindeer + - uses: dtolnay/install@buck2 - name: Install lld run: sudo apt-get install lld - - name: Vendor dependencies - run: | - cp third-party/Cargo.lock . - cargo vendor --versioned-dirs --locked third-party/vendor - - run: buck build :cxx#check --verbose=0 - - run: buck run demo --verbose=0 - - run: buck test ... --verbose=0 + - run: cargo vendor --versioned-dirs --locked + working-directory: third-party + - run: reindeer vendor + working-directory: third-party + - name: Check reindeer-generated BUCK file up to date + run: git diff --exit-code + - run: buck2 run demo + - run: buck2 build ... + - run: buck2 run tests:test bazel: name: Bazel runs-on: ubuntu-latest if: github.event_name != 'pull_request' + timeout-minutes: 45 steps: - uses: actions/checkout@v3 - name: Install Bazel @@ -110,6 +108,7 @@ jobs: name: Clippy runs-on: ubuntu-latest if: github.event_name != 'pull_request' + timeout-minutes: 45 steps: - uses: actions/checkout@v3 - uses: dtolnay/rust-toolchain@clippy @@ -119,6 +118,7 @@ jobs: name: Clang Tidy runs-on: ubuntu-latest if: github.event_name != 'pull_request' + timeout-minutes: 45 steps: - uses: actions/checkout@v3 - name: Install clang-tidy @@ -130,6 +130,7 @@ jobs: name: Outdated runs-on: ubuntu-latest if: github.event_name != 'pull_request' + timeout-minutes: 45 steps: - uses: actions/checkout@v3 - uses: dtolnay/install@cargo-outdated diff --git a/.github/workflows/site.yml b/.github/workflows/site.yml index e5f4ac47..09382b79 100644 --- a/.github/workflows/site.yml +++ b/.github/workflows/site.yml @@ -14,6 +14,7 @@ jobs: runs-on: ubuntu-latest permissions: contents: write + timeout-minutes: 30 steps: - uses: actions/checkout@v3 diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000..208a58a9 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "tools/buck/prelude"] + path = tools/buck/prelude + url = https://github.com/facebookincubator/buck2-prelude @@ -15,7 +15,10 @@ rust_library( rust_binary( name = "codegen", - srcs = glob(["gen/cmd/src/**/*.rs"]) + ["gen/cmd/src/gen/include/cxx.h"], + srcs = glob(["gen/cmd/src/**/*.rs"]) + [ + "gen/cmd/src/gen", + "gen/cmd/src/syntax", + ], crate = "cxxbridge", edition = "2018", visibility = ["PUBLIC"], @@ -41,7 +44,7 @@ cxx_library( rust_library( name = "macro", - srcs = glob(["macro/src/**/*.rs"]), + srcs = glob(["macro/src/**/*.rs"]) + ["macro/src/syntax"], crate = "cxxbridge_macro", edition = "2018", proc_macro = True, @@ -54,7 +57,10 @@ rust_library( rust_library( name = "build", - srcs = glob(["gen/build/src/**/*.rs"]), + srcs = glob(["gen/build/src/**/*.rs"]) + [ + "gen/build/src/gen", + "gen/build/src/syntax", + ], edition = "2018", visibility = ["PUBLIC"], deps = [ @@ -70,7 +76,10 @@ rust_library( rust_library( name = "lib", - srcs = glob(["gen/lib/src/**/*.rs"]), + srcs = glob(["gen/lib/src/**/*.rs"]) + [ + "gen/lib/src/gen", + "gen/lib/src/syntax", + ], edition = "2018", visibility = ["PUBLIC"], deps = [ @@ -1,6 +1,6 @@ [package] name = "cxx" -version = "1.0.77" # remember to update html_root_url +version = "1.0.85" # remember to update html_root_url authors = ["David Tolnay <dtolnay@gmail.com>"] categories = ["development-tools::ffi", "api-bindings", "no-std"] description = "Safe interop between Rust and C++" @@ -23,19 +23,22 @@ alloc = [] std = ["alloc"] [dependencies] -cxxbridge-macro = { version = "=1.0.77", path = "macro" } +cxxbridge-macro = { version = "=1.0.85", path = "macro" } link-cplusplus = "1.0" [build-dependencies] cc = "1.0.49" -cxxbridge-flags = { version = "=1.0.77", path = "flags", default-features = false } +cxxbridge-flags = { version = "=1.0.85", path = "flags", default-features = false } [dev-dependencies] -cxx-build = { version = "=1.0.77", path = "gen/build" } +cxx-build = { version = "=1.0.85", path = "gen/build" } cxx-gen = { version = "0.7", path = "gen/lib" } cxx-test-suite = { version = "0", path = "tests/ffi" } rustversion = "1.0" -trybuild = { version = "1.0.52", features = ["diff"] } +trybuild = { version = "1.0.66", features = ["diff"] } + +[lib] +doc-scrape-examples = false [workspace] members = ["demo", "flags", "gen/build", "gen/cmd", "gen/lib", "macro", "tests/ffi"] @@ -4,7 +4,7 @@ CXX — safe FFI between Rust and C++ [<img alt="github" src="https://img.shields.io/badge/github-dtolnay/cxx-8da0cb?style=for-the-badge&labelColor=555555&logo=github" height="20">](https://github.com/dtolnay/cxx) [<img alt="crates.io" src="https://img.shields.io/crates/v/cxx.svg?style=for-the-badge&color=fc8d62&logo=rust" height="20">](https://crates.io/crates/cxx) [<img alt="docs.rs" src="https://img.shields.io/badge/docs.rs-cxx-66c2a5?style=for-the-badge&labelColor=555555&logo=docs.rs" height="20">](https://docs.rs/cxx) -[<img alt="build status" src="https://img.shields.io/github/workflow/status/dtolnay/cxx/CI/master?style=for-the-badge" height="20">](https://github.com/dtolnay/cxx/actions?query=branch%3Amaster) +[<img alt="build status" src="https://img.shields.io/github/actions/workflow/status/dtolnay/cxx/ci.yml?branch=master&style=for-the-badge" height="20">](https://github.com/dtolnay/cxx/actions?query=branch%3Amaster) This library provides a **safe** mechanism for calling C++ code from Rust and Rust code from C++, not subject to the many ways that things can go wrong when @@ -14,7 +14,7 @@ http_archive( load("@rules_rust//rust:repositories.bzl", "rules_rust_dependencies", "rust_register_toolchains") -RUST_VERSION = "1.60.0" +RUST_VERSION = "1.65.0" rules_rust_dependencies() @@ -29,6 +29,6 @@ cxx_library( cxx_library( name = "blobstore-include", + exported_deps = ["//:core"], exported_headers = ["include/blobstore.h"], - deps = ["//:core"], ) diff --git a/flags/Cargo.toml b/flags/Cargo.toml index 15ba9a65..8958481c 100644 --- a/flags/Cargo.toml +++ b/flags/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cxxbridge-flags" -version = "1.0.77" +version = "1.0.85" authors = ["David Tolnay <dtolnay@gmail.com>"] categories = ["development-tools::ffi", "compilers"] description = "Compiler configuration of the `cxx` crate (implementation detail)" diff --git a/gen/build/Cargo.toml b/gen/build/Cargo.toml index bbeaf3e0..ea19af89 100644 --- a/gen/build/Cargo.toml +++ b/gen/build/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cxx-build" -version = "1.0.77" +version = "1.0.85" authors = ["David Tolnay <dtolnay@gmail.com>"] categories = ["development-tools::build-utils", "development-tools::ffi"] description = "C++ code generator for integrating `cxx` crate into a Cargo build." @@ -19,7 +19,7 @@ experimental-async-fn = [] [dependencies] cc = "1.0.49" -codespan-reporting = "0.11" +codespan-reporting = "0.11.1" once_cell = "1.9" proc-macro2 = { version = "1.0.39", default-features = false, features = ["span-locations"] } quote = { version = "1.0", default-features = false } @@ -27,8 +27,12 @@ scratch = "1.0" syn = { version = "1.0.95", default-features = false, features = ["parsing", "printing", "clone-impls", "full"] } [dev-dependencies] +cxx = { version = "1.0", path = "../.." } cxx-gen = { version = "0.7", path = "../lib" } pkg-config = "0.3" +[lib] +doc-scrape-examples = false + [package.metadata.docs.rs] targets = ["x86_64-unknown-linux-gnu"] diff --git a/gen/build/src/cfg.rs b/gen/build/src/cfg.rs index ef662ecf..69eb6945 100644 --- a/gen/build/src/cfg.rs +++ b/gen/build/src/cfg.rs @@ -12,6 +12,8 @@ pub struct Cfg<'a> { pub exported_header_prefixes: Vec<&'a str>, /// See [`CFG.exported_header_links`][CFG#cfgexported_header_links]. pub exported_header_links: Vec<&'a str>, + /// See [`CFG.doxygen`][CFG#cfgdoxygen]. + pub doxygen: bool, marker: PhantomData<*const ()>, // !Send + !Sync } @@ -19,7 +21,7 @@ pub struct Cfg<'a> { /// /// <br> /// -/// <div style="float:right;margin:22px 50px 0;font-size:1.15em;color:#444"><strong>&str</strong></div> +/// <div style="float:right;margin:22px 50px 0;font-size:1.15em;opacity:.73"><strong>&str</strong></div> /// /// ## **`CFG.include_prefix`** /// @@ -71,7 +73,7 @@ pub struct Cfg<'a> { /// /// <br> /// -/// <div style="float:right;margin:22px 50px 0;font-size:1.15em;color:#444"><strong>Vec<&Path></strong></div> +/// <div style="float:right;margin:22px 50px 0;font-size:1.15em;opacity:.73"><strong>Vec<&Path></strong></div> /// /// ## **`CFG.exported_header_dirs`** /// @@ -146,7 +148,7 @@ pub struct Cfg<'a> { /// /// <p style="margin:0"><br><br></p> /// -/// <div style="float:right;margin:22px 50px 0;font-size:1.15em;color:#444"><strong>Vec<&str></strong></div> +/// <div style="float:right;margin:22px 50px 0;font-size:1.15em;opacity:.73"><strong>Vec<&str></strong></div> /// /// ## **`CFG.exported_header_prefixes`** /// @@ -203,7 +205,7 @@ pub struct Cfg<'a> { /// /// <p style="margin:0"><br><br></p> /// -/// <div style="float:right;margin:22px 50px 0;font-size:1.15em;color:#444"><strong>Vec<&str></strong></div> +/// <div style="float:right;margin:22px 50px 0;font-size:1.15em;opacity:.73"><strong>Vec<&str></strong></div> /// /// ## **`CFG.exported_header_links`** /// @@ -232,12 +234,84 @@ pub struct Cfg<'a> { /// cxx_build::bridge("src/bridge.rs").compile("demo"); /// } /// ``` +/// +/// <p style="margin:0"><br><br></p> +/// +/// <div style="float:right;margin:22px 50px 0;font-size:1.15em;opacity:.73"><strong>bool</strong></div> +/// +/// ## **`CFG.doxygen`** +/// +/// Boolean. Whether to propagate Rust documentation from inside the cxx::bridge +/// module as Doxygen-style comments in the generated C++ header. +/// +/// Documentation on the following are supported: +/// +/// - shared structs, and fields of shared structs +/// - shared enums, and their variants +/// - extern "Rust" opaque types +/// - extern "Rust" functions, including methods/member functions +/// +/// ### Example +/// +/// ```no_run +/// // build.rs +/// +/// use cxx_build::CFG; +/// +/// fn main() { +/// CFG.doxygen = true; +/// +/// cxx_build::bridge("src/bridge.rs").compile("demo"); +/// } +/// ``` +/// +/// ```rust +/// // src/bridge.rs +/// +/// #[cxx::bridge] +/// mod ffi { +/// /// documentation of MyStruct +/// pub struct MyStruct { +/// /// documentation of the struct field +/// lol: String, +/// } +/// +/// extern "Rust" { +/// /// documentation of MyType +/// type MyType; +/// +/// /// function documentation +/// fn asdf() -> bool; +/// } +/// } +/// # +/// # pub struct MyType; +/// # fn asdf() -> bool { true } +/// # fn main() {} +/// ``` +/// +/// With `CFG.doxygen` enabled, the generated C++ header through which +/// downstream C++ code will be able to access these shared structs and extern +/// "Rust" signatures will have the Rust documentation comments propagated as +/// Doxygen-style comments: +/// +/// ```cpp +/// /// documentation of MyStruct +/// struct MyStruct final { +/// /// documentation of the struct field +/// ::rust::String lol; +/// … +/// }; +/// ``` +/// +/// Otherwise by default (without `CFG.doxygen`) they'll just be `//` comments. #[cfg(doc)] pub static mut CFG: Cfg = Cfg { include_prefix: "", exported_header_dirs: Vec::new(), exported_header_prefixes: Vec::new(), exported_header_links: Vec::new(), + doxygen: false, marker: PhantomData, }; @@ -248,6 +322,7 @@ impl<'a> Debug for Cfg<'a> { exported_header_dirs, exported_header_prefixes, exported_header_links, + doxygen, marker: _, } = self; formatter @@ -256,6 +331,7 @@ impl<'a> Debug for Cfg<'a> { .field("exported_header_dirs", exported_header_dirs) .field("exported_header_prefixes", exported_header_prefixes) .field("exported_header_links", exported_header_links) + .field("doxygen", doxygen) .finish() } } @@ -280,6 +356,7 @@ mod r#impl { exported_header_dirs: Vec<InternedString>, exported_header_prefixes: Vec<InternedString>, exported_header_links: Vec<InternedString>, + doxygen: bool, } impl CurrentCfg { @@ -290,11 +367,13 @@ mod r#impl { let exported_header_dirs = Vec::new(); let exported_header_prefixes = Vec::new(); let exported_header_links = Vec::new(); + let doxygen = false; CurrentCfg { include_prefix, exported_header_dirs, exported_header_prefixes, exported_header_links, + doxygen, } } } @@ -327,11 +406,13 @@ mod r#impl { let exported_header_dirs = current.exported_header_dirs.vec(); let exported_header_prefixes = current.exported_header_prefixes.vec(); let exported_header_links = current.exported_header_links.vec(); + let doxygen = current.doxygen; super::Cfg { include_prefix, exported_header_dirs, exported_header_prefixes, exported_header_links, + doxygen, marker: PhantomData, } } @@ -392,11 +473,20 @@ mod r#impl { impl<'a> Drop for Cfg<'a> { fn drop(&mut self) { if let Cfg::Mut(cfg) = self { + let super::Cfg { + include_prefix, + exported_header_dirs, + exported_header_prefixes, + exported_header_links, + doxygen, + marker: _, + } = cfg; let mut current = CURRENT.write().unwrap_or_else(PoisonError::into_inner); - current.include_prefix = intern(cfg.include_prefix); - current.exported_header_dirs = vec::intern(&cfg.exported_header_dirs); - current.exported_header_prefixes = vec::intern(&cfg.exported_header_prefixes); - current.exported_header_links = vec::intern(&cfg.exported_header_links); + current.include_prefix = intern(include_prefix); + current.exported_header_dirs = vec::intern(exported_header_dirs); + current.exported_header_prefixes = vec::intern(exported_header_prefixes); + current.exported_header_links = vec::intern(exported_header_links); + current.doxygen = *doxygen; } else { CONST_DEREFS.with(|derefs| derefs.borrow_mut().remove(&self.handle())); } diff --git a/gen/build/src/lib.rs b/gen/build/src/lib.rs index 7272a396..225042c2 100644 --- a/gen/build/src/lib.rs +++ b/gen/build/src/lib.rs @@ -399,6 +399,7 @@ fn generate_bridge(prj: &Project, build: &mut Build, rust_source_file: &Path) -> let opt = Opt { allow_dot_includes: false, cfg_evaluator: Box::new(CargoEnvCfgEvaluator), + doxygen: CFG.doxygen, ..Opt::default() }; let generated = gen::generate_from_path(rust_source_file, &opt); diff --git a/gen/cmd/Android.bp b/gen/cmd/Android.bp index bff1cb4b..ffda7dbc 100644 --- a/gen/cmd/Android.bp +++ b/gen/cmd/Android.bp @@ -1,4 +1,5 @@ -// This file is generated by cargo2android.py --run --dependencies --add_workspace --host-first-multilib. +// This file is generated by cargo2android.py --run --dependencies --add_workspace --host-first-multilib --no-pkg-vers. +// Do not modify this file as changes will be overridden on upgrade. package { // See: http://go/android-license-faq @@ -13,6 +14,7 @@ package { rust_binary_host { name: "cxxbridge", crate_name: "cxxbridge", + cargo_env_compat: true, srcs: ["src/main.rs"], edition: "2018", rustlibs: [ @@ -29,6 +31,7 @@ rust_binary_host { rust_library_host { name: "libcxxbridge_cmd", crate_name: "cxxbridge_cmd", + cargo_env_compat: true, srcs: ["src/lib.rs"], edition: "2018", rustlibs: [ @@ -40,20 +43,3 @@ rust_library_host { ], compile_multilib: "first", } - -// dependent_library ["feature_list"] -// ansi_term-0.11.0 -// atty-0.2.14 -// bitflags-1.2.1 "default" -// clap-2.33.3 "ansi_term,atty,color,default,strsim,suggestions,vec_map" -// codespan-reporting-0.9.5 -// libc-0.2.80 -// proc-macro2-1.0.24 "span-locations" -// quote-1.0.7 -// strsim-0.8.0 -// syn-1.0.50 "clone-impls,full,parsing,printing,quote" -// termcolor-1.1.2 -// textwrap-0.11.0 -// unicode-width-0.1.8 "default" -// unicode-xid-0.2.1 "default" -// vec_map-0.8.2 diff --git a/gen/cmd/Cargo.toml b/gen/cmd/Cargo.toml index b7e9e6c9..39d9a617 100644 --- a/gen/cmd/Cargo.toml +++ b/gen/cmd/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cxxbridge-cmd" -version = "1.0.77" +version = "1.0.85" authors = ["David Tolnay <dtolnay@gmail.com>"] categories = ["development-tools::build-utils", "development-tools::ffi"] description = "C++ code generator for integrating `cxx` crate into a non-Cargo build." @@ -21,7 +21,7 @@ path = "src/main.rs" experimental-async-fn = [] [dependencies] -clap = { version = "3.2", default-features = false, features = ["std", "suggestions"] } +clap = { version = "4", default-features = false, features = ["error-context", "help", "std", "suggestions", "usage"] } codespan-reporting = "0.11" proc-macro2 = { version = "1.0.39", default-features = false, features = ["span-locations"] } quote = { version = "1.0", default-features = false } diff --git a/gen/cmd/src/app.rs b/gen/cmd/src/app.rs index a1adb387..bfad8562 100644 --- a/gen/cmd/src/app.rs +++ b/gen/cmd/src/app.rs @@ -10,6 +10,7 @@ use clap::builder::{ArgAction, ValueParser}; use clap::{Arg, Command}; use std::collections::{BTreeMap as Map, BTreeSet as Set}; use std::path::PathBuf; +use std::process; use std::sync::{Arc, Mutex, PoisonError}; use syn::parse::Parser; @@ -24,51 +25,54 @@ const TEMPLATE: &str = "\ David Tolnay <dtolnay@gmail.com> https://github.com/dtolnay/cxx -USAGE: +{usage-heading} {usage} -ARGS: -{positionals} - -OPTIONS: -{options}\ +{all-args}\ "; -fn app() -> Command<'static> { +fn app() -> Command { let mut app = Command::new("cxxbridge") .override_usage(USAGE) .help_template(TEMPLATE) .next_line_help(true) + .disable_help_flag(true) + .disable_version_flag(true) .arg(arg_input()) + .arg(arg_cfg()) .arg(arg_cxx_impl_annotations()) .arg(arg_header()) + .arg(arg_help()) .arg(arg_include()) - .arg(arg_output()) - .arg(arg_cfg()) - .mut_arg("help", |a| a.help("Print help information.")); + .arg(arg_output()); if let Some(version) = option_env!("CARGO_PKG_VERSION") { - app = app - .version(version) - .mut_arg("version", |a| a.help("Print version information.")); + app = app.arg(arg_version()).version(version); } app } const INPUT: &str = "input"; +const CFG: &str = "cfg"; const CXX_IMPL_ANNOTATIONS: &str = "cxx-impl-annotations"; +const HELP: &str = "help"; const HEADER: &str = "header"; const INCLUDE: &str = "include"; const OUTPUT: &str = "output"; -const CFG: &str = "cfg"; +const VERSION: &str = "version"; pub(super) fn from_args() -> Opt { let matches = app().get_matches(); + if matches.get_flag(HELP) { + let _ = app().print_long_help(); + process::exit(0); + } + let input = matches.get_one::<PathBuf>(INPUT).cloned(); let cxx_impl_annotations = matches .get_one::<String>(CXX_IMPL_ANNOTATIONS) .map(String::clone); - let header = matches.contains_id(HEADER); + let header = matches.get_flag(HEADER); let include = matches .get_many::<String>(INCLUDE) .unwrap_or_default() @@ -115,14 +119,41 @@ pub(super) fn from_args() -> Opt { } } -fn arg_input() -> Arg<'static> { +fn arg_input() -> Arg { Arg::new(INPUT) .help("Input Rust source file containing #[cxx::bridge].") - .required_unless_present(HEADER) + .required_unless_present_any(&[HEADER, HELP]) .value_parser(ValueParser::path_buf()) } -fn arg_cxx_impl_annotations() -> Arg<'static> { +fn arg_cfg() -> Arg { + const HELP: &str = "\ +Compilation configuration matching what will be used to build +the Rust side of the bridge."; + let bool_cfgs = Arc::new(Mutex::new(Map::<String, bool>::new())); + Arg::new(CFG) + .long(CFG) + .num_args(1) + .value_name("name=\"value\" | name[=true] | name=false") + .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(arg.to_owned()) + } + Err(_) => Err("expected name=\"value\", name=true, or name=false".to_owned()), + }) + .help(HELP) +} + +fn arg_cxx_impl_annotations() -> Arg { const HELP: &str = "\ Optional annotation for implementations of C++ function wrappers that may be exposed to Rust. You may for example need to provide @@ -131,20 +162,27 @@ if Rust code from one shared object or executable depends on these C++ functions in another."; Arg::new(CXX_IMPL_ANNOTATIONS) .long(CXX_IMPL_ANNOTATIONS) - .takes_value(true) + .num_args(1) .value_name("annotation") .value_parser(ValueParser::string()) .help(HELP) } -fn arg_header() -> Arg<'static> { +fn arg_header() -> Arg { const HELP: &str = "\ Emit header with declarations only. Optional if using `-o` with a path ending in `.h`."; - Arg::new(HEADER).long(HEADER).help(HELP) + Arg::new(HEADER).long(HEADER).num_args(0).help(HELP) } -fn arg_include() -> Arg<'static> { +fn arg_help() -> Arg { + Arg::new(HELP) + .long(HELP) + .help("Print help information.") + .num_args(0) +} + +fn arg_include() -> Arg { const HELP: &str = "\ Any additional headers to #include. The cxxbridge tool does not parse or even require the given paths to exist; they simply go @@ -152,48 +190,28 @@ into the generated C++ code as #include lines."; Arg::new(INCLUDE) .long(INCLUDE) .short('i') - .takes_value(true) + .num_args(1) .action(ArgAction::Append) .value_parser(ValueParser::string()) .help(HELP) } -fn arg_output() -> Arg<'static> { +fn arg_output() -> Arg { const HELP: &str = "\ Path of file to write as output. Output goes to stdout if -o is not specified."; Arg::new(OUTPUT) .long(OUTPUT) .short('o') - .takes_value(true) + .num_args(1) .action(ArgAction::Append) .value_parser(ValueParser::path_buf()) .help(HELP) } -fn arg_cfg() -> Arg<'static> { - const HELP: &str = "\ -Compilation configuration matching what will be used to build -the Rust side of the bridge."; - let bool_cfgs = Arc::new(Mutex::new(Map::<String, bool>::new())); - Arg::new(CFG) - .long(CFG) - .takes_value(true) - .value_name("name=\"value\" | name[=true] | name=false") - .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(arg.to_owned()) - } - Err(_) => Err("expected name=\"value\", name=true, or name=false".to_owned()), - }) - .help(HELP) +fn arg_version() -> Arg { + Arg::new(VERSION) + .long(VERSION) + .help("Print version information.") + .action(ArgAction::Version) } diff --git a/gen/cmd/src/test.rs b/gen/cmd/src/test.rs index 33a61fdf..c04c28e8 100644 --- a/gen/cmd/src/test.rs +++ b/gen/cmd/src/test.rs @@ -3,45 +3,45 @@ cxxbridge $VERSION David Tolnay <dtolnay@gmail.com> https://github.com/dtolnay/cxx -USAGE: +Usage: cxxbridge <input>.rs Emit .cc file for bridge to stdout cxxbridge <input>.rs --header Emit .h file for bridge to stdout cxxbridge --header Emit \"rust/cxx.h\" header to stdout -ARGS: - <input> - Input Rust source file containing #[cxx::bridge]. +Arguments: + [input] + Input Rust source file containing #[cxx::bridge]. -OPTIONS: - --cfg <name=\"value\" | name[=true] | name=false> - Compilation configuration matching what will be used to build - the Rust side of the bridge. +Options: + --cfg <name=\"value\" | name[=true] | name=false> + Compilation configuration matching what will be used to build + the Rust side of the bridge. - --cxx-impl-annotations <annotation> - Optional annotation for implementations of C++ function wrappers - that may be exposed to Rust. You may for example need to provide - __declspec(dllexport) or __attribute__((visibility(\"default\"))) - if Rust code from one shared object or executable depends on - these C++ functions in another. + --cxx-impl-annotations <annotation> + Optional annotation for implementations of C++ function wrappers + that may be exposed to Rust. You may for example need to provide + __declspec(dllexport) or __attribute__((visibility(\"default\"))) + if Rust code from one shared object or executable depends on + these C++ functions in another. - -h, --help - Print help information. + --header + Emit header with declarations only. Optional if using `-o` with + a path ending in `.h`. - --header - Emit header with declarations only. Optional if using `-o` with - a path ending in `.h`. + --help + Print help information. - -i, --include <include> - Any additional headers to #include. The cxxbridge tool does not - parse or even require the given paths to exist; they simply go - into the generated C++ code as #include lines. + -i, --include <include> + Any additional headers to #include. The cxxbridge tool does not + parse or even require the given paths to exist; they simply go + into the generated C++ code as #include lines. - -o, --output <output> - Path of file to write as output. Output goes to stdout if -o is - not specified. + -o, --output <output> + Path of file to write as output. Output goes to stdout if -o is + not specified. - -V, --version - Print version information. + --version + Print version information. "; #[test] diff --git a/gen/lib/Cargo.toml b/gen/lib/Cargo.toml index 53882b54..df8c8558 100644 --- a/gen/lib/Cargo.toml +++ b/gen/lib/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cxx-gen" -version = "0.7.77" +version = "0.7.85" authors = ["Adrian Taylor <adetaylor@chromium.org>"] categories = ["development-tools::ffi"] description = "C++ code generator for integrating `cxx` crate into higher level tools." @@ -17,5 +17,8 @@ proc-macro2 = { version = "1.0.39", default-features = false, features = ["span- quote = { version = "1.0", default-features = false } syn = { version = "1.0.95", default-features = false, features = ["parsing", "printing", "clone-impls", "full"] } +[lib] +doc-scrape-examples = false + [package.metadata.docs.rs] targets = ["x86_64-unknown-linux-gnu"] diff --git a/gen/src/builtin.rs b/gen/src/builtin.rs index 7ee91c56..277c64f8 100644 --- a/gen/src/builtin.rs +++ b/gen/src/builtin.rs @@ -26,7 +26,6 @@ pub struct Builtins<'a> { pub rust_str_repr: bool, pub rust_slice_new: bool, pub rust_slice_repr: bool, - pub exception: bool, pub relocatable: bool, pub relocatable_or_array: bool, pub friend_impl: bool, @@ -138,6 +137,10 @@ pub(super) fn write(out: &mut OutFile) { builtin.unsafe_bitcopy_t = true; } + if builtin.trycatch { + builtin.ptr_len = true; + } + out.begin_block(Block::Namespace("rust")); out.begin_block(Block::InlineNamespace("cxxbridge1")); @@ -205,6 +208,26 @@ pub(super) fn write(out: &mut OutFile) { writeln!(out, "inline Slice<T>::Slice(uninit) noexcept {{}}"); } + out.begin_block(Block::Namespace("repr")); + + if builtin.repr_fat { + include.array = true; + include.cstdint = true; + out.next_section(); + writeln!(out, "using Fat = ::std::array<::std::uintptr_t, 2>;"); + } + + if builtin.ptr_len { + include.cstddef = true; + out.next_section(); + writeln!(out, "struct PtrLen final {{"); + writeln!(out, " void *ptr;"); + writeln!(out, " ::std::size_t len;"); + writeln!(out, "}};"); + } + + out.end_block(Block::Namespace("repr")); + out.begin_block(Block::Namespace("detail")); if builtin.maybe_uninit { @@ -231,6 +254,21 @@ pub(super) fn write(out: &mut OutFile) { writeln!(out, "}};"); } + if builtin.trycatch { + include.string = true; + out.next_section(); + writeln!(out, "class Fail final {{"); + writeln!(out, " ::rust::repr::PtrLen &throw$;"); + writeln!(out, "public:"); + writeln!( + out, + " Fail(::rust::repr::PtrLen &throw$) noexcept : throw$(throw$) {{}}", + ); + writeln!(out, " void operator()(char const *) noexcept;"); + writeln!(out, " void operator()(std::string const &) noexcept;"); + writeln!(out, "}};"); + } + out.end_block(Block::Namespace("detail")); if builtin.manually_drop { @@ -264,26 +302,6 @@ pub(super) fn write(out: &mut OutFile) { out.begin_block(Block::AnonymousNamespace); - if builtin.repr_fat { - include.array = true; - include.cstdint = true; - out.next_section(); - out.begin_block(Block::Namespace("repr")); - writeln!(out, "using Fat = ::std::array<::std::uintptr_t, 2>;"); - out.end_block(Block::Namespace("repr")); - } - - if builtin.ptr_len { - include.cstddef = true; - out.next_section(); - out.begin_block(Block::Namespace("repr")); - writeln!(out, "struct PtrLen final {{"); - writeln!(out, " void *ptr;"); - writeln!(out, " ::std::size_t len;"); - writeln!(out, "}};"); - out.end_block(Block::Namespace("repr")); - } - if builtin.rust_str_new_unchecked || builtin.rust_str_repr { out.next_section(); writeln!(out, "template <>"); @@ -334,7 +352,7 @@ pub(super) fn write(out: &mut OutFile) { writeln!(out, "public:"); writeln!(out, " static Error error(repr::PtrLen repr) noexcept {{"); writeln!(out, " Error error;"); - writeln!(out, " error.msg = static_cast<const char *>(repr.ptr);"); + writeln!(out, " error.msg = static_cast<char const *>(repr.ptr);"); writeln!(out, " error.len = repr.len;"); writeln!(out, " return error;"); writeln!(out, " }}"); @@ -394,21 +412,11 @@ pub(super) fn write(out: &mut OutFile) { writeln!(out, " missing>::value>::type"); writeln!(out, "trycatch(Try &&func, Fail &&fail) noexcept try {{"); writeln!(out, " func();"); - writeln!(out, "}} catch (const ::std::exception &e) {{"); + writeln!(out, "}} catch (::std::exception const &e) {{"); writeln!(out, " fail(e.what());"); writeln!(out, "}}"); out.end_block(Block::Namespace("behavior")); } out.end_block(Block::Namespace("rust")); - - if builtin.exception { - include.cstddef = true; - out.begin_block(Block::ExternC); - writeln!( - out, - "const char *cxxbridge1$exception(const char *, ::std::size_t);", - ); - out.end_block(Block::ExternC); - } } diff --git a/gen/src/mod.rs b/gen/src/mod.rs index 351ac187..f24846a7 100644 --- a/gen/src/mod.rs +++ b/gen/src/mod.rs @@ -59,6 +59,7 @@ pub struct Opt { pub(super) gen_implementation: bool, pub(super) allow_dot_includes: bool, pub(super) cfg_evaluator: Box<dyn CfgEvaluator>, + pub(super) doxygen: bool, } pub(super) trait CfgEvaluator { @@ -89,6 +90,7 @@ impl Default for Opt { gen_implementation: true, allow_dot_includes: true, cfg_evaluator: Box::new(UnsupportedCfgEvaluator), + doxygen: false, } } } diff --git a/gen/src/write.rs b/gen/src/write.rs index dddec7a5..6f535ccb 100644 --- a/gen/src/write.rs +++ b/gen/src/write.rs @@ -177,7 +177,7 @@ fn write_std_specializations(out: &mut OutFile, apis: &[Api]) { writeln!(out, "template <> struct hash<{}> {{", qualified); writeln!( out, - " ::std::size_t operator()(const {} &self) const noexcept {{", + " ::std::size_t operator()({} const &self) const noexcept {{", qualified, ); let link_name = mangle::operator(&strct.name, "hash"); @@ -227,6 +227,25 @@ fn pick_includes_and_builtins(out: &mut OutFile, apis: &[Api]) { } } +fn write_doc(out: &mut OutFile, indent: &str, doc: &Doc) { + let mut lines = 0; + for line in doc.to_string().lines() { + if out.opt.doxygen { + writeln!(out, "{}///{}", indent, line); + } else { + writeln!(out, "{}//{}", indent, line); + } + lines += 1; + } + // According to https://www.doxygen.nl/manual/docblocks.html, Doxygen only + // interprets `///` as a Doxygen comment block if there are at least 2 of + // them. In Rust, a single `///` is definitely still documentation so we + // make sure to propagate that as a Doxygen comment. + if out.opt.doxygen && lines == 1 { + writeln!(out, "{}///", indent); + } +} + fn write_struct<'a>(out: &mut OutFile<'a>, strct: &'a Struct, methods: &[&ExternFn]) { let operator_eq = derive::contains(&strct.derives, Trait::PartialEq); let operator_ord = derive::contains(&strct.derives, Trait::PartialOrd); @@ -235,15 +254,11 @@ fn write_struct<'a>(out: &mut OutFile<'a>, strct: &'a Struct, methods: &[&Extern let guard = format!("CXXBRIDGE1_STRUCT_{}", strct.name.to_symbol()); writeln!(out, "#ifndef {}", guard); writeln!(out, "#define {}", guard); - for line in strct.doc.to_string().lines() { - writeln!(out, "//{}", line); - } + write_doc(out, "", &strct.doc); writeln!(out, "struct {} final {{", strct.name.cxx); for field in &strct.fields { - for line in field.doc.to_string().lines() { - writeln!(out, " //{}", line); - } + write_doc(out, " ", &field.doc); write!(out, " "); write_type_space(out, &field.ty); writeln!(out, "{};", field.name.cxx); @@ -255,9 +270,7 @@ fn write_struct<'a>(out: &mut OutFile<'a>, strct: &'a Struct, methods: &[&Extern if !method.doc.is_empty() { out.next_section(); } - for line in method.doc.to_string().lines() { - writeln!(out, " //{}", line); - } + write_doc(out, " ", &method.doc); write!(out, " "); let sig = &method.sig; let local_name = method.name.cxx.to_string(); @@ -272,12 +285,12 @@ fn write_struct<'a>(out: &mut OutFile<'a>, strct: &'a Struct, methods: &[&Extern if operator_eq { writeln!( out, - " bool operator==(const {} &) const noexcept;", + " bool operator==({} const &) const noexcept;", strct.name.cxx, ); writeln!( out, - " bool operator!=(const {} &) const noexcept;", + " bool operator!=({} const &) const noexcept;", strct.name.cxx, ); } @@ -285,22 +298,22 @@ fn write_struct<'a>(out: &mut OutFile<'a>, strct: &'a Struct, methods: &[&Extern if operator_ord { writeln!( out, - " bool operator<(const {} &) const noexcept;", + " bool operator<({} const &) const noexcept;", strct.name.cxx, ); writeln!( out, - " bool operator<=(const {} &) const noexcept;", + " bool operator<=({} const &) const noexcept;", strct.name.cxx, ); writeln!( out, - " bool operator>(const {} &) const noexcept;", + " bool operator>({} const &) const noexcept;", strct.name.cxx, ); writeln!( out, - " bool operator>=(const {} &) const noexcept;", + " bool operator>=({} const &) const noexcept;", strct.name.cxx, ); } @@ -336,9 +349,7 @@ fn write_opaque_type<'a>(out: &mut OutFile<'a>, ety: &'a ExternType, methods: &[ let guard = format!("CXXBRIDGE1_STRUCT_{}", ety.name.to_symbol()); writeln!(out, "#ifndef {}", guard); writeln!(out, "#define {}", guard); - for line in ety.doc.to_string().lines() { - writeln!(out, "//{}", line); - } + write_doc(out, "", &ety.doc); out.builtin.opaque = true; writeln!( @@ -351,9 +362,7 @@ fn write_opaque_type<'a>(out: &mut OutFile<'a>, ety: &'a ExternType, methods: &[ if i > 0 && !method.doc.is_empty() { out.next_section(); } - for line in method.doc.to_string().lines() { - writeln!(out, " //{}", line); - } + write_doc(out, " ", &method.doc); write!(out, " "); let sig = &method.sig; let local_name = method.name.cxx.to_string(); @@ -390,16 +399,12 @@ fn write_enum<'a>(out: &mut OutFile<'a>, enm: &'a Enum) { let guard = format!("CXXBRIDGE1_ENUM_{}", enm.name.to_symbol()); writeln!(out, "#ifndef {}", guard); writeln!(out, "#define {}", guard); - for line in enm.doc.to_string().lines() { - writeln!(out, "//{}", line); - } + write_doc(out, "", &enm.doc); write!(out, "enum class {} : ", enm.name.cxx); write_atom(out, repr); writeln!(out, " {{"); for variant in &enm.variants { - for line in variant.doc.to_string().lines() { - writeln!(out, " //{}", line); - } + write_doc(out, " ", &variant.doc); writeln!(out, " {} = {},", variant.name.cxx, variant.discriminant); } writeln!(out, "}};"); @@ -505,7 +510,7 @@ fn write_struct_operator_decls<'a>(out: &mut OutFile<'a>, strct: &'a Struct) { let link_name = mangle::operator(&strct.name, "eq"); writeln!( out, - "bool {}(const {1} &, const {1} &) noexcept;", + "bool {}({1} const &, {1} const &) noexcept;", link_name, strct.name.cxx, ); @@ -513,7 +518,7 @@ fn write_struct_operator_decls<'a>(out: &mut OutFile<'a>, strct: &'a Struct) { let link_name = mangle::operator(&strct.name, "ne"); writeln!( out, - "bool {}(const {1} &, const {1} &) noexcept;", + "bool {}({1} const &, {1} const &) noexcept;", link_name, strct.name.cxx, ); } @@ -523,14 +528,14 @@ fn write_struct_operator_decls<'a>(out: &mut OutFile<'a>, strct: &'a Struct) { let link_name = mangle::operator(&strct.name, "lt"); writeln!( out, - "bool {}(const {1} &, const {1} &) noexcept;", + "bool {}({1} const &, {1} const &) noexcept;", link_name, strct.name.cxx, ); let link_name = mangle::operator(&strct.name, "le"); writeln!( out, - "bool {}(const {1} &, const {1} &) noexcept;", + "bool {}({1} const &, {1} const &) noexcept;", link_name, strct.name.cxx, ); @@ -538,14 +543,14 @@ fn write_struct_operator_decls<'a>(out: &mut OutFile<'a>, strct: &'a Struct) { let link_name = mangle::operator(&strct.name, "gt"); writeln!( out, - "bool {}(const {1} &, const {1} &) noexcept;", + "bool {}({1} const &, {1} const &) noexcept;", link_name, strct.name.cxx, ); let link_name = mangle::operator(&strct.name, "ge"); writeln!( out, - "bool {}(const {1} &, const {1} &) noexcept;", + "bool {}({1} const &, {1} const &) noexcept;", link_name, strct.name.cxx, ); } @@ -556,7 +561,7 @@ fn write_struct_operator_decls<'a>(out: &mut OutFile<'a>, strct: &'a Struct) { let link_name = mangle::operator(&strct.name, "hash"); writeln!( out, - "::std::size_t {}(const {} &) noexcept;", + "::std::size_t {}({} const &) noexcept;", link_name, strct.name.cxx, ); } @@ -575,7 +580,7 @@ fn write_struct_operators<'a>(out: &mut OutFile<'a>, strct: &'a Struct) { out.next_section(); writeln!( out, - "bool {0}::operator==(const {0} &rhs) const noexcept {{", + "bool {0}::operator==({0} const &rhs) const noexcept {{", strct.name.cxx, ); let link_name = mangle::operator(&strct.name, "eq"); @@ -585,7 +590,7 @@ fn write_struct_operators<'a>(out: &mut OutFile<'a>, strct: &'a Struct) { out.next_section(); writeln!( out, - "bool {0}::operator!=(const {0} &rhs) const noexcept {{", + "bool {0}::operator!=({0} const &rhs) const noexcept {{", strct.name.cxx, ); if derive::contains(&strct.derives, Trait::Eq) { @@ -601,7 +606,7 @@ fn write_struct_operators<'a>(out: &mut OutFile<'a>, strct: &'a Struct) { out.next_section(); writeln!( out, - "bool {0}::operator<(const {0} &rhs) const noexcept {{", + "bool {0}::operator<({0} const &rhs) const noexcept {{", strct.name.cxx, ); let link_name = mangle::operator(&strct.name, "lt"); @@ -611,7 +616,7 @@ fn write_struct_operators<'a>(out: &mut OutFile<'a>, strct: &'a Struct) { out.next_section(); writeln!( out, - "bool {0}::operator<=(const {0} &rhs) const noexcept {{", + "bool {0}::operator<=({0} const &rhs) const noexcept {{", strct.name.cxx, ); let link_name = mangle::operator(&strct.name, "le"); @@ -621,7 +626,7 @@ fn write_struct_operators<'a>(out: &mut OutFile<'a>, strct: &'a Struct) { out.next_section(); writeln!( out, - "bool {0}::operator>(const {0} &rhs) const noexcept {{", + "bool {0}::operator>({0} const &rhs) const noexcept {{", strct.name.cxx, ); if derive::contains(&strct.derives, Trait::Ord) { @@ -635,7 +640,7 @@ fn write_struct_operators<'a>(out: &mut OutFile<'a>, strct: &'a Struct) { out.next_section(); writeln!( out, - "bool {0}::operator>=(const {0} &rhs) const noexcept {{", + "bool {0}::operator>=({0} const &rhs) const noexcept {{", strct.name.cxx, ); if derive::contains(&strct.derives, Trait::Ord) { @@ -709,25 +714,29 @@ fn write_cxx_function_shim<'a>(out: &mut OutFile<'a>, efn: &'a ExternFn) { let mangled = mangle::extern_fn(efn, out.types); write!(out, "{}(", mangled); if let Some(receiver) = &efn.receiver { - if !receiver.mutable { - write!(out, "const "); - } write!( out, - "{} &self", + "{}", out.types.resolve(&receiver.ty).name.to_fully_qualified(), ); + if !receiver.mutable { + write!(out, " const"); + } + write!(out, " &self"); } for (i, arg) in efn.args.iter().enumerate() { if i > 0 || efn.receiver.is_some() { write!(out, ", "); } if arg.ty == RustString { - write!(out, "const "); + write_type_space(out, &arg.ty); + write!(out, "const *{}", arg.name.cxx); } else if let Type::RustVec(_) = arg.ty { - write!(out, "const "); + write_type_space(out, &arg.ty); + write!(out, "const *{}", arg.name.cxx); + } else { + write_extern_arg(out, arg); } - write_extern_arg(out, arg); } let indirect_return = indirect_return(efn, out.types); if indirect_return { @@ -847,17 +856,9 @@ fn write_cxx_function_shim<'a>(out: &mut OutFile<'a>, efn: &'a ExternFn) { } writeln!(out, ";"); if efn.throws { - out.include.cstring = true; - out.builtin.exception = true; writeln!(out, " throw$.ptr = nullptr;"); writeln!(out, " }},"); - writeln!(out, " [&](const char *catch$) noexcept {{"); - writeln!(out, " throw$.len = ::std::strlen(catch$);"); - writeln!( - out, - " throw$.ptr = const_cast<char *>(::cxxbridge1$exception(catch$, throw$.len));", - ); - writeln!(out, " }});"); + writeln!(out, " ::rust::detail::Fail(throw$));"); writeln!(out, " return throw$;"); } writeln!(out, "}}"); @@ -906,14 +907,15 @@ fn write_rust_function_decl_impl( write!(out, "{}(", link_name); let mut needs_comma = false; if let Some(receiver) = &sig.receiver { - if !receiver.mutable { - write!(out, "const "); - } write!( out, - "{} &self", + "{}", out.types.resolve(&receiver.ty).name.to_fully_qualified(), ); + if !receiver.mutable { + write!(out, " const"); + } + write!(out, " &self"); needs_comma = true; } for arg in &sig.args { @@ -929,8 +931,11 @@ fn write_rust_function_decl_impl( } match sig.ret.as_ref().unwrap() { Type::Ref(ret) => { - write_pointee_type(out, &ret.inner, ret.mutable); - write!(out, " *"); + write_type_space(out, &ret.inner); + if !ret.mutable { + write!(out, "const "); + } + write!(out, "*"); } ret => write_type_space(out, ret), } @@ -1009,9 +1014,7 @@ fn write_rust_function_shim_impl( } if sig.receiver.is_none() { // Member functions already documented at their declaration. - for line in doc.to_string().lines() { - writeln!(out, "//{}", line); - } + write_doc(out, "", doc); } write_rust_function_shim_decl(out, local_name, sig, indirect_call); if out.header { @@ -1035,8 +1038,11 @@ fn write_rust_function_shim_impl( write!(out, "::rust::MaybeUninit<"); match sig.ret.as_ref().unwrap() { Type::Ref(ret) => { - write_pointee_type(out, &ret.inner, ret.mutable); - write!(out, " *"); + write_type_space(out, &ret.inner); + if !ret.mutable { + write!(out, "const "); + } + write!(out, "*"); } ret => write_type(out, ret), } @@ -1155,11 +1161,11 @@ fn write_indirect_return_type(out: &mut OutFile, ty: &Type) { write!(out, "*"); } Type::Ref(ty) => { + write_type_space(out, &ty.inner); if !ty.mutable { write!(out, "const "); } - write_type(out, &ty.inner); - write!(out, " *"); + write!(out, "*"); } _ => write_type(out, ty), } @@ -1181,11 +1187,11 @@ fn write_extern_return_type_space(out: &mut OutFile, ty: &Option<Type>) { write!(out, "*"); } Some(Type::Ref(ty)) => { + write_type_space(out, &ty.inner); if !ty.mutable { write!(out, "const "); } - write_type(out, &ty.inner); - write!(out, " *"); + write!(out, "*"); } Some(Type::Str(_)) | Some(Type::SliceRef(_)) => { out.builtin.repr_fat = true; @@ -1251,22 +1257,28 @@ fn write_type(out: &mut OutFile, ty: &Type) { write!(out, ">"); } Type::Ref(r) => { - write_pointee_type(out, &r.inner, r.mutable); - write!(out, " &"); + write_type_space(out, &r.inner); + if !r.mutable { + write!(out, "const "); + } + write!(out, "&"); } Type::Ptr(p) => { - write_pointee_type(out, &p.inner, p.mutable); - write!(out, " *"); + write_type_space(out, &p.inner); + if !p.mutable { + write!(out, "const "); + } + write!(out, "*"); } Type::Str(_) => { write!(out, "::rust::Str"); } Type::SliceRef(slice) => { write!(out, "::rust::Slice<"); + write_type_space(out, &slice.inner); if slice.mutability.is_none() { - write!(out, "const "); + write!(out, "const"); } - write_type(out, &slice.inner); write!(out, ">"); } Type::Fn(f) => { @@ -1293,21 +1305,6 @@ fn write_type(out: &mut OutFile, ty: &Type) { } } -// Write just the T type behind a &T or &mut T or *const T or *mut T. -fn write_pointee_type(out: &mut OutFile, inner: &Type, mutable: bool) { - if let Type::Ptr(_) = inner { - write_type_space(out, inner); - if !mutable { - write!(out, "const"); - } - } else { - if !mutable { - write!(out, "const "); - } - write_type(out, inner); - } -} - fn write_atom(out: &mut OutFile, atom: Atom) { match atom { Bool => write!(out, "bool"), @@ -1465,7 +1462,7 @@ fn write_rust_vec_extern(out: &mut OutFile, key: NamedImplKey) { writeln!( out, - "void cxxbridge1$rust_vec${}$new(const ::rust::Vec<{}> *ptr) noexcept;", + "void cxxbridge1$rust_vec${}$new(::rust::Vec<{}> const *ptr) noexcept;", instance, inner, ); writeln!( @@ -1475,17 +1472,17 @@ fn write_rust_vec_extern(out: &mut OutFile, key: NamedImplKey) { ); writeln!( out, - "::std::size_t cxxbridge1$rust_vec${}$len(const ::rust::Vec<{}> *ptr) noexcept;", + "::std::size_t cxxbridge1$rust_vec${}$len(::rust::Vec<{}> const *ptr) noexcept;", instance, inner, ); writeln!( out, - "::std::size_t cxxbridge1$rust_vec${}$capacity(const ::rust::Vec<{}> *ptr) noexcept;", + "::std::size_t cxxbridge1$rust_vec${}$capacity(::rust::Vec<{}> const *ptr) noexcept;", instance, inner, ); writeln!( out, - "const {} *cxxbridge1$rust_vec${}$data(const ::rust::Vec<{0}> *ptr) noexcept;", + "{} const *cxxbridge1$rust_vec${}$data(::rust::Vec<{0}> const *ptr) noexcept;", inner, instance, ); writeln!( @@ -1582,7 +1579,7 @@ fn write_rust_vec_impl(out: &mut OutFile, key: NamedImplKey) { writeln!(out, "template <>"); begin_function_definition(out); - writeln!(out, "const {} *Vec<{0}>::data() const noexcept {{", inner); + writeln!(out, "{} const *Vec<{0}>::data() const noexcept {{", inner); writeln!(out, " return cxxbridge1$rust_vec${}$data(this);", instance); writeln!(out, "}}"); @@ -1711,7 +1708,7 @@ fn write_unique_ptr_common(out: &mut OutFile, ty: UniquePtr) { begin_function_definition(out); writeln!( out, - "const {} *cxxbridge1$unique_ptr${}$get(const ::std::unique_ptr<{}>& ptr) noexcept {{", + "{} const *cxxbridge1$unique_ptr${}$get(::std::unique_ptr<{}> const &ptr) noexcept {{", inner, instance, inner, ); writeln!(out, " return ptr.get();"); @@ -1719,7 +1716,7 @@ fn write_unique_ptr_common(out: &mut OutFile, ty: UniquePtr) { begin_function_definition(out); writeln!( out, - "{} *cxxbridge1$unique_ptr${}$release(::std::unique_ptr<{}>& ptr) noexcept {{", + "{} *cxxbridge1$unique_ptr${}$release(::std::unique_ptr<{}> &ptr) noexcept {{", inner, instance, inner, ); writeln!(out, " return ptr.release();"); @@ -1796,7 +1793,7 @@ fn write_shared_ptr(out: &mut OutFile, key: NamedImplKey) { begin_function_definition(out); writeln!( out, - "void cxxbridge1$shared_ptr${}$clone(const ::std::shared_ptr<{}>& self, ::std::shared_ptr<{}> *ptr) noexcept {{", + "void cxxbridge1$shared_ptr${}$clone(::std::shared_ptr<{}> const &self, ::std::shared_ptr<{}> *ptr) noexcept {{", instance, inner, inner, ); writeln!(out, " ::new (ptr) ::std::shared_ptr<{}>(self);", inner); @@ -1804,7 +1801,7 @@ fn write_shared_ptr(out: &mut OutFile, key: NamedImplKey) { begin_function_definition(out); writeln!( out, - "const {} *cxxbridge1$shared_ptr${}$get(const ::std::shared_ptr<{}>& self) noexcept {{", + "{} const *cxxbridge1$shared_ptr${}$get(::std::shared_ptr<{}> const &self) noexcept {{", inner, instance, inner, ); writeln!(out, " return self.get();"); @@ -1847,7 +1844,7 @@ fn write_weak_ptr(out: &mut OutFile, key: NamedImplKey) { begin_function_definition(out); writeln!( out, - "void cxxbridge1$weak_ptr${}$clone(const ::std::weak_ptr<{}>& self, ::std::weak_ptr<{}> *ptr) noexcept {{", + "void cxxbridge1$weak_ptr${}$clone(::std::weak_ptr<{}> const &self, ::std::weak_ptr<{}> *ptr) noexcept {{", instance, inner, inner, ); writeln!(out, " ::new (ptr) ::std::weak_ptr<{}>(self);", inner); @@ -1855,7 +1852,7 @@ fn write_weak_ptr(out: &mut OutFile, key: NamedImplKey) { begin_function_definition(out); writeln!( out, - "void cxxbridge1$weak_ptr${}$downgrade(const ::std::shared_ptr<{}>& shared, ::std::weak_ptr<{}> *weak) noexcept {{", + "void cxxbridge1$weak_ptr${}$downgrade(::std::shared_ptr<{}> const &shared, ::std::weak_ptr<{}> *weak) noexcept {{", instance, inner, inner, ); writeln!(out, " ::new (weak) ::std::weak_ptr<{}>(shared);", inner); @@ -1863,7 +1860,7 @@ fn write_weak_ptr(out: &mut OutFile, key: NamedImplKey) { begin_function_definition(out); writeln!( out, - "void cxxbridge1$weak_ptr${}$upgrade(const ::std::weak_ptr<{}>& weak, ::std::shared_ptr<{}> *shared) noexcept {{", + "void cxxbridge1$weak_ptr${}$upgrade(::std::weak_ptr<{}> const &weak, ::std::shared_ptr<{}> *shared) noexcept {{", instance, inner, inner, ); writeln!( @@ -1893,7 +1890,7 @@ fn write_cxx_vector(out: &mut OutFile, key: NamedImplKey) { writeln!( out, - "::std::size_t cxxbridge1$std$vector${}$size(const ::std::vector<{}> &s) noexcept {{", + "::std::size_t cxxbridge1$std$vector${}$size(::std::vector<{}> const &s) noexcept {{", instance, inner, ); writeln!(out, " return s.size();"); diff --git a/macro/Android.bp b/macro/Android.bp index 6f418506..6f6b12a3 100644 --- a/macro/Android.bp +++ b/macro/Android.bp @@ -1,4 +1,5 @@ // This file is generated by cargo2android.py --run --dependencies --add_workspace. +// Do not modify this file as changes will be overridden on upgrade. package { // See: http://go/android-license-faq @@ -13,6 +14,8 @@ package { rust_proc_macro { name: "libcxxbridge_macro", crate_name: "cxxbridge_macro", + cargo_env_compat: true, + cargo_pkg_version: "1.0.85", srcs: ["src/lib.rs"], edition: "2018", rustlibs: [ @@ -21,9 +24,3 @@ rust_proc_macro { "libsyn", ], } - -// dependent_library ["feature_list"] -// proc-macro2-1.0.19 "default,proc-macro" -// quote-1.0.7 "default,proc-macro" -// syn-1.0.36 "clone-impls,default,derive,full,parsing,printing,proc-macro,quote" -// unicode-xid-0.2.1 "default" diff --git a/macro/Cargo.toml b/macro/Cargo.toml index 31e8f1b7..ed230388 100644 --- a/macro/Cargo.toml +++ b/macro/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cxxbridge-macro" -version = "1.0.77" +version = "1.0.85" authors = ["David Tolnay <dtolnay@gmail.com>"] categories = ["development-tools::ffi"] description = "Implementation detail of the `cxx` crate." diff --git a/macro/src/load.rs b/macro/src/load.rs index a9958aee..dccece44 100644 --- a/macro/src/load.rs +++ b/macro/src/load.rs @@ -264,7 +264,7 @@ fn translate_qual_type(cx: &mut Errors, enm: &Enum, qual_type: &str) -> Path { .unwrap() .span(); let ident = Ident::new(rust_std_name, span); - let path = quote_spanned!(span=> ::std::os::raw::#ident); + let path = quote_spanned!(span=> ::cxx::core::ffi::#ident); parse_quote!(#path) } diff --git a/macro/src/tokens.rs b/macro/src/tokens.rs index 135be9ae..805af227 100644 --- a/macro/src/tokens.rs +++ b/macro/src/tokens.rs @@ -33,7 +33,7 @@ impl ToTokens for ReceiverType<'_> { mutability, } = &self.0; if let Some((pin, langle, _rangle)) = pin_tokens { - tokens.extend(quote_spanned!(pin.span=> ::std::pin::Pin)); + tokens.extend(quote_spanned!(pin.span=> ::cxx::core::pin::Pin)); langle.to_tokens(tokens); } ampersand.to_tokens(tokens); @@ -61,7 +61,7 @@ impl ToTokens for ReceiverTypeSelf<'_> { mutability, } = &self.0; if let Some((pin, langle, _rangle)) = pin_tokens { - tokens.extend(quote_spanned!(pin.span=> ::std::pin::Pin)); + tokens.extend(quote_spanned!(pin.span=> ::cxx::core::pin::Pin)); langle.to_tokens(tokens); } ampersand.to_tokens(tokens); diff --git a/macro/src/type_id.rs b/macro/src/type_id.rs index 74f0c1c9..7bca67b1 100644 --- a/macro/src/type_id.rs +++ b/macro/src/type_id.rs @@ -1,6 +1,7 @@ use crate::syntax::qualified::QualifiedName; use proc_macro2::{TokenStream, TokenTree}; use quote::{format_ident, quote, ToTokens}; +use syn::ext::IdentExt; pub enum Crate { Cxx, @@ -24,7 +25,7 @@ pub fn expand(krate: Crate, arg: QualifiedName) -> TokenStream { if !ids.is_empty() { ids.push(quote!(())); } - for ch in word.to_string().chars() { + for ch in word.unraw().to_string().chars() { ids.push(match ch { 'A'..='Z' | 'a'..='z' => { let t = format_ident!("{}", ch); diff --git a/src/c_char.rs b/src/c_char.rs index a0d41803..333d8491 100644 --- a/src/c_char.rs +++ b/src/c_char.rs @@ -1,5 +1,4 @@ -#![cfg(feature = "alloc")] - +#[allow(missing_docs)] pub type c_char = c_char_definition::c_char; // Validate that our definition is consistent with libstd's definition, without @@ -506,6 +506,17 @@ union MaybeUninit { }; } // namespace +namespace repr { +struct PtrLen final { + void *ptr; + std::size_t len; +}; +} // namespace repr + +extern "C" { +repr::PtrLen cxxbridge1$exception(const char *, std::size_t len) noexcept; +} + namespace detail { // On some platforms size_t is the same C++ type as one of the sized integer // types; on others it is a distinct type. Only in the latter case do we need to @@ -519,6 +530,23 @@ using isize_if_unique = typename std::conditional<std::is_same<rust::isize, int64_t>::value || std::is_same<rust::isize, int32_t>::value, struct isize_ignore, rust::isize>::type; + +class Fail final { + repr::PtrLen &throw$; + +public: + Fail(repr::PtrLen &throw$) noexcept : throw$(throw$) {} + void operator()(const char *) noexcept; + void operator()(const std::string &) noexcept; +}; + +void Fail::operator()(const char *catch$) noexcept { + throw$ = cxxbridge1$exception(catch$, std::strlen(catch$)); +} + +void Fail::operator()(const std::string &catch$) noexcept { + throw$ = cxxbridge1$exception(catch$.data(), catch$.length()); +} } // namespace detail } // namespace cxxbridge1 @@ -364,7 +364,7 @@ //! </table> #![no_std] -#![doc(html_root_url = "https://docs.rs/cxx/1.0.77")] +#![doc(html_root_url = "https://docs.rs/cxx/1.0.85")] #![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))] @@ -490,6 +490,7 @@ pub type Vector<T> = CxxVector<T>; // Not public API. #[doc(hidden)] pub mod private { + pub use crate::c_char::c_char; pub use crate::cxx_vector::VectorElement; pub use crate::extern_type::{verify_extern_kind, verify_extern_type}; pub use crate::function::FatFunction; diff --git a/src/result.rs b/src/result.rs index c0aa8d5e..ba77858e 100644 --- a/src/result.rs +++ b/src/result.rs @@ -12,9 +12,9 @@ use core::str; #[repr(C)] #[derive(Copy, Clone)] -struct PtrLen { - ptr: NonNull<u8>, - len: usize, +pub struct PtrLen { + pub ptr: NonNull<u8>, + pub len: usize, } #[repr(C)] diff --git a/src/symbols/exception.rs b/src/symbols/exception.rs index 845e8ab6..b8fe1b5d 100644 --- a/src/symbols/exception.rs +++ b/src/symbols/exception.rs @@ -1,12 +1,18 @@ #![cfg(feature = "alloc")] +use crate::result::PtrLen; use alloc::boxed::Box; use alloc::string::String; +use core::ptr::NonNull; use core::slice; #[export_name = "cxxbridge1$exception"] -unsafe extern "C" fn exception(ptr: *const u8, len: usize) -> *const u8 { +unsafe extern "C" fn exception(ptr: *const u8, len: usize) -> PtrLen { let slice = unsafe { slice::from_raw_parts(ptr, len) }; - let boxed = String::from_utf8_lossy(slice).into_owned().into_boxed_str(); - Box::leak(boxed).as_ptr() + let string = String::from_utf8_lossy(slice); + let len = string.len(); + let raw_str = Box::into_raw(string.into_owned().into_boxed_str()); + let raw_u8 = raw_str.cast::<u8>(); + let nonnull = unsafe { NonNull::new_unchecked(raw_u8) }; + PtrLen { ptr: nonnull, len } } diff --git a/syntax/qualified.rs b/syntax/qualified.rs index 96f07c19..5f182fa9 100644 --- a/syntax/qualified.rs +++ b/syntax/qualified.rs @@ -1,5 +1,5 @@ use syn::ext::IdentExt; -use syn::parse::{ParseStream, Result}; +use syn::parse::{Error, ParseStream, Result}; use syn::{Ident, LitStr, Token}; pub struct QualifiedName { @@ -8,21 +8,8 @@ pub struct QualifiedName { impl QualifiedName { pub fn parse_unquoted(input: ParseStream) -> Result<Self> { - let mut segments = Vec::new(); - let mut trailing_punct = true; - let leading_colons: Option<Token![::]> = input.parse()?; - while trailing_punct && input.peek(Ident::peek_any) { - let ident = Ident::parse_any(input)?; - segments.push(ident); - let colons: Option<Token![::]> = input.parse()?; - trailing_punct = colons.is_some(); - } - if segments.is_empty() && leading_colons.is_none() { - return Err(input.error("expected path")); - } else if trailing_punct { - return Err(input.error("expected path segment")); - } - Ok(QualifiedName { segments }) + let allow_raw = true; + parse_unquoted(input, allow_raw) } pub fn parse_quoted_or_unquoted(input: ParseStream) -> Result<Self> { @@ -32,10 +19,41 @@ impl QualifiedName { let segments = Vec::new(); Ok(QualifiedName { segments }) } else { - lit.parse_with(Self::parse_unquoted) + lit.parse_with(|input: ParseStream| { + let allow_raw = false; + parse_unquoted(input, allow_raw) + }) } } else { Self::parse_unquoted(input) } } } + +fn parse_unquoted(input: ParseStream, allow_raw: bool) -> Result<QualifiedName> { + let mut segments = Vec::new(); + let mut trailing_punct = true; + let leading_colons: Option<Token![::]> = input.parse()?; + while trailing_punct && input.peek(Ident::peek_any) { + let mut ident = Ident::parse_any(input)?; + if let Some(unraw) = ident.to_string().strip_prefix("r#") { + if !allow_raw { + let msg = format!( + "raw identifier `{}` is not allowed in a quoted namespace; use `{}`, or remove quotes", + ident, unraw, + ); + return Err(Error::new(ident.span(), msg)); + } + ident = Ident::new(unraw, ident.span()); + } + segments.push(ident); + let colons: Option<Token![::]> = input.parse()?; + trailing_punct = colons.is_some(); + } + if segments.is_empty() && leading_colons.is_none() { + return Err(input.error("expected path")); + } else if trailing_punct { + return Err(input.error("expected path segment")); + } + Ok(QualifiedName { segments }) +} diff --git a/syntax/tokens.rs b/syntax/tokens.rs index 62d37c23..a9f42bd4 100644 --- a/syntax/tokens.rs +++ b/syntax/tokens.rs @@ -13,10 +13,13 @@ impl ToTokens for Type { Type::Ident(ident) => { if ident.rust == Char { let span = ident.rust.span(); - tokens.extend(quote_spanned!(span=> ::std::os::raw::)); + tokens.extend(quote_spanned!(span=> ::cxx::private::)); } else if ident.rust == CxxString { let span = ident.rust.span(); tokens.extend(quote_spanned!(span=> ::cxx::)); + } else if ident.rust == RustString { + let span = ident.rust.span(); + tokens.extend(quote_spanned!(span=> ::cxx::alloc::string::)); } ident.to_tokens(tokens); } @@ -66,8 +69,11 @@ impl ToTokens for Ty1 { "UniquePtr" | "SharedPtr" | "WeakPtr" | "CxxVector" => { tokens.extend(quote_spanned!(span=> ::cxx::)); } + "Box" => { + tokens.extend(quote_spanned!(span=> ::cxx::alloc::boxed::)); + } "Vec" => { - tokens.extend(quote_spanned!(span=> ::std::vec::)); + tokens.extend(quote_spanned!(span=> ::cxx::alloc::vec::)); } _ => {} } @@ -90,7 +96,7 @@ impl ToTokens for Ref { mutability, } = self; if let Some((pin, langle, _rangle)) = pin_tokens { - tokens.extend(quote_spanned!(pin.span=> ::std::pin::Pin)); + tokens.extend(quote_spanned!(pin.span=> ::cxx::core::pin::Pin)); langle.to_tokens(tokens); } ampersand.to_tokens(tokens); @@ -32,20 +32,26 @@ cxx_library( ":bridge/source", ":module/source", ], - headers = { + exported_deps = ["//:core"], + exported_headers = { "ffi/lib.rs.h": ":bridge/header", "ffi/module.rs.h": ":module/header", "ffi/tests.h": "ffi/tests.h", }, - deps = ["//:core"], ) rust_cxx_bridge( name = "bridge", src = "ffi/lib.rs", + deps = [ + ":impl", + ], ) rust_cxx_bridge( name = "module", src = "ffi/module.rs", + deps = [ + ":impl", + ], ) diff --git a/tests/ffi/tests.cc b/tests/ffi/tests.cc index 3398c073..984e2220 100644 --- a/tests/ffi/tests.cc +++ b/tests/ffi/tests.cc @@ -177,9 +177,7 @@ rust::Vec<rust::String> c_return_rust_vec_string() { return {"2", "0", "2", "0"}; } -rust::Vec<bool> c_return_rust_vec_bool() { - return {true, true, false}; -} +rust::Vec<bool> c_return_rust_vec_bool() { return {true, true, false}; } size_t c_return_identity(size_t n) { return n; } diff --git a/tests/ui/derive_duplicate.stderr b/tests/ui/derive_duplicate.stderr index 33683052..75920862 100644 --- a/tests/ui/derive_duplicate.stderr +++ b/tests/ui/derive_duplicate.stderr @@ -1,7 +1,7 @@ -error[E0119]: conflicting implementations of trait `std::clone::Clone` for type `ffi::Struct` +error[E0119]: conflicting implementations of trait `Clone` for type `Struct` --> tests/ui/derive_duplicate.rs:3:21 | 3 | #[derive(Clone, Clone)] - | ----- ^^^^^ conflicting implementation for `ffi::Struct` + | ----- ^^^^^ conflicting implementation for `Struct` | | | first implementation here diff --git a/tests/ui/drop_shared.stderr b/tests/ui/drop_shared.stderr index e8911ca4..41a5287f 100644 --- a/tests/ui/drop_shared.stderr +++ b/tests/ui/drop_shared.stderr @@ -1,8 +1,8 @@ -error[E0119]: conflicting implementations of trait `ffi::_::forbid::Drop` for type `ffi::Shared` +error[E0119]: conflicting implementations of trait `forbid::Drop` for type `Shared` --> tests/ui/drop_shared.rs:3:5 | 1 | #[cxx::bridge] | -------------- first implementation here 2 | mod ffi { 3 | struct Shared { - | ^^^^^^^^^^^^^ conflicting implementation for `ffi::Shared` + | ^^^^^^^^^^^^^ conflicting implementation for `Shared` diff --git a/tests/ui/include.stderr b/tests/ui/include.stderr index c1541c60..45cc5591 100644 --- a/tests/ui/include.stderr +++ b/tests/ui/include.stderr @@ -26,4 +26,4 @@ error: expected "quoted/path/to" or <bracketed/path/to> --> tests/ui/include.rs:8:18 | 8 | include!(...); - | ^^^ + | ^ diff --git a/tests/ui/missing_unsafe.stderr b/tests/ui/missing_unsafe.stderr index 263564ed..e7dcba74 100644 --- a/tests/ui/missing_unsafe.stderr +++ b/tests/ui/missing_unsafe.stderr @@ -2,6 +2,8 @@ error[E0133]: call to unsafe function is unsafe and requires unsafe function or --> tests/ui/missing_unsafe.rs:4:12 | 4 | fn f(x: i32); - | ^ call to unsafe function + | ^ - items do not inherit unsafety from separate enclosing items + | | + | call to unsafe function | = note: consult the function's documentation for information on how to avoid undefined behavior diff --git a/tests/ui/nonlocal_rust_type.stderr b/tests/ui/nonlocal_rust_type.stderr index dee91955..f6cb06cb 100644 --- a/tests/ui/nonlocal_rust_type.stderr +++ b/tests/ui/nonlocal_rust_type.stderr @@ -13,7 +13,7 @@ error[E0117]: only traits defined in the current crate can be implemented for ty --> tests/ui/nonlocal_rust_type.rs:14:13 | 14 | rs: Box<OptBuilder<'a>>, - | ^^^^--------------- + | ^^^^-------------- | | | | | `Option` is not defined in the current crate | impl doesn't use only types from inside the current crate diff --git a/tests/ui/ptr_no_const_mut.stderr b/tests/ui/ptr_no_const_mut.stderr index 8402120a..4b1bf06f 100644 --- a/tests/ui/ptr_no_const_mut.stderr +++ b/tests/ui/ptr_no_const_mut.stderr @@ -1,10 +1,15 @@ -error: expected mut or const in raw pointer type +error: expected `mut` or `const` keyword in raw pointer type --> tests/ui/ptr_no_const_mut.rs:6:43 | 6 | fn get_neither_const_nor_mut() -> *C; - | ^ expected mut or const in raw pointer type + | ^ | - = help: use `*mut T` or `*const T` as appropriate +help: add `mut` or `const` here + | +6 | fn get_neither_const_nor_mut() -> *const C; + | +++++ +6 | fn get_neither_const_nor_mut() -> *mut C; + | +++ error: expected `const` or `mut` --> tests/ui/ptr_no_const_mut.rs:6:44 diff --git a/tests/ui/ptr_unsupported.stderr b/tests/ui/ptr_unsupported.stderr index fd3f0314..ea1dafd8 100644 --- a/tests/ui/ptr_unsupported.stderr +++ b/tests/ui/ptr_unsupported.stderr @@ -14,4 +14,4 @@ error: unsupported vector element type --> tests/ui/ptr_unsupported.rs:8:45 | 8 | fn get_vector_of_ptr() -> UniquePtr<CxxVector<*mut C>>; - | ^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/raw_ident_namespace.rs b/tests/ui/raw_ident_namespace.rs new file mode 100644 index 00000000..2c8286c7 --- /dev/null +++ b/tests/ui/raw_ident_namespace.rs @@ -0,0 +1,53 @@ +use cxx::{type_id, ExternType}; + +#[repr(transparent)] +pub struct QuotedRaw(usize); + +unsafe impl ExternType for QuotedRaw { + type Id = type_id!("org::r#box::implementation::QuotedRaw"); + type Kind = cxx::kind::Trivial; +} + +#[repr(transparent)] +pub struct QuotedKeyword(usize); + +unsafe impl ExternType for QuotedKeyword { + type Id = type_id!("org::box::implementation::QuotedKeyword"); + type Kind = cxx::kind::Trivial; +} + +#[repr(transparent)] +pub struct UnquotedRaw(usize); + +unsafe impl ExternType for UnquotedRaw { + type Id = type_id!(org::r#box::implementation::UnquotedRaw); + type Kind = cxx::kind::Trivial; +} + +#[repr(transparent)] +pub struct UnquotedKeyword(usize); + +unsafe impl ExternType for UnquotedKeyword { + type Id = type_id!(org::box::implementation::UnquotedKeyword); + type Kind = cxx::kind::Trivial; +} + +#[cxx::bridge] +pub mod ffi { + extern "C++" { + #[namespace = "org::r#box::implementation"] + type QuotedRaw = crate::QuotedRaw; + + #[namespace = "org::box::implementation"] + type QuotedKeyword = crate::QuotedKeyword; + + #[namespace = org::r#box::implementation] + type UnquotedRaw = crate::UnquotedRaw; + + // Not allowed by rustc (independent of cxx): + // #[namespace = org::box::implementation] + // type UnquotedKeyword = crate::UnquotedKeyword; + } +} + +fn main() {} diff --git a/tests/ui/raw_ident_namespace.stderr b/tests/ui/raw_ident_namespace.stderr new file mode 100644 index 00000000..86c8b6fd --- /dev/null +++ b/tests/ui/raw_ident_namespace.stderr @@ -0,0 +1,11 @@ +error: raw identifier `r#box` is not allowed in a quoted namespace; use `box`, or remove quotes + --> tests/ui/raw_ident_namespace.rs:7:24 + | +7 | type Id = type_id!("org::r#box::implementation::QuotedRaw"); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: raw identifier `r#box` is not allowed in a quoted namespace; use `box`, or remove quotes + --> tests/ui/raw_ident_namespace.rs:38:23 + | +38 | #[namespace = "org::r#box::implementation"] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/slice_of_type_alias.stderr b/tests/ui/slice_of_type_alias.stderr index a75caa4f..9339da37 100644 --- a/tests/ui/slice_of_type_alias.stderr +++ b/tests/ui/slice_of_type_alias.stderr @@ -1,16 +1,16 @@ error[E0271]: type mismatch resolving `<ElementOpaque as ExternType>::Kind == Trivial` - --> tests/ui/slice_of_type_alias.rs:13:14 - | -13 | type ElementOpaque = crate::ElementOpaque; - | ^^^^^^^^^^^^^ type mismatch resolving `<ElementOpaque as ExternType>::Kind == Trivial` - | + --> tests/ui/slice_of_type_alias.rs:13:14 + | +13 | type ElementOpaque = crate::ElementOpaque; + | ^^^^^^^^^^^^^ type mismatch resolving `<ElementOpaque as ExternType>::Kind == Trivial` + | note: expected this to be `Trivial` - --> tests/ui/slice_of_type_alias.rs:27:17 - | -27 | type Kind = cxx::kind::Opaque; - | ^^^^^^^^^^^^^^^^^ + --> tests/ui/slice_of_type_alias.rs:27:17 + | +27 | type Kind = cxx::kind::Opaque; + | ^^^^^^^^^^^^^^^^^ note: required by a bound in `verify_extern_kind` - --> src/extern_type.rs - | - | pub fn verify_extern_kind<T: ExternType<Kind = Kind>, Kind: self::Kind>() {} - | ^^^^^^^^^^^ required by this bound in `verify_extern_kind` + --> src/extern_type.rs + | + | pub fn verify_extern_kind<T: ExternType<Kind = Kind>, Kind: self::Kind>() {} + | ^^^^^^^^^^^ required by this bound in `verify_extern_kind` diff --git a/tests/ui/unique_ptr_twice.stderr b/tests/ui/unique_ptr_twice.stderr index 1315e064..b21791fb 100644 --- a/tests/ui/unique_ptr_twice.stderr +++ b/tests/ui/unique_ptr_twice.stderr @@ -1,4 +1,4 @@ -error[E0119]: conflicting implementations of trait `cxx::memory::UniquePtrTarget` for type `here::C` +error[E0119]: conflicting implementations of trait `UniquePtrTarget` for type `here::C` --> tests/ui/unique_ptr_twice.rs:16:5 | 7 | impl UniquePtr<C> {} diff --git a/tests/ui/unpin_impl.rs b/tests/ui/unpin_impl.rs new file mode 100644 index 00000000..129fcb11 --- /dev/null +++ b/tests/ui/unpin_impl.rs @@ -0,0 +1,10 @@ +#[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 new file mode 100644 index 00000000..18099bb6 --- /dev/null +++ b/tests/ui/unpin_impl.stderr @@ -0,0 +1,20 @@ +error[E0282]: type annotations needed + --> tests/ui/unpin_impl.rs:1:1 + | +1 | #[cxx::bridge] + | ^^^^^^^^^^^^^^ cannot infer type of the type parameter `Self` declared on the trait `__AmbiguousIfImpl` + | + = note: this error originates in the attribute macro `cxx::bridge` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0283]: type annotations needed + --> tests/ui/unpin_impl.rs:1:1 + | +1 | #[cxx::bridge] + | ^^^^^^^^^^^^^^ cannot infer type of the type parameter `Self` declared on the trait `__AmbiguousIfImpl` + | +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/vec_opaque.stderr b/tests/ui/vec_opaque.stderr index 22416fdf..cd038e66 100644 --- a/tests/ui/vec_opaque.stderr +++ b/tests/ui/vec_opaque.stderr @@ -11,13 +11,13 @@ error: needs a cxx::ExternType impl in order to be used as a vector element in V | ^^^^^^^^ error[E0271]: type mismatch resolving `<handle::Job as ExternType>::Kind == Trivial` - --> tests/ui/vec_opaque.rs:22:14 - | -22 | type Job = crate::handle::Job; - | ^^^ expected enum `Trivial`, found enum `cxx::kind::Opaque` - | + --> tests/ui/vec_opaque.rs:22:14 + | +22 | type Job = crate::handle::Job; + | ^^^ expected enum `Trivial`, found enum `Opaque` + | note: required by a bound in `verify_extern_kind` - --> src/extern_type.rs - | - | pub fn verify_extern_kind<T: ExternType<Kind = Kind>, Kind: self::Kind>() {} - | ^^^^^^^^^^^ required by this bound in `verify_extern_kind` + --> src/extern_type.rs + | + | pub fn verify_extern_kind<T: ExternType<Kind = Kind>, Kind: self::Kind>() {} + | ^^^^^^^^^^^ required by this bound in `verify_extern_kind` diff --git a/tests/ui/wrong_type_id.stderr b/tests/ui/wrong_type_id.stderr index 56fae3fe..8cb78980 100644 --- a/tests/ui/wrong_type_id.stderr +++ b/tests/ui/wrong_type_id.stderr @@ -1,13 +1,13 @@ error[E0271]: type mismatch resolving `<StringPiece as ExternType>::Id == (f, o, l, l, y, (), B, y, t, e, R, a, n, g, e)` - --> tests/ui/wrong_type_id.rs:11:14 - | -11 | type ByteRange = crate::here::StringPiece; - | ^^^^^^^^^ expected a tuple with 15 elements, found one with 17 elements - | - = note: expected tuple `(f, o, l, l, y, (), B, y, t, e, R, a, n, g, e)` - found tuple `(f, o, l, l, y, (), S, t, r, i, n, g, P, i, e, c, e)` + --> tests/ui/wrong_type_id.rs:11:14 + | +11 | type ByteRange = crate::here::StringPiece; + | ^^^^^^^^^ expected a tuple with 15 elements, found one with 17 elements + | + = note: expected tuple `(f, o, l, l, y, (), B, y, t, e, R, a, n, g, e)` + found tuple `(f, o, l, l, y, (), S, t, r, i, n, g, P, i, e, c, e)` note: required by a bound in `verify_extern_type` - --> src/extern_type.rs - | - | pub fn verify_extern_type<T: ExternType<Id = Id>, Id>() {} - | ^^^^^^^ required by this bound in `verify_extern_type` + --> src/extern_type.rs + | + | pub fn verify_extern_type<T: ExternType<Id = Id>, Id>() {} + | ^^^^^^^ required by this bound in `verify_extern_type` diff --git a/third-party/.gitignore b/third-party/.gitignore index 61ead866..b0509488 100644 --- a/third-party/.gitignore +++ b/third-party/.gitignore @@ -1 +1,2 @@ +/.cargo /vendor diff --git a/third-party/BUCK b/third-party/BUCK index b4545ff2..8036117e 100644 --- a/third-party/BUCK +++ b/third-party/BUCK @@ -1,166 +1,540 @@ -# To be generated by Facebook's `reindeer` tool once that is open source. +# @generated by `reindeer buckify` -load("//tools/buck:rust_library.bzl", "rust_library") +load("//tools/buck:buildscript.bzl", "buildscript_args") rust_library( - name = "bitflags", - srcs = glob(["vendor/bitflags-1.3.2/src/**/*.rs"]), + name = "bitflags-1.3.2", + srcs = [ + "vendor/bitflags-1.3.2/src/example_generated.rs", + "vendor/bitflags-1.3.2/src/lib.rs", + ], + crate = "bitflags", + crate_root = "vendor/bitflags-1.3.2/src/lib.rs", edition = "2018", + features = ["default"], + rustc_flags = ["--cap-lints=allow"], + visibility = [], ) -rust_library( +alias( name = "cc", - srcs = glob(["vendor/cc-1.0.73/src/**/*.rs"]), - edition = "2018", + actual = ":cc-1.0.77", visibility = ["PUBLIC"], ) rust_library( - name = "clap", - srcs = glob(["vendor/clap-3.2.22/src/**/*.rs"]) + [ - "vendor/clap-3.2.22/examples/demo.md", - "vendor/clap-3.2.22/examples/demo.rs", + name = "cc-1.0.77", + srcs = [ + "vendor/cc-1.0.77/src/com.rs", + "vendor/cc-1.0.77/src/lib.rs", + "vendor/cc-1.0.77/src/registry.rs", + "vendor/cc-1.0.77/src/setup_config.rs", + "vendor/cc-1.0.77/src/vs_instances.rs", + "vendor/cc-1.0.77/src/winapi.rs", + "vendor/cc-1.0.77/src/windows_registry.rs", ], - edition = "2021", - features = ["std"], + crate = "cc", + crate_root = "vendor/cc-1.0.77/src/lib.rs", + edition = "2018", + rustc_flags = ["--cap-lints=allow"], + visibility = [], +) + +alias( + name = "clap", + actual = ":clap-4.0.29", visibility = ["PUBLIC"], - deps = [ - ":bitflags", - ":clap_lex", - ":indexmap", - ":textwrap", - ], ) rust_library( - name = "clap_lex", - srcs = glob(["vendor/clap_lex-0.2.4/src/**/*.rs"]), + name = "clap-4.0.29", + srcs = [ + "vendor/clap-4.0.29/examples/demo.md", + "vendor/clap-4.0.29/examples/demo.rs", + "vendor/clap-4.0.29/src/_cookbook/cargo_example.rs", + "vendor/clap-4.0.29/src/_cookbook/cargo_example_derive.rs", + "vendor/clap-4.0.29/src/_cookbook/escaped_positional.rs", + "vendor/clap-4.0.29/src/_cookbook/escaped_positional_derive.rs", + "vendor/clap-4.0.29/src/_cookbook/find.rs", + "vendor/clap-4.0.29/src/_cookbook/git.rs", + "vendor/clap-4.0.29/src/_cookbook/git_derive.rs", + "vendor/clap-4.0.29/src/_cookbook/mod.rs", + "vendor/clap-4.0.29/src/_cookbook/multicall_busybox.rs", + "vendor/clap-4.0.29/src/_cookbook/multicall_hostname.rs", + "vendor/clap-4.0.29/src/_cookbook/pacman.rs", + "vendor/clap-4.0.29/src/_cookbook/repl.rs", + "vendor/clap-4.0.29/src/_cookbook/typed_derive.rs", + "vendor/clap-4.0.29/src/_derive/_tutorial.rs", + "vendor/clap-4.0.29/src/_derive/mod.rs", + "vendor/clap-4.0.29/src/_faq.rs", + "vendor/clap-4.0.29/src/_features.rs", + "vendor/clap-4.0.29/src/_tutorial.rs", + "vendor/clap-4.0.29/src/builder/action.rs", + "vendor/clap-4.0.29/src/builder/app_settings.rs", + "vendor/clap-4.0.29/src/builder/arg.rs", + "vendor/clap-4.0.29/src/builder/arg_group.rs", + "vendor/clap-4.0.29/src/builder/arg_predicate.rs", + "vendor/clap-4.0.29/src/builder/arg_settings.rs", + "vendor/clap-4.0.29/src/builder/command.rs", + "vendor/clap-4.0.29/src/builder/debug_asserts.rs", + "vendor/clap-4.0.29/src/builder/mod.rs", + "vendor/clap-4.0.29/src/builder/os_str.rs", + "vendor/clap-4.0.29/src/builder/possible_value.rs", + "vendor/clap-4.0.29/src/builder/range.rs", + "vendor/clap-4.0.29/src/builder/resettable.rs", + "vendor/clap-4.0.29/src/builder/str.rs", + "vendor/clap-4.0.29/src/builder/styled_str.rs", + "vendor/clap-4.0.29/src/builder/tests.rs", + "vendor/clap-4.0.29/src/builder/value_hint.rs", + "vendor/clap-4.0.29/src/builder/value_parser.rs", + "vendor/clap-4.0.29/src/derive.rs", + "vendor/clap-4.0.29/src/error/context.rs", + "vendor/clap-4.0.29/src/error/format.rs", + "vendor/clap-4.0.29/src/error/kind.rs", + "vendor/clap-4.0.29/src/error/mod.rs", + "vendor/clap-4.0.29/src/lib.rs", + "vendor/clap-4.0.29/src/macros.rs", + "vendor/clap-4.0.29/src/mkeymap.rs", + "vendor/clap-4.0.29/src/output/fmt.rs", + "vendor/clap-4.0.29/src/output/help.rs", + "vendor/clap-4.0.29/src/output/help_template.rs", + "vendor/clap-4.0.29/src/output/mod.rs", + "vendor/clap-4.0.29/src/output/textwrap/core.rs", + "vendor/clap-4.0.29/src/output/textwrap/mod.rs", + "vendor/clap-4.0.29/src/output/textwrap/word_separators.rs", + "vendor/clap-4.0.29/src/output/textwrap/wrap_algorithms.rs", + "vendor/clap-4.0.29/src/output/usage.rs", + "vendor/clap-4.0.29/src/parser/arg_matcher.rs", + "vendor/clap-4.0.29/src/parser/error.rs", + "vendor/clap-4.0.29/src/parser/features/mod.rs", + "vendor/clap-4.0.29/src/parser/features/suggestions.rs", + "vendor/clap-4.0.29/src/parser/matches/any_value.rs", + "vendor/clap-4.0.29/src/parser/matches/arg_matches.rs", + "vendor/clap-4.0.29/src/parser/matches/matched_arg.rs", + "vendor/clap-4.0.29/src/parser/matches/mod.rs", + "vendor/clap-4.0.29/src/parser/matches/value_source.rs", + "vendor/clap-4.0.29/src/parser/mod.rs", + "vendor/clap-4.0.29/src/parser/parser.rs", + "vendor/clap-4.0.29/src/parser/validator.rs", + "vendor/clap-4.0.29/src/util/color.rs", + "vendor/clap-4.0.29/src/util/flat_map.rs", + "vendor/clap-4.0.29/src/util/flat_set.rs", + "vendor/clap-4.0.29/src/util/graph.rs", + "vendor/clap-4.0.29/src/util/id.rs", + "vendor/clap-4.0.29/src/util/mod.rs", + "vendor/clap-4.0.29/src/util/str_to_bool.rs", + ], + crate = "clap", + crate_root = "vendor/clap-4.0.29/src/lib.rs", edition = "2021", + features = [ + "error-context", + "help", + "std", + "usage", + ], + rustc_flags = ["--cap-lints=allow"], + visibility = [], deps = [ - ":os_str_bytes", + ":bitflags-1.3.2", + ":clap_lex-0.3.0", ], ) rust_library( + name = "clap_lex-0.3.0", + srcs = ["vendor/clap_lex-0.3.0/src/lib.rs"], + crate = "clap_lex", + crate_root = "vendor/clap_lex-0.3.0/src/lib.rs", + edition = "2021", + rustc_flags = ["--cap-lints=allow"], + visibility = [], + deps = [":os_str_bytes-6.4.1"], +) + +alias( name = "codespan-reporting", - srcs = glob(["vendor/codespan-reporting-0.11.1/src/**/*.rs"]), - edition = "2018", + actual = ":codespan-reporting-0.11.1", visibility = ["PUBLIC"], +) + +rust_library( + name = "codespan-reporting-0.11.1", + srcs = [ + "vendor/codespan-reporting-0.11.1/src/diagnostic.rs", + "vendor/codespan-reporting-0.11.1/src/files.rs", + "vendor/codespan-reporting-0.11.1/src/lib.rs", + "vendor/codespan-reporting-0.11.1/src/term.rs", + "vendor/codespan-reporting-0.11.1/src/term/config.rs", + "vendor/codespan-reporting-0.11.1/src/term/renderer.rs", + "vendor/codespan-reporting-0.11.1/src/term/views.rs", + ], + crate = "codespan_reporting", + crate_root = "vendor/codespan-reporting-0.11.1/src/lib.rs", + edition = "2018", + rustc_flags = ["--cap-lints=allow"], + visibility = [], deps = [ - ":termcolor", - ":unicode-width", + ":termcolor-1.1.3", + ":unicode-width-0.1.10", ], ) +alias( + name = "once_cell", + actual = ":once_cell-1.16.0", + visibility = ["PUBLIC"], +) + rust_library( - name = "hashbrown", - srcs = glob(["vendor/hashbrown-0.12.3/src/**/*.rs"]), + name = "once_cell-1.16.0", + srcs = [ + "vendor/once_cell-1.16.0/src/imp_cs.rs", + "vendor/once_cell-1.16.0/src/imp_pl.rs", + "vendor/once_cell-1.16.0/src/imp_std.rs", + "vendor/once_cell-1.16.0/src/lib.rs", + "vendor/once_cell-1.16.0/src/race.rs", + ], + crate = "once_cell", + crate_root = "vendor/once_cell-1.16.0/src/lib.rs", edition = "2021", - features = ["raw"], + features = [ + "alloc", + "default", + "race", + "std", + ], + rustc_flags = ["--cap-lints=allow"], + visibility = [], ) rust_library( - name = "indexmap", - srcs = glob(["vendor/indexmap-1.9.1/src/**/*.rs"]), + name = "os_str_bytes-6.4.1", + srcs = [ + "vendor/os_str_bytes-6.4.1/src/common/mod.rs", + "vendor/os_str_bytes-6.4.1/src/common/raw.rs", + "vendor/os_str_bytes-6.4.1/src/iter.rs", + "vendor/os_str_bytes-6.4.1/src/lib.rs", + "vendor/os_str_bytes-6.4.1/src/pattern.rs", + "vendor/os_str_bytes-6.4.1/src/raw_str.rs", + "vendor/os_str_bytes-6.4.1/src/util.rs", + "vendor/os_str_bytes-6.4.1/src/wasm/mod.rs", + "vendor/os_str_bytes-6.4.1/src/wasm/raw.rs", + "vendor/os_str_bytes-6.4.1/src/windows/mod.rs", + "vendor/os_str_bytes-6.4.1/src/windows/raw.rs", + "vendor/os_str_bytes-6.4.1/src/windows/wtf8/code_points.rs", + "vendor/os_str_bytes-6.4.1/src/windows/wtf8/convert.rs", + "vendor/os_str_bytes-6.4.1/src/windows/wtf8/mod.rs", + "vendor/os_str_bytes-6.4.1/src/windows/wtf8/string.rs", + ], + crate = "os_str_bytes", + crate_root = "vendor/os_str_bytes-6.4.1/src/lib.rs", edition = "2021", - features = ["std"], - rustc_flags = ["--cfg=has_std"], - deps = [":hashbrown"], + features = ["raw_os_str"], + rustc_flags = ["--cap-lints=allow"], + visibility = [], +) + +alias( + name = "proc-macro2", + actual = ":proc-macro2-1.0.47", + visibility = ["PUBLIC"], ) rust_library( - name = "once_cell", - srcs = glob(["vendor/once_cell-1.15.0/src/**/*.rs"]), + name = "proc-macro2-1.0.47", + srcs = [ + "vendor/proc-macro2-1.0.47/src/detection.rs", + "vendor/proc-macro2-1.0.47/src/fallback.rs", + "vendor/proc-macro2-1.0.47/src/lib.rs", + "vendor/proc-macro2-1.0.47/src/marker.rs", + "vendor/proc-macro2-1.0.47/src/parse.rs", + "vendor/proc-macro2-1.0.47/src/rcvec.rs", + "vendor/proc-macro2-1.0.47/src/wrapper.rs", + ], + crate = "proc_macro2", + crate_root = "vendor/proc-macro2-1.0.47/src/lib.rs", edition = "2018", features = [ - "alloc", - "std", + "default", + "proc-macro", + "span-locations", ], - visibility = ["PUBLIC"], + rustc_flags = [ + "--cap-lints=allow", + "@$(location :proc-macro2-1.0.47-build-script-build-args)", + ], + visibility = [], + deps = [":unicode-ident-1.0.5"], ) -rust_library( - name = "os_str_bytes", - srcs = glob(["vendor/os_str_bytes-6.3.0/src/**/*.rs"]), - edition = "2021", +rust_binary( + name = "proc-macro2-1.0.47-build-script-build", + srcs = ["vendor/proc-macro2-1.0.47/build.rs"], + crate = "build_script_build", + crate_root = "vendor/proc-macro2-1.0.47/build.rs", + edition = "2018", features = [ - "raw_os_str", + "default", + "proc-macro", + "span-locations", ], + rustc_flags = ["--cap-lints=allow"], + visibility = [], ) -rust_library( - name = "proc-macro2", - srcs = glob(["vendor/proc-macro2-1.0.44/src/**/*.rs"]), - build_script = "vendor/proc-macro2-1.0.44/build.rs", - edition = "2018", +buildscript_args( + name = "proc-macro2-1.0.47-build-script-build-args", + package_name = "proc-macro2", + buildscript_rule = ":proc-macro2-1.0.47-build-script-build", + cfgs = [], features = [ + "default", "proc-macro", "span-locations", ], - visibility = ["PUBLIC"], - deps = [":unicode-ident"], + outfile = "args.txt", + version = "1.0.47", ) -rust_library( +alias( name = "quote", - srcs = glob(["vendor/quote-1.0.21/src/**/*.rs"]), - build_script = "vendor/quote-1.0.21/build.rs", - edition = "2018", - features = ["proc-macro"], + actual = ":quote-1.0.21", visibility = ["PUBLIC"], - deps = [":proc-macro2"], ) rust_library( - name = "scratch", - srcs = glob(["vendor/scratch-1.0.2/src/**/*.rs"]), + name = "quote-1.0.21", + srcs = [ + "vendor/quote-1.0.21/src/ext.rs", + "vendor/quote-1.0.21/src/format.rs", + "vendor/quote-1.0.21/src/ident_fragment.rs", + "vendor/quote-1.0.21/src/lib.rs", + "vendor/quote-1.0.21/src/runtime.rs", + "vendor/quote-1.0.21/src/spanned.rs", + "vendor/quote-1.0.21/src/to_tokens.rs", + ], + crate = "quote", + crate_root = "vendor/quote-1.0.21/src/lib.rs", + edition = "2018", + features = [ + "default", + "proc-macro", + ], + rustc_flags = [ + "--cap-lints=allow", + "@$(location :quote-1.0.21-build-script-build-args)", + ], + visibility = [], + deps = [":proc-macro2-1.0.47"], +) + +rust_binary( + name = "quote-1.0.21-build-script-build", + srcs = ["vendor/quote-1.0.21/build.rs"], + crate = "build_script_build", + crate_root = "vendor/quote-1.0.21/build.rs", edition = "2018", - env = {"OUT_DIR": ""}, + features = [ + "default", + "proc-macro", + ], + rustc_flags = ["--cap-lints=allow"], + visibility = [], +) + +buildscript_args( + name = "quote-1.0.21-build-script-build-args", + package_name = "quote", + buildscript_rule = ":quote-1.0.21-build-script-build", + cfgs = [], + features = [ + "default", + "proc-macro", + ], + outfile = "args.txt", + version = "1.0.21", +) + +alias( + name = "scratch", + actual = ":scratch-1.0.2", visibility = ["PUBLIC"], ) rust_library( + name = "scratch-1.0.2", + srcs = ["vendor/scratch-1.0.2/src/lib.rs"], + crate = "scratch", + crate_root = "vendor/scratch-1.0.2/src/lib.rs", + edition = "2015", + env = { + "OUT_DIR": "generated", + }, + rustc_flags = ["--cap-lints=allow"], + visibility = [], +) + +alias( name = "syn", - srcs = glob(["vendor/syn-1.0.101/src/**/*.rs"]), - build_script = "vendor/syn-1.0.101/build.rs", + actual = ":syn-1.0.105", + visibility = ["PUBLIC"], +) + +rust_library( + name = "syn-1.0.105", + srcs = [ + "vendor/syn-1.0.105/src/attr.rs", + "vendor/syn-1.0.105/src/await.rs", + "vendor/syn-1.0.105/src/bigint.rs", + "vendor/syn-1.0.105/src/buffer.rs", + "vendor/syn-1.0.105/src/custom_keyword.rs", + "vendor/syn-1.0.105/src/custom_punctuation.rs", + "vendor/syn-1.0.105/src/data.rs", + "vendor/syn-1.0.105/src/derive.rs", + "vendor/syn-1.0.105/src/discouraged.rs", + "vendor/syn-1.0.105/src/drops.rs", + "vendor/syn-1.0.105/src/error.rs", + "vendor/syn-1.0.105/src/export.rs", + "vendor/syn-1.0.105/src/expr.rs", + "vendor/syn-1.0.105/src/ext.rs", + "vendor/syn-1.0.105/src/file.rs", + "vendor/syn-1.0.105/src/gen/clone.rs", + "vendor/syn-1.0.105/src/gen/debug.rs", + "vendor/syn-1.0.105/src/gen/eq.rs", + "vendor/syn-1.0.105/src/gen/fold.rs", + "vendor/syn-1.0.105/src/gen/hash.rs", + "vendor/syn-1.0.105/src/gen/visit.rs", + "vendor/syn-1.0.105/src/gen/visit_mut.rs", + "vendor/syn-1.0.105/src/gen_helper.rs", + "vendor/syn-1.0.105/src/generics.rs", + "vendor/syn-1.0.105/src/group.rs", + "vendor/syn-1.0.105/src/ident.rs", + "vendor/syn-1.0.105/src/item.rs", + "vendor/syn-1.0.105/src/lib.rs", + "vendor/syn-1.0.105/src/lifetime.rs", + "vendor/syn-1.0.105/src/lit.rs", + "vendor/syn-1.0.105/src/lookahead.rs", + "vendor/syn-1.0.105/src/mac.rs", + "vendor/syn-1.0.105/src/macros.rs", + "vendor/syn-1.0.105/src/op.rs", + "vendor/syn-1.0.105/src/parse.rs", + "vendor/syn-1.0.105/src/parse_macro_input.rs", + "vendor/syn-1.0.105/src/parse_quote.rs", + "vendor/syn-1.0.105/src/pat.rs", + "vendor/syn-1.0.105/src/path.rs", + "vendor/syn-1.0.105/src/print.rs", + "vendor/syn-1.0.105/src/punctuated.rs", + "vendor/syn-1.0.105/src/reserved.rs", + "vendor/syn-1.0.105/src/sealed.rs", + "vendor/syn-1.0.105/src/span.rs", + "vendor/syn-1.0.105/src/spanned.rs", + "vendor/syn-1.0.105/src/stmt.rs", + "vendor/syn-1.0.105/src/thread.rs", + "vendor/syn-1.0.105/src/token.rs", + "vendor/syn-1.0.105/src/tt.rs", + "vendor/syn-1.0.105/src/ty.rs", + "vendor/syn-1.0.105/src/verbatim.rs", + "vendor/syn-1.0.105/src/whitespace.rs", + ], + crate = "syn", + crate_root = "vendor/syn-1.0.105/src/lib.rs", edition = "2018", features = [ "clone-impls", + "default", "derive", "full", "parsing", "printing", "proc-macro", + "quote", ], - visibility = ["PUBLIC"], + rustc_flags = [ + "--cap-lints=allow", + "@$(location :syn-1.0.105-build-script-build-args)", + ], + visibility = [], deps = [ - ":proc-macro2", - ":quote", - ":unicode-ident", + ":proc-macro2-1.0.47", + ":quote-1.0.21", + ":unicode-ident-1.0.5", ], ) -rust_library( - name = "termcolor", - srcs = glob(["vendor/termcolor-1.1.3/src/**/*.rs"]), +rust_binary( + name = "syn-1.0.105-build-script-build", + srcs = ["vendor/syn-1.0.105/build.rs"], + crate = "build_script_build", + crate_root = "vendor/syn-1.0.105/build.rs", edition = "2018", + features = [ + "clone-impls", + "default", + "derive", + "full", + "parsing", + "printing", + "proc-macro", + "quote", + ], + rustc_flags = ["--cap-lints=allow"], + visibility = [], +) + +buildscript_args( + name = "syn-1.0.105-build-script-build-args", + package_name = "syn", + buildscript_rule = ":syn-1.0.105-build-script-build", + cfgs = [], + features = [ + "clone-impls", + "default", + "derive", + "full", + "parsing", + "printing", + "proc-macro", + "quote", + ], + outfile = "args.txt", + version = "1.0.105", ) rust_library( - name = "textwrap", - srcs = glob(["vendor/textwrap-0.15.1/src/**/*.rs"]), + name = "termcolor-1.1.3", + srcs = ["vendor/termcolor-1.1.3/src/lib.rs"], + crate = "termcolor", + crate_root = "vendor/termcolor-1.1.3/src/lib.rs", edition = "2018", - deps = [":unicode-width"], + rustc_flags = ["--cap-lints=allow"], + visibility = [], ) rust_library( - name = "unicode-ident", - srcs = glob(["vendor/unicode-ident-1.0.4/src/**/*.rs"]), + name = "unicode-ident-1.0.5", + srcs = [ + "vendor/unicode-ident-1.0.5/src/lib.rs", + "vendor/unicode-ident-1.0.5/src/tables.rs", + ], + crate = "unicode_ident", + crate_root = "vendor/unicode-ident-1.0.5/src/lib.rs", edition = "2018", + rustc_flags = ["--cap-lints=allow"], + visibility = [], ) rust_library( - name = "unicode-width", - srcs = glob(["vendor/unicode-width-0.1.10/src/**/*.rs"]), - edition = "2018", + name = "unicode-width-0.1.10", + srcs = [ + "vendor/unicode-width-0.1.10/src/lib.rs", + "vendor/unicode-width-0.1.10/src/tables.rs", + "vendor/unicode-width-0.1.10/src/tests.rs", + ], + crate = "unicode_width", + crate_root = "vendor/unicode-width-0.1.10/src/lib.rs", + edition = "2015", + features = ["default"], + rustc_flags = ["--cap-lints=allow"], + visibility = [], ) diff --git a/third-party/BUILD b/third-party/BUILD index 9e3a7959..1b599321 100644 --- a/third-party/BUILD +++ b/third-party/BUILD @@ -13,29 +13,32 @@ rust_library( rust_library( name = "cc", - srcs = glob(["vendor/cc-1.0.73/src/**/*.rs"]), + srcs = glob(["vendor/cc-1.0.77/src/**/*.rs"]), edition = "2018", visibility = ["//visibility:public"], ) rust_library( name = "clap", - srcs = glob(["vendor/clap-3.2.22/src/**/*.rs"]) + ["vendor/clap-3.2.22/examples/demo.rs"], - crate_features = ["std"], - data = ["vendor/clap-3.2.22/examples/demo.md"], + srcs = glob(["vendor/clap-4.0.29/src/**/*.rs"]) + ["vendor/clap-4.0.29/examples/demo.rs"], + crate_features = [ + "error-context", + "help", + "std", + "usage", + ], + data = ["vendor/clap-4.0.29/examples/demo.md"], edition = "2021", visibility = ["//visibility:public"], deps = [ ":bitflags", ":clap_lex", - ":indexmap", - ":textwrap", ], ) rust_library( name = "clap_lex", - srcs = glob(["vendor/clap_lex-0.2.4/src/**/*.rs"]), + srcs = glob(["vendor/clap_lex-0.3.0/src/**/*.rs"]), edition = "2021", deps = [ ":os_str_bytes", @@ -54,35 +57,21 @@ rust_library( ) rust_library( - name = "hashbrown", - srcs = glob(["vendor/hashbrown-0.12.3/src/**/*.rs"]), - crate_features = ["raw"], - edition = "2021", -) - -rust_library( - name = "indexmap", - srcs = glob(["vendor/indexmap-1.9.1/src/**/*.rs"]), - crate_features = ["std"], - edition = "2021", - rustc_flags = ["--cfg=has_std"], - deps = [":hashbrown"], -) - -rust_library( name = "once_cell", - srcs = glob(["vendor/once_cell-1.15.0/src/**/*.rs"]), + srcs = glob(["vendor/once_cell-1.16.0/src/**/*.rs"]), crate_features = [ "alloc", + "default", + "race", "std", ], - edition = "2018", + edition = "2021", visibility = ["//visibility:public"], ) rust_library( name = "os_str_bytes", - srcs = glob(["vendor/os_str_bytes-6.3.0/src/**/*.rs"]), + srcs = glob(["vendor/os_str_bytes-6.4.1/src/**/*.rs"]), crate_features = [ "raw_os_str", ], @@ -91,8 +80,9 @@ rust_library( rust_library( name = "proc-macro2", - srcs = glob(["vendor/proc-macro2-1.0.44/src/**/*.rs"]), + srcs = glob(["vendor/proc-macro2-1.0.47/src/**/*.rs"]), crate_features = [ + "default", "proc-macro", "span-locations", ], @@ -106,8 +96,9 @@ rust_library( cargo_build_script( name = "proc-macro2@build", - srcs = ["vendor/proc-macro2-1.0.44/build.rs"], + srcs = ["vendor/proc-macro2-1.0.47/build.rs"], crate_features = [ + "default", "proc-macro", "span-locations", ], @@ -118,7 +109,10 @@ cargo_build_script( rust_library( name = "quote", srcs = glob(["vendor/quote-1.0.21/src/**/*.rs"]), - crate_features = ["proc-macro"], + crate_features = [ + "default", + "proc-macro", + ], edition = "2018", visibility = ["//visibility:public"], deps = [ @@ -130,7 +124,10 @@ rust_library( cargo_build_script( name = "quote@build", srcs = ["vendor/quote-1.0.21/build.rs"], - crate_features = ["proc-macro"], + crate_features = [ + "default", + "proc-macro", + ], crate_name = "build", edition = "2018", ) @@ -138,21 +135,23 @@ cargo_build_script( rust_library( name = "scratch", srcs = glob(["vendor/scratch-1.0.2/src/**/*.rs"]), - edition = "2018", + edition = "2015", rustc_env = {"OUT_DIR": ""}, visibility = ["//visibility:public"], ) rust_library( name = "syn", - srcs = glob(["vendor/syn-1.0.101/src/**/*.rs"]), + srcs = glob(["vendor/syn-1.0.105/src/**/*.rs"]), crate_features = [ "clone-impls", + "default", "derive", "full", "parsing", "printing", "proc-macro", + "quote", ], edition = "2018", visibility = ["//visibility:public"], @@ -166,14 +165,16 @@ rust_library( cargo_build_script( name = "syn@build", - srcs = ["vendor/syn-1.0.101/build.rs"], + srcs = ["vendor/syn-1.0.105/build.rs"], crate_features = [ "clone-impls", + "default", "derive", "full", "parsing", "printing", "proc-macro", + "quote", ], crate_name = "build", edition = "2018", @@ -186,20 +187,16 @@ rust_library( ) rust_library( - name = "textwrap", - srcs = glob(["vendor/textwrap-0.15.1/src/**/*.rs"]), - edition = "2018", - deps = [":unicode-width"], -) - -rust_library( name = "unicode-ident", - srcs = glob(["vendor/unicode-ident-1.0.4/src/**/*.rs"]), + srcs = glob(["vendor/unicode-ident-1.0.5/src/**/*.rs"]), edition = "2018", ) rust_library( name = "unicode-width", srcs = glob(["vendor/unicode-width-0.1.10/src/**/*.rs"]), - edition = "2018", + crate_features = [ + "default", + ], + edition = "2015", ) diff --git a/third-party/Cargo.lock b/third-party/Cargo.lock index e5b81189..1c054218 100644 --- a/third-party/Cargo.lock +++ b/third-party/Cargo.lock @@ -3,18 +3,6 @@ version = 3 [[package]] -name = "adler" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" - -[[package]] -name = "autocfg" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" - -[[package]] name = "bitflags" version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -22,46 +10,25 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "cc" -version = "1.0.73" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11" -dependencies = [ - "jobserver", -] - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] -name = "clang-ast" -version = "0.1.9" +version = "1.0.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2ec567dd2f3a079936500b168b605e9d840ebc7b919a5b3b3e14f09ad79d07a" -dependencies = [ - "serde", -] +checksum = "e9f73505338f7d905b19d18738976aae232eb46b8efc15554ffc56deb5d9ebe4" [[package]] name = "clap" -version = "3.2.22" +version = "4.0.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86447ad904c7fb335a790c9d7fe3d0d971dc523b8ccd1561a520de9a85302750" +checksum = "4d63b9e9c07271b9957ad22c173bae2a4d9a81127680962039296abcd2f8251d" dependencies = [ "bitflags", "clap_lex", - "indexmap", - "strsim", - "textwrap", ] [[package]] name = "clap_lex" -version = "0.2.4" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5" +checksum = "0d4198f73e42b4936b35b5bb248d81d2b595ecb170da0bac7655c54eedfa8da8" dependencies = [ "os_str_bytes", ] @@ -77,211 +44,22 @@ dependencies = [ ] [[package]] -name = "crc32fast" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "cxx" -version = "1.0.77" -dependencies = [ - "cc", - "cxx-build", - "cxx-gen", - "cxx-test-suite", - "cxxbridge-flags", - "cxxbridge-macro", - "link-cplusplus", - "rustversion", - "trybuild", -] - -[[package]] -name = "cxx-build" -version = "1.0.77" -dependencies = [ - "cc", - "codespan-reporting", - "cxx-gen", - "once_cell", - "pkg-config", - "proc-macro2", - "quote", - "scratch", - "syn", -] - -[[package]] -name = "cxx-gen" -version = "0.7.77" -dependencies = [ - "codespan-reporting", - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "cxx-test-suite" -version = "0.0.0" -dependencies = [ - "cxx", - "cxx-build", - "cxxbridge-flags", -] - -[[package]] -name = "cxxbridge-cmd" -version = "1.0.77" -dependencies = [ - "clap", - "codespan-reporting", - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "cxxbridge-flags" -version = "1.0.77" - -[[package]] -name = "cxxbridge-macro" -version = "1.0.77" -dependencies = [ - "clang-ast", - "cxx", - "flate2", - "memmap", - "proc-macro2", - "quote", - "serde", - "serde_json", - "syn", -] - -[[package]] -name = "demo" -version = "0.0.0" -dependencies = [ - "cxx", - "cxx-build", -] - -[[package]] -name = "dissimilar" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c97b9233581d84b8e1e689cdd3a47b6f69770084fc246e86a7f78b0d9c1d4a5" - -[[package]] -name = "flate2" -version = "1.0.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f82b0f4c27ad9f8bfd1f3208d882da2b09c301bc1c828fd3a00d0216d2fbbff6" -dependencies = [ - "crc32fast", - "miniz_oxide", -] - -[[package]] -name = "glob" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" - -[[package]] -name = "hashbrown" -version = "0.12.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" - -[[package]] -name = "indexmap" -version = "1.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10a35a97730320ffe8e2d410b5d3b69279b98d2c14bdb8b70ea89ecf7888d41e" -dependencies = [ - "autocfg", - "hashbrown", -] - -[[package]] -name = "itoa" -version = "1.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8af84674fe1f223a982c933a0ee1086ac4d4052aa0fb8060c12c6ad838e754" - -[[package]] -name = "jobserver" -version = "0.1.25" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "068b1ee6743e4d11fb9c6a1e6064b3693a1b600e7f5f5988047d98b3dc9fb90b" -dependencies = [ - "libc", -] - -[[package]] -name = "libc" -version = "0.2.133" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0f80d65747a3e43d1596c7c5492d95d5edddaabd45a7fcdb02b95f644164966" - -[[package]] -name = "link-cplusplus" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9272ab7b96c9046fbc5bc56c06c117cb639fe2d509df0c421cad82d2915cf369" -dependencies = [ - "cc", -] - -[[package]] -name = "memmap" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6585fd95e7bb50d6cc31e20d4cf9afb4e2ba16c5846fc76793f11218da9c475b" -dependencies = [ - "libc", - "winapi", -] - -[[package]] -name = "miniz_oxide" -version = "0.5.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96590ba8f175222643a85693f33d26e9c8a015f599c216509b1a6894af675d34" -dependencies = [ - "adler", -] - -[[package]] name = "once_cell" -version = "1.15.0" +version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e82dad04139b71a90c080c8463fe0dc7902db5192d939bd0950f074d014339e1" +checksum = "86f0b0d4bf799edbc74508c1e8bf170ff5f41238e5f8225603ca7caaae2b7860" [[package]] name = "os_str_bytes" -version = "6.3.0" +version = "6.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ff7415e9ae3fff1225851df9e0d9e4e5479f947619774677a63572e55e80eff" - -[[package]] -name = "pkg-config" -version = "0.3.25" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1df8c4ec4b0627e53bdf214615ad287367e482558cf84b109250b37464dc03ae" +checksum = "9b7820b9daea5457c9f21c69448905d723fbd21136ccf521748f23fd49e723ee" [[package]] name = "proc-macro2" -version = "1.0.44" +version = "1.0.47" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7bd7356a8122b6c4a24a82b278680c73357984ca2fc79a0f9fa6dea7dced7c58" +checksum = "5ea3d908b0e36316caf9e9e2c4625cdde190a7e6f440d794667ed17a1855e725" dependencies = [ "unicode-ident", ] @@ -296,65 +74,16 @@ dependencies = [ ] [[package]] -name = "rustversion" -version = "1.0.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97477e48b4cf8603ad5f7aaf897467cf42ab4218a38ef76fb14c2d6773a6d6a8" - -[[package]] -name = "ryu" -version = "1.0.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09" - -[[package]] name = "scratch" version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8132065adcfd6e02db789d9285a0deb2f3fcb04002865ab67d5fb103533898" [[package]] -name = "serde" -version = "1.0.145" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "728eb6351430bccb993660dfffc5a72f91ccc1295abaa8ce19b27ebe4f75568b" -dependencies = [ - "serde_derive", -] - -[[package]] -name = "serde_derive" -version = "1.0.145" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81fa1584d3d1bcacd84c277a0dfe21f5b0f6accf4a23d04d4c6d61f1af522b4c" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "serde_json" -version = "1.0.85" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e55a28e3aaef9d5ce0506d0a14dbba8054ddc7e499ef522dd8b26859ec9d4a44" -dependencies = [ - "itoa", - "ryu", - "serde", -] - -[[package]] -name = "strsim" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" - -[[package]] name = "syn" -version = "1.0.101" +version = "1.0.105" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e90cde112c4b9690b8cbe810cba9ddd8bc1d7472e2cae317b69e9438c1cba7d2" +checksum = "60b9b43d45702de4c839cb9b51d9f529c5dd26a4aff255b42b1ebc03e88ee908" dependencies = [ "proc-macro2", "quote", @@ -371,41 +100,24 @@ dependencies = [ ] [[package]] -name = "textwrap" -version = "0.15.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "949517c0cf1bf4ee812e2e07e08ab448e3ae0d23472aee8a06c985f0c8815b16" - -[[package]] -name = "toml" -version = "0.5.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d82e1a7758622a465f8cee077614c73484dac5b836c02ff6a40d5d1010324d7" -dependencies = [ - "serde", -] - -[[package]] -name = "trybuild" -version = "1.0.65" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e13556ba7dba80b3c76d1331989a341290c77efcf688eca6c307ee3066383dd" +name = "third-party" +version = "0.0.0" dependencies = [ - "dissimilar", - "glob", + "cc", + "clap", + "codespan-reporting", "once_cell", - "serde", - "serde_derive", - "serde_json", - "termcolor", - "toml", + "proc-macro2", + "quote", + "scratch", + "syn", ] [[package]] name = "unicode-ident" -version = "1.0.4" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dcc811dc4066ac62f84f11307873c4850cb653bfa9b1719cee2bd2204a4bc5dd" +checksum = "6ceab39d59e4c9499d4e5a8ee0e2735b891bb7308ac83dfb4e80cad195c9f6f3" [[package]] name = "unicode-width" diff --git a/third-party/Cargo.toml b/third-party/Cargo.toml new file mode 100644 index 00000000..84657de5 --- /dev/null +++ b/third-party/Cargo.toml @@ -0,0 +1,18 @@ +[workspace] +[package] +name = "third-party" +version = "0.0.0" +publish = false + +[lib] +path = "/dev/null" + +[dependencies] +cc = "1.0.49" +clap = { version = "4", default-features = false, features = ["error-context", "help", "std", "usage"] } +codespan-reporting = "0.11.1" +once_cell = "1.9" +proc-macro2 = { version = "1.0.39", features = ["span-locations"] } +quote = "1.0.4" +scratch = "1" +syn = { version = "1.0.95", features = ["full"] } diff --git a/third-party/fixups/cc/fixups.toml b/third-party/fixups/cc/fixups.toml new file mode 100644 index 00000000..e148831c --- /dev/null +++ b/third-party/fixups/cc/fixups.toml @@ -0,0 +1 @@ +omit_targets = ["gcc-shim"] diff --git a/third-party/fixups/clap/fixups.toml b/third-party/fixups/clap/fixups.toml new file mode 100644 index 00000000..36ad30f5 --- /dev/null +++ b/third-party/fixups/clap/fixups.toml @@ -0,0 +1,2 @@ +extra_srcs = ["examples/demo.md", "examples/demo.rs"] +omit_targets = ["stdio-fixture"] diff --git a/third-party/fixups/proc-macro2/fixups.toml b/third-party/fixups/proc-macro2/fixups.toml new file mode 100644 index 00000000..5e026f75 --- /dev/null +++ b/third-party/fixups/proc-macro2/fixups.toml @@ -0,0 +1,2 @@ +[[buildscript]] +[buildscript.rustc_flags] diff --git a/third-party/fixups/quote/fixups.toml b/third-party/fixups/quote/fixups.toml new file mode 100644 index 00000000..5e026f75 --- /dev/null +++ b/third-party/fixups/quote/fixups.toml @@ -0,0 +1,2 @@ +[[buildscript]] +[buildscript.rustc_flags] diff --git a/third-party/fixups/scratch/fixups.toml b/third-party/fixups/scratch/fixups.toml new file mode 100644 index 00000000..72f4bdd0 --- /dev/null +++ b/third-party/fixups/scratch/fixups.toml @@ -0,0 +1,4 @@ +buildscript = [] + +[env] +OUT_DIR = "generated" diff --git a/third-party/fixups/syn/fixups.toml b/third-party/fixups/syn/fixups.toml new file mode 100644 index 00000000..5e026f75 --- /dev/null +++ b/third-party/fixups/syn/fixups.toml @@ -0,0 +1,2 @@ +[[buildscript]] +[buildscript.rustc_flags] diff --git a/third-party/reindeer.toml b/third-party/reindeer.toml new file mode 100644 index 00000000..eb65857c --- /dev/null +++ b/third-party/reindeer.toml @@ -0,0 +1,13 @@ +precise_srcs = true +rustc_flags = ["--cap-lints=allow"] + +[cargo] +versioned_dirs = true + +[buck] +generated_file_header = """ +# \u0040generated by `reindeer buckify` +""" +buckfile_imports = """ +load("//tools/buck:buildscript.bzl", "buildscript_args") +""" diff --git a/tools/bazel/vendor.bzl b/tools/bazel/vendor.bzl index b4dd253e..0f199145 100644 --- a/tools/bazel/vendor.bzl +++ b/tools/bazel/vendor.bzl @@ -12,12 +12,6 @@ def _impl(repository_ctx): workspace = lockfile.dirname.dirname repository_ctx.symlink(workspace, "workspace") - # Copy third-party/Cargo.lock since those are the crate versions that the - # BUILD file is written against. - vendor_lockfile = repository_ctx.path("workspace/third-party/Cargo.lock") - root_lockfile = repository_ctx.path("workspace/Cargo.lock") - _copy_file(repository_ctx, src = vendor_lockfile, dst = root_lockfile) - # Figure out which version of cargo to use. if repository_ctx.attr.target_triple: target_triple = repository_ctx.attr.target_triple @@ -34,20 +28,16 @@ def _impl(repository_ctx): target_triple = target_triple, ) - cmd = ["{}/bin/cargo".format(repository_ctx.path(".")), "vendor", "--versioned-dirs", "third-party/vendor"] + cmd = ["{}/bin/cargo".format(repository_ctx.path(".")), "vendor", "--versioned-dirs"] result = repository_ctx.execute( cmd, quiet = True, - working_directory = "workspace", + working_directory = "workspace/third-party", ) _log_cargo_vendor(repository_ctx, result) if result.return_code != 0: fail("failed to execute `{}`".format(" ".join(cmd))) - # Copy lockfile back to third-party/Cargo.lock to reflect any modification - # performed by Cargo. - _copy_file(repository_ctx, src = root_lockfile, dst = vendor_lockfile) - # Produce a token for third_party_glob to depend on so that the necessary # sequencing is visible to Bazel. repository_ctx.file("BUILD", executable = False) diff --git a/tools/buck/buildscript.bzl b/tools/buck/buildscript.bzl new file mode 100644 index 00000000..bbcf1060 --- /dev/null +++ b/tools/buck/buildscript.bzl @@ -0,0 +1,13 @@ +def buildscript_args( + name, + package_name, + buildscript_rule, + cfgs, + features, + outfile, + version): + native.genrule( + name = name, + out = outfile, + cmd = "env RUSTC=rustc TARGET= $(exe %s) | sed -n s/^cargo:rustc-cfg=/--cfg=/p > ${OUT}" % buildscript_rule, + ) diff --git a/tools/buck/genrule.bzl b/tools/buck/genrule.bzl deleted file mode 100644 index b5364b7f..00000000 --- a/tools/buck/genrule.bzl +++ /dev/null @@ -1,8 +0,0 @@ -def genrule(cmd, **kwargs): - # Resolve a distracting inconsistency between Buck and Bazel. - # Bazel creates the directory for your output file, while Buck expects the - # cmd to create it. - # - # TODO: send this as a PR to Buck, because Bazel's behavior here is better. - cmd = "mkdir -p `dirname ${OUT}`; " + cmd - native.genrule(cmd = cmd, **kwargs) diff --git a/tools/buck/prelude b/tools/buck/prelude new file mode 160000 +Subproject bed5249482b20f591d9d231663b23f318b6c10b diff --git a/tools/buck/rust_cxx_bridge.bzl b/tools/buck/rust_cxx_bridge.bzl index 4acc7c66..49e38fce 100644 --- a/tools/buck/rust_cxx_bridge.bzl +++ b/tools/buck/rust_cxx_bridge.bzl @@ -1,19 +1,17 @@ -load("//tools/buck:genrule.bzl", "genrule") - def rust_cxx_bridge(name, src, deps = []): - genrule( + native.genrule( name = "%s/header" % name, out = src + ".h", cmd = "cp $(location :%s/generated)/generated.h ${OUT}" % name, ) - genrule( + native.genrule( name = "%s/source" % name, out = src + ".cc", cmd = "cp $(location :%s/generated)/generated.cc ${OUT}" % name, ) - genrule( + native.genrule( name = "%s/generated" % name, srcs = [src], out = ".", @@ -21,14 +19,14 @@ def rust_cxx_bridge(name, src, deps = []): type = "cxxbridge", ) - cxx_library( + native.cxx_library( name = name, srcs = [":%s/source" % name], preferred_linkage = "static", - deps = deps + [":%s/include" % name], + exported_deps = deps + [":%s/include" % name], ) - cxx_library( + native.cxx_library( name = "%s/include" % name, exported_headers = [":%s/header" % name], ) diff --git a/tools/buck/rust_library.bzl b/tools/buck/rust_library.bzl deleted file mode 100644 index 4c85614d..00000000 --- a/tools/buck/rust_library.bzl +++ /dev/null @@ -1,37 +0,0 @@ -load("//tools/buck:genrule.bzl", "genrule") - -def rust_library( - name, - srcs, - edition, - features = [], - rustc_flags = [], - build_script = None, - **kwargs): - if build_script: - rust_binary( - name = "%s@build" % name, - srcs = srcs + [build_script], - crate = "build", - crate_root = build_script, - edition = edition, - features = features, - rustc_flags = rustc_flags, - ) - - genrule( - name = "%s@cfg" % name, - out = "output", - cmd = "env RUSTC=rustc TARGET= $(exe :%s@build) | sed -n s/^cargo:rustc-cfg=/--cfg=/p > ${OUT}" % name, - ) - - rustc_flags = rustc_flags + ["@$(location :%s@cfg)" % name] - - native.rust_library( - name = name, - srcs = srcs, - edition = edition, - features = features, - rustc_flags = rustc_flags, - **kwargs - ) diff --git a/tools/buck/toolchains/BUCK b/tools/buck/toolchains/BUCK new file mode 100644 index 00000000..87ee8933 --- /dev/null +++ b/tools/buck/toolchains/BUCK @@ -0,0 +1,21 @@ +load("@prelude//toolchains:cxx.bzl", "system_cxx_toolchain") +load("@prelude//toolchains:python.bzl", "system_python_bootstrap_toolchain") +load("@prelude//toolchains:rust.bzl", "system_rust_toolchain") + +system_cxx_toolchain( + name = "cxx", + visibility = ["PUBLIC"], +) + +system_python_bootstrap_toolchain( + name = "python_bootstrap", + visibility = ["PUBLIC"], +) + +system_rust_toolchain( + name = "rust", + default_edition = None, + rustc_flags = ["-Clink-arg=-fuse-ld=lld"], + rustdoc_flags = ["-Zunstable-options"], # doc builds use unstable '--extern-html-root-url' + visibility = ["PUBLIC"], +) |