Skip to content

Commit

Permalink
Merge branch 'mozilla:master' into zig-bindgen
Browse files Browse the repository at this point in the history
  • Loading branch information
kassane committed Aug 26, 2023
2 parents 6981047 + 5f235ec commit edf9378
Show file tree
Hide file tree
Showing 18 changed files with 177 additions and 98 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/cbindgen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ jobs:

- name: Run rustfmt
run: |
cargo fmt --check
cargo +stable fmt --check
- name: Run clippy
run: |
cargo clippy --workspace -- -D warnings
cargo +stable clippy --workspace -- -D warnings
- name: Install minimum supported Rust version
id: msrv
uses: dtolnay/rust-toolchain@1.57
uses: dtolnay/rust-toolchain@1.64

- name: Build with minimum supported Rust version
run: |
Expand Down Expand Up @@ -64,18 +64,18 @@ jobs:

- name: Build
run: |
cargo build --verbose
cargo +stable build --verbose
- name: Build no-default-features
run: |
cargo build --verbose --no-default-features
cargo +stable build --verbose --no-default-features
- name: Test package
env:
CBINDGEN_TEST_VERIFY: 1
run: |
cargo package --verbose
(cd target/package/cbindgen-$(cargo run -- --version | cut -d ' ' -f 2) && cargo test --verbose)
cargo +stable package --verbose
(cd target/package/cbindgen-$(cargo +stable run -- --version | cut -d ' ' -f 2) && cargo +stable test --verbose)
- name: Install nightly Rust
uses: dtolnay/rust-toolchain@nightly
Expand Down
23 changes: 15 additions & 8 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,28 @@ on:
jobs:

linux-binaries:
permissions:
# Grant the GITHUB_TOKEN additional permissions necessary for creating a release.
# We only run this action for tags, so any code has already been reviewed by
# someone with permissions to create a tag.
contents: write

runs-on: ubuntu-latest
runs-on: ubuntu-20.04

steps:
- uses: actions/checkout@v3

- name: Install stable
uses: dtolnay/rust-toolchain@stable

- name: semver
run: |
cargo +stable install cargo-semver-checks --locked
cargo semver-checks check-release
- name: Build cbindgen
run: |
cargo build --release
cargo +stable build --release
- name: Strip cbindgen
run: |
Expand All @@ -39,11 +49,8 @@ jobs:
sed '$ d' | awk '{$1=$1};1' > CHANGES.txt
- name: Create a release
uses: softprops/action-gh-release@v1
with:
name: v${{ steps.tagName.outputs.version }}
body_path: CHANGES.txt
files: |
target/release/cbindgen
run: |
TAG=${{ steps.tagName.outputs.version }}
gh release create ${TAG} --title "${TAG}" --notes-file "CHANGES.txt" --draft 'target/release/cbindgen#cbindgen-ubuntu20.04'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
12 changes: 12 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
# Unreleased

* Fix swapping of `>>=` and `<<=` in constants.

## 0.25.0

