Development · Evolving reference
NativeAbiProfile
Selects the foreign-language ABI profile at a native boundary.
Sn is under heavy development. This reference includes the intended 1.0 design; features may be incomplete in the current compiler. Read the status →
Module std.abi
import std.abi;Public declaration contracts and authored examples. A page can document several related symbols. Implementation bodies are excluded.
NativeAbiProfile
pub enum NativeAbiProfileSelects the foreign-language ABI profile at a native boundary.
The profile is interpreted under std.compiler.CurrentTargetAbi; it never changes the default convention of unqualified Sn functions.
Example
module example.native_abi_catalog;
import std.abi as abi;
struct<.C> NativeResource;
alias Visitor = unsafe fn<.C>(void*) -> void;
[abi.NativeLayout(Pack = 4_usize, Alignment = 8_usize)]
struct<.C> NativeHeader {
[abi.NativeFieldLayout(Offset = 0_usize, Alignment = 4_usize)]
pub Tag: u32;
}
[abi.Import(Symbol = "sn_fill", Version = "SNAPI_1.0", Mode = .Linked)]
[abi.NoUnwind]
fn<.C> Fill(
[abi.NonNull]
[abi.NoCapture]
[abi.NoAlias]
[abi.PointeeAlignment(16)] Destination: mut byte*,
Count: usize
) -> void;
[abi.Import(Symbol = "sn_visit")]
fn<.C> Visit(
[abi.SynchronousCallback(ContextParameter = 1_usize)] Callback: Visitor,
Context: void*
) -> void;
[abi.Import(Symbol = "sn_release")]
fn<.C> Release(
[abi.TakesOwnership] Resource: mut NativeResource*
) -> void;
[abi.Import(Symbol = "sn_create")]
[abi.ReturnsOwnership]
fn<.C> Create() -> mut NativeResource*;
[abi.Import(Symbol = "sn_data")]
[abi.BorrowedFrom(0_usize)]
fn<.C> Data(Resource: readonly NativeResource*) -> readonly byte*;
[abi.Import(Symbol = "sn_library_name")]
[abi.BorrowedFromLibrary]
fn<.C> LibraryName() -> readonly byte*;
[abi.Import(Symbol = "abort")]
[abi.NoUnwind]
[abi.NoReturn]
fn<.C> Abort() -> never;
final class RuntimeApi {
[abi.Import(Symbol = "sn_optional_create", Mode = .RuntimeOptional)]
[abi.NoUnwind]
[abi.NonNull]
[abi.PointeeAlignment(8)]
[abi.ReturnsOwnership]
pub Create: (unsafe fn<.C>() -> mut NativeResource*)?;
[abi.Import(Symbol = "sn_invoke", Mode = .RuntimeRequired)]
[abi.NoCapture(Parameter = 1_usize)]
[abi.NoAlias(Parameter = 2_usize)]
[abi.SynchronousCallback(ContextParameter = 1_usize, Parameter = 0_usize)]
[abi.TakesOwnership(Parameter = 2_usize)]
pub Invoke: unsafe fn<.C>(Visitor, void*, mut NativeResource*) -> void;
[abi.Import(Symbol = "sn_borrow", Mode = .RuntimeRequired)]
[abi.BorrowedFrom(Parameter = 0_usize)]
pub Borrow: unsafe fn<.C>(readonly NativeResource*) -> readonly byte*;
}
[abi.Export(Symbol = "sn_status", Version = "SNAPI_1.0")]
pub fn<.C> Status() -> i32 { return 0; }
fn Main() -> i32 {
let Header = NativeHeader { Tag = 7 };
if Header.Tag != 7 || Status() != 0 { return 1; }
return 0;
}NativeAbiProfile.C
C;Selects the target C language ABI.
Documentation snapshot: October 24, 2026 About versions ↗