Skip to content

Commit

Permalink
Merge pull request #16 from JohnTitor/edition-2018
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnTitor authored Oct 30, 2020
2 parents f1cbf78 + 4aafd94 commit 82ef3da
Show file tree
Hide file tree
Showing 12 changed files with 27 additions and 44 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ description = """
Automated tests of FFI bindings.
"""
include = ["src/lib.rs", "LICENSE-*", "README.md"]
edition = "2018"

[dependencies]
garando_syntax = "0.1"
Expand Down
6 changes: 0 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ ctest2 = "0.2"
Next, add a build script to `systest/build.rs`:

```rust
extern crate ctest2;

fn main() {
let mut cfg = ctest2::TestGenerator::new();

Expand All @@ -57,17 +55,13 @@ fn main() {
// the module to generate.
cfg.generate("../mylib-sys/lib.rs", "all.rs");
}

```

Next, add this to `src/main.rs`

```rust
#![allow(bad_style)]

extern crate mylib_sys;
extern crate libc;

use libc::*;
use mylib_sys::*;

Expand Down
45 changes: 21 additions & 24 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,8 @@
//! [project]: https://github.com/JohnTitor/ctest2

#![deny(missing_docs)]
#![allow(bare_trait_objects)]

extern crate cc;
extern crate garando_syntax as syntax;

extern crate rustc_version;
use garando_syntax as syntax;

use std::cell::RefCell;
use std::collections::{HashMap, HashSet};
Expand Down Expand Up @@ -65,6 +61,7 @@ pub enum Lang {

/// A kind of item to which the C volatile qualifier could apply.
#[derive(Debug)]
#[allow(clippy::manual_non_exhaustive)] // FIXME: Use `#[non_exhaustive]` in the future.
pub enum VolatileItemKind {
/// A struct field (struct_name, field_name)
StructField(String, String),
Expand Down Expand Up @@ -93,22 +90,22 @@ pub struct TestGenerator {
defines: Vec<(String, Option<String>)>,
cfg: Vec<(String, Option<String>)>,
verbose_skip: bool,
volatile_item: Box<Fn(VolatileItemKind) -> bool>,
array_arg: Box<Fn(&str, usize) -> bool>,
skip_fn: Box<Fn(&str) -> bool>,
skip_fn_ptrcheck: Box<Fn(&str) -> bool>,
skip_static: Box<Fn(&str) -> bool>,
skip_field: Box<Fn(&str, &str) -> bool>,
skip_field_type: Box<Fn(&str, &str) -> bool>,
skip_const: Box<Fn(&str) -> bool>,
skip_signededness: Box<Fn(&str) -> bool>,
skip_type: Box<Fn(&str) -> bool>,
skip_struct: Box<Fn(&str) -> bool>,
skip_roundtrip: Box<Fn(&str) -> bool>,
field_name: Box<Fn(&str, &str) -> String>,
type_name: Box<Fn(&str, bool, bool) -> String>,
fn_cname: Box<Fn(&str, Option<&str>) -> String>,
const_cname: Box<Fn(&str) -> String>,
volatile_item: Box<dyn Fn(VolatileItemKind) -> bool>,
array_arg: Box<dyn Fn(&str, usize) -> bool>,
skip_fn: Box<dyn Fn(&str) -> bool>,
skip_fn_ptrcheck: Box<dyn Fn(&str) -> bool>,
skip_static: Box<dyn Fn(&str) -> bool>,
skip_field: Box<dyn Fn(&str, &str) -> bool>,
skip_field_type: Box<dyn Fn(&str, &str) -> bool>,
skip_const: Box<dyn Fn(&str) -> bool>,
skip_signededness: Box<dyn Fn(&str) -> bool>,
skip_type: Box<dyn Fn(&str) -> bool>,
skip_struct: Box<dyn Fn(&str) -> bool>,
skip_roundtrip: Box<dyn Fn(&str) -> bool>,
field_name: Box<dyn Fn(&str, &str) -> String>,
type_name: Box<dyn Fn(&str, bool, bool) -> String>,
fn_cname: Box<dyn Fn(&str, Option<&str>) -> String>,
const_cname: Box<dyn Fn(&str) -> String>,
rust_version: rustc_version::Version,
}

Expand All @@ -120,8 +117,8 @@ struct TyFinder {

struct Generator<'a> {
target: &'a str,
rust: Box<Write>,
c: Box<Write>,
rust: Box<dyn Write>,
c: Box<dyn Write>,
sh: &'a SpanHandler,
structs: HashSet<String>,
unions: HashSet<String>,
Expand Down Expand Up @@ -1695,7 +1692,7 @@ impl<'a> Generator<'a> {
ty = rust_ty
));
} else if rust_ty.starts_with('[') && rust_ty.ends_with(']') {
let c_ptr_ty = c_ty.split(' ').nth(0).unwrap();
let c_ptr_ty = c_ty.split(' ').next().unwrap();
let mut lens = Vec::new();
for i in c_ty.split(' ').skip(1) {
lens.push(i);
Expand Down
1 change: 1 addition & 0 deletions testcrate/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name = "testcrate"
version = "0.1.0"
authors = ["Alex Crichton <alex@alexcrichton.com>"]
build = "build.rs"
edition = "2018"

[build-dependencies]
ctest2 = { path = ".." }
Expand Down
5 changes: 1 addition & 4 deletions testcrate/build.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
extern crate cc;
extern crate ctest2;

fn main() {
use std::env;
let opt_level = env::var("OPT_LEVEL")
.ok()
.and_then(|s| s.parse().ok())
.unwrap_or(0);
let profile = env::var("PROFILE").unwrap_or(String::new());
let profile = env::var("PROFILE").unwrap_or_default();
if profile == "release" || opt_level >= 2 {
println!("cargo:rustc-cfg=optimized");
}
Expand Down
2 changes: 0 additions & 2 deletions testcrate/src/bin/t1.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#![cfg(not(test))]
#![deny(warnings)]

extern crate libc;
extern crate testcrate;
use libc::*;
use testcrate::t1::*;

Expand Down
2 changes: 0 additions & 2 deletions testcrate/src/bin/t1_cxx.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#![cfg(not(test))]
#![deny(warnings)]

extern crate libc;
extern crate testcrate;
use libc::*;
use testcrate::t1::*;

Expand Down
1 change: 0 additions & 1 deletion testcrate/src/bin/t2.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#![cfg(not(test))]
#![deny(warnings)]

extern crate testcrate;
use testcrate::t2::*;

include!(concat!(env!("OUT_DIR"), "/t2gen.rs"));
1 change: 0 additions & 1 deletion testcrate/src/bin/t2_cxx.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#![cfg(not(test))]
#![deny(warnings)]

extern crate testcrate;
use testcrate::t2::*;

include!(concat!(env!("OUT_DIR"), "/t2gen_cxx.rs"));
2 changes: 0 additions & 2 deletions testcrate/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
extern crate libc;

pub mod t1;
pub mod t2;
3 changes: 2 additions & 1 deletion testcrate/src/t1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use libc::*;

pub type T1Foo = i32;
pub const T1S: &'static str = "foo";
pub const T1S: &str = "foo";

pub const T1N: i32 = 5;

Expand Down Expand Up @@ -69,6 +69,7 @@ extern "C" {
pub fn T1e(a: c_uint, b: *const T1Bar);

#[link_name = "T1f"]
#[allow(clippy::unused_unit)]
pub fn f() -> ();

pub fn T1g(a: *mut [i32; 4]);
Expand Down
2 changes: 1 addition & 1 deletion testcrate/src/t2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub union T2Union {
pub const T2C: i32 = 5;

i! {
pub const T2S: &'static str = "b";
pub const T2S: &str = "b";
}

extern "C" {
Expand Down

0 comments on commit 82ef3da

Please sign in to comment.