Skip to content

Commit

Permalink
Fix used_linker feature (#310)
Browse files Browse the repository at this point in the history
Reported in #309 -- feature logic was wrong.
  • Loading branch information
mmastrac authored Nov 20, 2024
1 parent fc9cd68 commit 16f0898
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion ctor/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ctor"
version = "0.2.8"
version = "0.2.9"
authors = ["Matt Mastracci <matthew@mastracci.com>"]
edition = "2018"
description = "__attribute__((constructor)) for Rust"
Expand Down
10 changes: 8 additions & 2 deletions ctor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,15 +170,21 @@ pub fn ctor(_attribute: TokenStream, function: TokenStream) -> TokenStream {
.expect("Unable to create identifier");

let tokens = ctor_attributes!();

let used = if cfg!(feature = "used_linker") {
quote!(#[used(linker)])
} else {
quote!(#[used])
};

let output = quote!(
#[cfg(not(any(target_os = "linux", target_os = "android", target_os = "freebsd", target_os = "netbsd", target_os = "openbsd", target_os = "dragonfly", target_os = "illumos", target_os = "haiku", target_vendor = "apple", windows)))]
compile_error!("#[ctor] is not supported on the current target");

#(#attrs)*
#vis #unsafety extern #abi #constness fn #ident() #block

#[cfg_attr(not(feature = "used_linker"), used)]
#[cfg_attr(feature = "used_linker", used(linker))]
#used
#[allow(non_upper_case_globals, non_snake_case)]
#[doc(hidden)]
#tokens
Expand Down

0 comments on commit 16f0898

Please sign in to comment.