Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update syn to 2.0 #231

Merged
merged 3 commits into from
Jun 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions Cargo.lock

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

6 changes: 3 additions & 3 deletions crates/rb-sys-build/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ description = "Build system for rb-sys"
homepage = "https://github.com/oxidize-rb/rb-sys"
license = "MIT OR Apache-2.0"
repository = "https://github.com/oxidize-rb/rb-sys"
rust-version = "1.57"
rust-version = "1.60"

[lib]
bench = false
Expand All @@ -15,9 +15,9 @@ doctest = false
[dependencies]
regex = "1"
shell-words = "1.1"
bindgen = { version = "0.62", default-features = false, features = ["runtime"] }
bindgen = { version = "0.66", default-features = false, features = ["runtime"] }
cc-impl = { version = "1.0", optional = true, package = "cc" }
syn = { version = "1.0", features = ["parsing", "full", "extra-traits"] }
syn = { version = "2.0", features = ["parsing", "full", "extra-traits"] }
quote = "1.0"
lazy_static = "1.4.0"
proc-macro2 = "1.0"
Expand Down
1 change: 0 additions & 1 deletion crates/rb-sys-build/src/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ fn clean_docs(rbconfig: &RbConfig, syntax: &mut syn::File) {

fn default_bindgen(clang_args: Vec<String>) -> bindgen::Builder {
let bindings = bindgen::Builder::default()
.rustfmt_bindings(false) // We use syn so this is pointless
.rustified_enum(".*")
.no_copy("rb_data_type_struct")
.derive_eq(true)
Expand Down
35 changes: 15 additions & 20 deletions crates/rb-sys-build/src/bindings/sanitizer.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use proc_macro2::{Literal, TokenTree};
use quote::ToTokens;
use regex::Regex;
use std::{borrow::Cow, error::Error};
use syn::{Attribute, Item};
use std::{
borrow::{Borrow, Cow},
error::Error,
};
use syn::{Attribute, Expr, Item, Lit, LitStr, Meta};

lazy_static::lazy_static! {
static ref URL_REGEX: Regex = Regex::new(r#"https?://[^\s'"]+"#).unwrap();
Expand Down Expand Up @@ -100,19 +101,16 @@ pub fn cleanup_docs(syntax: &mut syn::File, ruby_version: &str) -> Result<(), Bo
}

fn clean_doc_line(attr: &mut Attribute) -> bool {
if !attr.path.is_ident("doc") {
if !attr.path().is_ident("doc") {
return false;
}

let mut deprecated: bool = false;

let new_tokens = attr
.tokens
.to_token_stream()
.into_iter()
.map(|token| {
if let TokenTree::Literal(l) = token {
let cleaned = l.to_string();
if let Meta::NameValue(name_value) = &mut attr.meta {
if let Expr::Lit(expr_lit) = &mut name_value.value {
if let Lit::Str(lit_str) = &mut expr_lit.lit {
let cleaned = lit_str.value();
let cleaned = cleaned.trim_matches('"').trim();
let cleaned = URL_REGEX.replace_all(cleaned, "<${0}>");
let cleaned =
Expand All @@ -125,24 +123,21 @@ fn clean_doc_line(attr: &mut Attribute) -> bool {
});
let cleaned = PARAM_DIRECTIVE_REGEX.replace(&cleaned, "- **$1** `$2` $3");
let cleaned = OTHER_DIRECTIVE_REGEX.replace(&cleaned, "- **$1** $2");
let cleaned = BARE_CODE_REF_REGEX.replace_all(&cleaned, "${1}[`${2}`]");
let mut cleaned = BARE_CODE_REF_REGEX.replace_all(&cleaned, "${1}[`${2}`]");

if cleaned.is_empty() {
return TokenTree::Literal(Literal::string("\n"));
cleaned = "\n".into();
}

if cleaned.contains("@deprecated") {
deprecated = true;
}

Literal::string(&cleaned).into()
} else {
token
*lit_str = LitStr::new(cleaned.borrow(), lit_str.span());
}
})
.collect();
}
}

attr.tokens = new_tokens;
deprecated
}

Expand Down
2 changes: 1 addition & 1 deletion crates/rb-sys-env/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ homepage = "https://github.com/oxidize-rb/rb-sys"
license = "MIT OR Apache-2.0"
repository = "https://github.com/oxidize-rb/rb-sys"
readme = "readme.md"
rust-version = "1.57"
rust-version = "1.60"

[lib]
bench = false
Expand Down
4 changes: 2 additions & 2 deletions crates/rb-sys-test-helpers-macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ homepage = "https://github.com/oxidize-rb/rb-sys"
license = "MIT OR Apache-2.0"
repository = "https://github.com/oxidize-rb/rb-sys"
readme = "readme.md"
rust-version = "1.57"
rust-version = "1.60"

[lib]
proc-macro = true
bench = false
doctest = true

[dependencies]
syn = { version = "1.0", features = ["parsing", "full"] }
syn = { version = "2.0", features = ["parsing", "full"] }
quote = "1.0"

[dev-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/rb-sys-test-helpers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ homepage = "https://github.com/oxidize-rb/rb-sys"
license = "MIT OR Apache-2.0"
repository = "https://github.com/oxidize-rb/rb-sys"
readme = "readme.md"
rust-version = "1.57"
rust-version = "1.60"

[lib]
bench = false
Expand Down
2 changes: 1 addition & 1 deletion crates/rb-sys-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.9.79"
edition = "2018"
autotests = false
publish = false
rust-version = "1.57"
rust-version = "1.60"

[lib]
bench = false
Expand Down
2 changes: 1 addition & 1 deletion crates/rb-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ homepage = "https://github.com/oxidize-rb/rb-sys"
license = "MIT OR Apache-2.0"
links = "rb"
repository = "https://github.com/oxidize-rb/rb-sys"
rust-version = "1.57"
rust-version = "1.60"

[build-dependencies]
rb-sys-build = { version = "0.9.79", path = "../rb-sys-build" }
Expand Down
2 changes: 1 addition & 1 deletion data/toolchains.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"policy": {
"minimum-supported-ruby-version": "2.4",
"minimum-supported-rust-version": "1.57"
"minimum-supported-rust-version": "1.60"
},
"toolchains": [
{
Expand Down
8 changes: 4 additions & 4 deletions examples/rust_reverse/ext/rust_reverse/Cargo.lock

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

3 changes: 1 addition & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ building your own gem.

- Ruby: <!--toolchains .policy.minimum-supported-ruby-version -->2.4<!--/toolchains-->+ (for full compatibility with
Rubygems)
- Rust: <!--toolchains .policy.minimum-supported-rust-version -->1.57<!--/toolchains-->+ (for old versions of rust
toolchains ubuntu)
- Rust: <!--toolchains .policy.minimum-supported-rust-version -->1.60<!--/toolchains-->+

## Supported Platforms

Expand Down