proc-macro support for the ctor crate
  • Rust 98.8%
  • TypeScript 1.2%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Matt Mastracci b4e7ed6621
Some checks failed
CI / generate-matrix (push) Has been cancelled
CI / FreeBSD / test (stable) (push) Has been cancelled
CI / OpenBSD / test (stable) (push) Has been cancelled
CI / NetBSD / examples (stable) (push) Has been cancelled
CI / DragonFly BSD / examples (stable) (push) Has been cancelled
CI / success (push) Has been cancelled
Preparing ctor/dtor/link-section publish (#452)
Big changes:

 - AIX in link-section
 - UEFI
 - Win7/UWP and other windows platforms
- Fallback support for other OSes in ctor/dtor (use
init_array/fini_array by default)
2026-05-08 19:36:22 -06:00
.cargo AIX support in link-section (#446) 2026-05-08 19:22:27 -06:00
.github Don't fail build if cache fails (#448) 2026-05-08 22:07:00 +00:00
ctor Preparing ctor/dtor/link-section publish (#452) 2026-05-08 19:36:22 -06:00
docs Pre-1.0 doc and typo fixes, release 0.13.1 (#415) 2026-05-02 22:50:45 +00:00
dtor Preparing ctor/dtor/link-section publish (#452) 2026-05-08 19:36:22 -06:00
link-section Preparing ctor/dtor/link-section publish (#452) 2026-05-08 19:36:22 -06:00
linktime Preparing ctor/dtor/link-section publish (#452) 2026-05-08 19:36:22 -06:00
linktime-proc-macro Update crate metadata (#432) 2026-05-06 14:58:06 +00:00
macro-magic Fall back to .init_array on unsupported platforms (#445) 2026-05-08 07:53:55 -06:00
scattered-collect Update crate metadata (#432) 2026-05-06 14:58:06 +00:00
scattered-collect-proc-macro Update crate metadata (#432) 2026-05-06 14:58:06 +00:00
tests Fix unsafe C library access with default priority value (#442) 2026-05-07 12:52:21 +00:00
.gitignore ctor/dtor/link-section macro rewrite (#391) 2026-04-28 11:28:06 -06:00
Cargo.lock Preparing ctor/dtor/link-section publish (#452) 2026-05-08 19:36:22 -06:00
Cargo.toml Preparing ctor/dtor/link-section publish (#452) 2026-05-08 19:36:22 -06:00
CHANGELOG.md Pre-1.0 doc and typo fixes, release 0.13.1 (#415) 2026-05-02 22:50:45 +00:00
LICENSE-APACHE Fix #109 by adding real license files 2021-01-11 09:01:12 -07:00
LICENSE-MIT Fix #109 by adding real license files 2021-01-11 09:01:12 -07:00
README.md Cleaning up used(linker) (#411) 2026-05-02 15:44:24 -06:00

linktime

Cross-platform libraries for link-time initialization, finalization and collection in Rust.

Build Status

crate docs version
linktime docs.rs crates.io
ctor docs.rs crates.io
dtor docs.rs crates.io
link-section docs.rs crates.io

Crates

The linktime project comprises three crates, and the top-level linktime crate aggregates them all.

Pick-and-choose, or import the top-level crate to get all three.

ctor

Module initialization functions for Rust (like __attribute__((constructor)) in C/C++).

Run code before main to initialize data, external resources, or other state.

[dependencies]
linktime = { version = "...", features = ["ctor"] }  # note: already enabled by default
# or
ctor = "..."
use linktime::ctor; // or ctor::ctor
use libc_print::*;

#[ctor(unsafe)]
fn foo() {
    libc_println!("Life before main!");
}

dtor

Module shutdown functions for Rust (like __attribute__((destructor))).

Run code after main to clean up resources, or perform other final operations.

[dependencies]
linktime = { version = "...", features = ["dtor"] }  # note: already enabled by default
# or
dtor = "..."
use linktime::dtor; // or dtor::dtor
use libc_print::*;

#[dtor(unsafe)]
fn foo() {
    libc_println!("Life after main!");
}

Typed and untyped link section support for Rust.

Collect related items from an entire linked binary into a single link section.

[dependencies]
linktime = { version = "...", features = ["link-section"] }  # note: already enabled by default
# or
link-section = "..."
use linktime::link_section::{section, in_section, TypedSection};
use linktime::ctor;
use libc_print::*;

#[section]
static FOO: TypedSection<fn()>;

#[in_section(FOO)]
fn foo() {
    libc_println!("Hello, world!");
}

#[ctor(unsafe)]
fn print_numbers() {
    for f in FOO {
        f();
    }
}

Contributing

Contributions are welcome!

License

These projects are dual-licensed under the Apache License, Version 2.0 and the MIT License.