Skip to content

Commit

Permalink
Fix macOS build
Browse files Browse the repository at this point in the history
  • Loading branch information
jonas-schievink committed Jan 15, 2021
1 parent 970f779 commit 39706f9
Showing 1 changed file with 35 additions and 18 deletions.
53 changes: 35 additions & 18 deletions macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,28 +160,45 @@ pub fn timestamp(ts: TokenStream) -> TokenStream {
Err(e) => return e.to_compile_error().into(),
};

quote!(
const _: () = {
#[export_name = "_defmt_timestamp"]
fn defmt_timestamp(fmt: ::defmt::Formatter<'_>) {
match (fmt.inner, #(&(#args)),*) {
(_fmt_, #(#pats),*) => {
// NOTE: No format string index, and no finalize call.
#(#exprs;)*
if cfg!(feature = "unstable-test") {
// Only check that the formatting arguments compile.
quote!(
const _: () = {
fn defmt_timestamp(fmt: ::defmt::Formatter<'_>) {
match (fmt.inner, #(&(#args)),*) {
(_fmt_, #(#pats),*) => {
// NOTE: No format string index, and no finalize call.
#(#exprs;)*
}
}
}
};
)
.into()
} else {
quote!(
const _: () = {
#[export_name = "_defmt_timestamp"]
fn defmt_timestamp(fmt: ::defmt::Formatter<'_>) {
match (fmt.inner, #(&(#args)),*) {
(_fmt_, #(#pats),*) => {
// NOTE: No format string index, and no finalize call.
#(#exprs;)*
}
}
}
}

#sym;
#sym;

// Unique symbol name to prevent multiple `timestamp!` invocations in the crate graph.
// Uses `#symname` to ensure it is not discarded by the linker.
#[no_mangle]
#[link_section = ".defmt.end.timestamp"]
static __DEFMT_MARKER_TIMESTAMP_WAS_DEFINED: &u8 = &#symname;
};
)
.into()
// Unique symbol name to prevent multiple `timestamp!` invocations in the crate graph.
// Uses `#symname` to ensure it is not discarded by the linker.
#[no_mangle]
#[link_section = ".defmt.end.timestamp"]
static __DEFMT_MARKER_TIMESTAMP_WAS_DEFINED: &u8 = &#symname;
};
)
.into()
}
}

// returns a list of features of which one has to be enabled for `level` to be active
Expand Down

0 comments on commit 39706f9

Please sign in to comment.