Skip to content

Commit

Permalink
Adding diagnostics for use on non-nightly.
Browse files Browse the repository at this point in the history
  • Loading branch information
adetaylor committed Oct 18, 2022
1 parent 075bd8e commit cb9c680
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 2 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ regex = "1.5"
indexmap = "1.8"
prettyplease = { version = "0.1.15", features = ["verbatim"] }

[build-dependencies]
rustc_version = "0.4"

[dependencies.syn]
version = "1.0.39"
features = [ "full", "printing" ]
Expand Down
15 changes: 15 additions & 0 deletions engine/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright 2022 Google LLC
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use rustc_version::{version_meta, Channel};

fn main() {
if version_meta().unwrap().channel == Channel::Nightly {
println!("cargo:rustc-cfg=nightly");
}
}
10 changes: 10 additions & 0 deletions engine/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ pub enum Error {
NoAutoCxxInc,
#[error(transparent)]
Conversion(conversion::ConvertError),
#[error("Using `unsafe_references_wrapped` requires the Rust nightly `arbitrary_self_types` feature")]
WrappedReferencesButNoArbitrarySelfTypes,
}

/// Result type.
Expand Down Expand Up @@ -398,6 +400,14 @@ impl IncludeCppEngine {
State::Generated(_) => panic!("Only call generate once"),
}

if matches!(
self.config.unsafe_policy,
UnsafePolicy::ReferencesWrappedAllFunctionsSafe
) && cfg!(not(nightly))
{
return Err(Error::WrappedReferencesButNoArbitrarySelfTypes);
}

let mod_name = self.config.get_mod_name();
let mut builder = self.make_bindgen_builder(&inc_dirs, extra_clang_args);
if let Some(dep_recorder) = dep_recorder {
Expand Down
5 changes: 3 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,9 @@ macro_rules! concrete {
/// `safety!(unsafe_references_wrapped)`
/// This policy treats C++ references as scary and requires
/// them to be wrapped in a `CppRef` type: see [`CppRef`].
/// This only works practically on nightly Rust because it
/// depends upon an unstable feature. However, it should
/// This only works on nightly Rust because it
/// depends upon an unstable feature
/// (`arbitrary_self_types`). However, it should
/// eliminate all undefined behavior related to Rust's
/// stricter aliasing rules than C++.
#[macro_export]
Expand Down

0 comments on commit cb9c680

Please sign in to comment.