Skip to content

Commit 6e7d40e

Browse files
committed
fix: Fix nightly and #define support.
1 parent 9a606b5 commit 6e7d40e

File tree

5 files changed

+17
-4
lines changed

5 files changed

+17
-4
lines changed

build.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
fn main() {
2+
println!("cargo:rustc-check-cfg=cfg(nightly)");
3+
24
if rustc_version::version_meta().unwrap().channel == rustc_version::Channel::Nightly {
35
println!("cargo:rustc-cfg=nightly");
46
}

macros/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# `inline-c-macro`
22

3-
please check the [`readme.md` of the `inline-c`
3+
Please check the [`readme.md` of the `inline-c`
44
crate](https://github.com/hywan/inline-c-rs) to learn more.

macros/build.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
fn main() {
2+
println!("cargo:rustc-check-cfg=cfg(nightly)");
3+
24
if rustc_version::version_meta().unwrap().channel == rustc_version::Channel::Nightly {
35
println!("cargo:rustc-cfg=nightly");
46
}

macros/src/lib.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//! Please see the `inline-c` crate to learn more.
22
3+
#![cfg_attr(nightly, feature(proc_macro_span))]
4+
35
use proc_macro2::TokenStream;
46
use quote::quote;
57

@@ -114,14 +116,18 @@ fn reconstruct(input: TokenStream) -> String {
114116

115117
#[cfg(nightly)]
116118
{
117-
let current_line = define.span().start().line;
119+
// `Span::start()` doesn't work on `proc_macro2`, we need to fallback to
120+
// `proc_macro` itself, see https://github.com/dtolnay/proc-macro2/issues/402.
121+
let current_line = define.span().unwrap().start().line();
118122
iterator.next();
119123
output.push_str("define ");
120124

121125
loop {
122126
match iterator.peek() {
123127
Some(item) => {
124-
if item.span().start().line == current_line {
128+
if item.span().unwrap().start().line()
129+
== current_line
130+
{
125131
output.push_str(&item.to_string());
126132
iterator.next();
127133
} else {

src/run.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,6 @@ fn command_add_linker_flags_msvc(command: &mut Command, variables: &HashMap<Stri
200200
mod tests {
201201
use super::*;
202202
use crate::predicates::*;
203-
use std::env::{remove_var, set_var};
204203

205204
#[test]
206205
fn test_run_c() {
@@ -220,8 +219,12 @@ mod tests {
220219
.success()
221220
.stdout(predicate::eq("Hello, World!\n").normalize());
222221
}
222+
223+
#[cfg(not(target_os = "macos"))] // macOS doesn't support `--defsym`
223224
#[test]
224225
fn test_run_c_ldflags() {
226+
use std::env::{remove_var, set_var};
227+
225228
let host = target_lexicon::HOST.to_string();
226229
let msvc = host.contains("msvc");
227230
if msvc {

0 commit comments

Comments
 (0)