* Re-release of yanked 0.24.6 as a major release
* Update MSRV to 1.57
* Support variadic arguments (`...`) (#805)
* Add --depfile option (#820)
* Breaking changes: The `Config` struct now has a private member.

## 0.24.6 (YANKED: depfile option was breaking, see #841)

* Update MSRV to 1.57
Expand Down
4 changes: 2 additions & 2 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ keywords = ["bindings", "ffi", "code-generation"]
categories = ["external-ffi-bindings", "development-tools::ffi"]
repository = "https://github.com/eqrion/cbindgen"
edition = "2018"
rust-version = "1.57"
rust-version = "1.64"
exclude = [
"tests/profile.rs", # Test relies in a sub-crate, see https://github.com/rust-lang/cargo/issues/9017
]
Expand All @@ -26,7 +26,7 @@ serde = { version = "1.0.103", default-features = false, features = ["derive"] }
serde_json = "1.0"
tempfile = "3"
toml = "0.5"
proc-macro2 = "1"
proc-macro2 = "1.0.60"
quote = "1"
heck = "0.4"

Expand Down
1 change: 1 addition & 0 deletions contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ There is continuous integration setup for `cbindgen` using [GitHub Actions](http

In addition to a C/C++ compiler `cargo test` requires Python and Cython
(`python -m pip install Cython`) for checking Cython bindings generated from tests (`.pyx` files).
Note that the tests will be failed with Cython 3.x or later.

Please run `cargo test` before filing a pull request to be sure that all tests pass. This will also update the test expectations.

Expand Down
2 changes: 2 additions & 0 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[toolchain]
channel = "nightly"
2 changes: 1 addition & 1 deletion src/bindgen/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ impl Bindings {
let mut canon_source_files: Vec<_> = self
.source_files
.iter()
.chain(self.config.config_path.as_ref().into_iter())
.chain(self.config.config_path.as_ref())
.map(|p| p.canonicalize().unwrap())
.collect();
// Sorting makes testing easier by ensuring the output is ordered.
Expand Down
4 changes: 2 additions & 2 deletions src/bindgen/ir/constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,8 @@ impl Literal {
syn::BinOp::BitXorEq(..) => "^=",
syn::BinOp::BitAndEq(..) => "&=",
syn::BinOp::BitOrEq(..) => "|=",
syn::BinOp::ShlEq(..) => ">>=",
syn::BinOp::ShrEq(..) => "<<=",
syn::BinOp::ShlEq(..) => "<<=",
syn::BinOp::ShrEq(..) => ">>=",
};
Ok(Literal::BinOp {
left: Box::new(l),
Expand Down
10 changes: 6 additions & 4 deletions src/bindgen/ir/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

use std::io::Write;

use syn::ext::IdentExt;

use crate::bindgen::cdecl;
use crate::bindgen::config::Config;
use crate::bindgen::declarationtyperesolver::DeclarationTypeResolver;
Expand All @@ -26,15 +24,19 @@ pub struct Static {
}

impl Static {
pub fn load(item: &syn::ItemStatic, mod_cfg: Option<&Cfg>) -> Result<Static, String> {
pub fn load(
path: Path,
item: &syn::ItemStatic,
mod_cfg: Option<&Cfg>,
) -> Result<Static, String> {
let ty = Type::load(&item.ty)?;

if ty.is_none() {
return Err("Cannot have a zero sized static definition.".to_owned());
}

Ok(Static::new(
Path::new(item.ident.unraw().to_string()),
path,
ty.unwrap(),
item.mutability.is_some(),
Cfg::append(mod_cfg, Cfg::load(&item.attrs)),
Expand Down
96 changes: 30 additions & 66 deletions src/bindgen/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use crate::bindgen::ir::{
AnnotationSet, Cfg, Constant, Documentation, Enum, Function, GenericParam, GenericParams,
ItemMap, OpaqueItem, Path, Static, Struct, Type, Typedef, Union,
};
use crate::bindgen::utilities::{SynAbiHelpers, SynAttributeHelpers, SynItemFnHelpers};
use crate::bindgen::utilities::{SynAbiHelpers, SynAttributeHelpers, SynItemHelpers};

const STD_CRATES: &[&str] = &[
"std",
Expand Down Expand Up @@ -643,7 +643,6 @@ impl Parse {
item,
Some(self_type),
&item.sig,
&item.vis,
&item.attrs,
)
}
Expand All @@ -665,7 +664,6 @@ impl Parse {
item,
None,
&item.sig,
&item.vis,
&item.attrs,
);
}
Expand All @@ -677,10 +675,9 @@ impl Parse {
binding_crate_name: &str,
crate_name: &str,
mod_cfg: Option<&Cfg>,
named_symbol: &dyn SynItemFnHelpers,
named_symbol: &dyn SynItemHelpers,
self_type: Option<&Path>,
sig: &syn::Signature,
vis: &syn::Visibility,
attrs: &[syn::Attribute],
) {
if !config
Expand All @@ -707,53 +704,29 @@ impl Parse {
let is_extern_c = sig.abi.is_omitted() || sig.abi.is_c();
let exported_name = named_symbol.exported_name();

if let syn::Visibility::Public(_) = vis {
match (is_extern_c, exported_name) {
(true, Some(exported_name)) => {
let path = Path::new(exported_name);
match Function::load(path, self_type, sig, false, attrs, mod_cfg) {
Ok(func) => {
info!("Take {}.", loggable_item_name());
self.functions.push(func);
}
Err(msg) => {
error!("Cannot use fn {} ({}).", loggable_item_name(), msg);
}
match (is_extern_c, exported_name) {
(true, Some(exported_name)) => {
let path = Path::new(exported_name);
match Function::load(path, self_type, sig, false, attrs, mod_cfg) {
Ok(func) => {
info!("Take {}.", loggable_item_name());
self.functions.push(func);
}
Err(msg) => {
error!("Cannot use fn {} ({}).", loggable_item_name(), msg);
}
}
(true, None) => {
warn!(
"Skipping {} - (not `no_mangle`, and has no `export_name` attribute)",
loggable_item_name()
);
}
(false, Some(_exported_name)) => {
warn!("Skipping {} - (not `extern \"C\"`", loggable_item_name());
}
(false, None) => {}
}
} else {
match (is_extern_c, exported_name) {
(true, Some(..)) => {
warn!(
"Skipping {} - (not `pub` but is `extern \"C\"` and `no_mangle`)",
loggable_item_name()
);
}
(true, None) => {
warn!(
"Skipping {} - (not `pub` but is `extern \"C\"`)",
loggable_item_name()
);
}
(false, Some(..)) => {
warn!(
"Skipping {} - (not `pub` but is `no_mangle`)",
loggable_item_name()
);
}
(false, None) => {}
(true, None) => {
warn!(
"Skipping {} - (not `no_mangle`, and has no `export_name` attribute)",
loggable_item_name()
);
}
(false, Some(_exported_name)) => {
warn!("Skipping {} - (not `extern \"C\"`", loggable_item_name());
}
(false, None) => {}
}
}

Expand Down Expand Up @@ -892,27 +865,18 @@ impl Parse {
return;
}

if let syn::Visibility::Public(_) = item.vis {
if item.is_no_mangle() {
match Static::load(item, mod_cfg) {
Ok(constant) => {
info!("Take {}::{}.", crate_name, &item.ident);

self.globals.try_insert(constant);
}
Err(msg) => {
warn!("Skip {}::{} - ({})", crate_name, &item.ident, msg);
}
if let Some(exported_name) = item.exported_name() {
let path = Path::new(exported_name);
match Static::load(path, item, mod_cfg) {
Ok(constant) => {
info!("Take {}::{}.", crate_name, &item.ident);
self.globals.try_insert(constant);
}
Err(msg) => {
warn!("Skip {}::{} - ({})", crate_name, &item.ident, msg);
}
}
}

// TODO
if let syn::Visibility::Public(_) = item.vis {
} else {
warn!("Skip {}::{} - (not `pub`).", crate_name, &item.ident);
}
if !item.is_no_mangle() {
warn!("Skip {}::{} - (not `no_mangle`).", crate_name, &item.ident);
}
}
Expand Down
20 changes: 17 additions & 3 deletions src/bindgen/utilities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ where
}
}

pub trait SynItemFnHelpers: SynAttributeHelpers {
pub trait SynItemHelpers: SynAttributeHelpers {
fn exported_name(&self) -> Option<String>;
}

impl SynItemFnHelpers for syn::ItemFn {
impl SynItemHelpers for syn::ItemFn {
fn exported_name(&self) -> Option<String> {
self.attrs
.attr_name_value_lookup("export_name")
Expand All @@ -48,7 +48,7 @@ impl SynItemFnHelpers for syn::ItemFn {
}
}

impl SynItemFnHelpers for syn::ImplItemMethod {
impl SynItemHelpers for syn::ImplItemMethod {
fn exported_name(&self) -> Option<String> {
self.attrs
.attr_name_value_lookup("export_name")
Expand All @@ -62,6 +62,20 @@ impl SynItemFnHelpers for syn::ImplItemMethod {
}
}

impl SynItemHelpers for syn::ItemStatic {
fn exported_name(&self) -> Option<String> {
self.attrs
.attr_name_value_lookup("export_name")
.or_else(|| {
if self.is_no_mangle() {
Some(self.ident.unraw().to_string())
} else {
None
}
})
}
}

/// Returns whether this attribute causes us to skip at item. This basically
/// checks for `#[cfg(test)]`, `#[test]`, `/// cbindgen::ignore` and
/// variations thereof.
Expand Down

0 comments on commit edf9378

Please sign in to comment.