
Line-by-line transliteration enabling link-time initialization, finalization, and typed link-section collection via ctor/dtor/section annotations; preserves upstream provenance with port-lint headers.
This is a Kotlin Multiplatform line-by-line transliteration port of mmastrac/linktime.
Original Project: This port is based on mmastrac/linktime. All design credit and project intent belong to the upstream authors; this repository is a faithful port to Kotlin Multiplatform with no behavioural changes intended.
This is an in-progress port. The goal is feature parity with the upstream Rust crate while providing a native Kotlin Multiplatform API. Every Kotlin file carries a // port-lint: source <path> header naming its upstream Rust counterpart so the AST-distance tool can track provenance.
The text below is reproduced and lightly edited from
https://github.com/mmastrac/linktime. It is the upstream project's own description and remains under the upstream authors' authorship; links have been rewritten to absolute upstream URLs so they continue to resolve from this repository.
Cross-platform libraries for link-time initialization, finalization and collection in Rust.
| crate | docs | version |
|---|---|---|
linktime |
||
ctor |
||
dtor |
||
link-section |
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.
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!");
}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();
}
}Contributions are welcome!
These projects are dual-licensed under the Apache License, Version 2.0 and the MIT License.
dependencies {
implementation("io.github.kotlinmania:ctor-kotlin:0.1.0")
}./gradlew build
./gradlew testSee AGENTS.md and CLAUDE.md for translator discipline, port-lint header convention, and Rust → Kotlin idiom mapping.
This Kotlin port is distributed under the same Apache-2.0 license as the upstream mmastrac/linktime. See LICENSE (and any sibling LICENSE-* / NOTICE files mirrored from upstream) for the full text.
Original work copyrighted by the linktime authors.
Kotlin port: Copyright (c) 2026 Sydney Renee and The Solace Project.
Thanks to the mmastrac/linktime maintainers and contributors for the original Rust implementation. This port reproduces their work in Kotlin Multiplatform; bug reports about upstream design or behavior should go to the upstream repository.
This is a Kotlin Multiplatform line-by-line transliteration port of mmastrac/linktime.
Original Project: This port is based on mmastrac/linktime. All design credit and project intent belong to the upstream authors; this repository is a faithful port to Kotlin Multiplatform with no behavioural changes intended.
This is an in-progress port. The goal is feature parity with the upstream Rust crate while providing a native Kotlin Multiplatform API. Every Kotlin file carries a // port-lint: source <path> header naming its upstream Rust counterpart so the AST-distance tool can track provenance.
The text below is reproduced and lightly edited from
https://github.com/mmastrac/linktime. It is the upstream project's own description and remains under the upstream authors' authorship; links have been rewritten to absolute upstream URLs so they continue to resolve from this repository.
Cross-platform libraries for link-time initialization, finalization and collection in Rust.
| crate | docs | version |
|---|---|---|
linktime |
||
ctor |
||
dtor |
||
link-section |
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.
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!");
}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();
}
}Contributions are welcome!
These projects are dual-licensed under the Apache License, Version 2.0 and the MIT License.
dependencies {
implementation("io.github.kotlinmania:ctor-kotlin:0.1.0")
}./gradlew build
./gradlew testSee AGENTS.md and CLAUDE.md for translator discipline, port-lint header convention, and Rust → Kotlin idiom mapping.
This Kotlin port is distributed under the same Apache-2.0 license as the upstream mmastrac/linktime. See LICENSE (and any sibling LICENSE-* / NOTICE files mirrored from upstream) for the full text.
Original work copyrighted by the linktime authors.
Kotlin port: Copyright (c) 2026 Sydney Renee and The Solace Project.
Thanks to the mmastrac/linktime maintainers and contributors for the original Rust implementation. This port reproduces their work in Kotlin Multiplatform; bug reports about upstream design or behavior should go to the upstream repository.