Skip to content
Beskid Platform specification

Beskid

Jump to a Beskid service

Beskid

Jump to a Beskid service

ExternalLibrary provider trait

Platform spec article

ExternalLibrary provider trait

Spec standingStandard

Owner
Piotr Mikstacki
Submitter
Piotr Mikstacki

Extern contracts carry a logical Library name (for example "libc", "pthread"). Linkers need concrete flags (-lc, -lpthread, framework paths). The ExternalLibrary trait abstracts that mapping so the CLI can support multiple providers over time.

/// Resolves a logical library name from Beskid `Extern` metadata to linker inputs.
pub trait ExternalLibrary: Send + Sync {
/// Stable provider id (for example `"c-posix"`, `"msvc"` Proposed).
fn id(&self) -> &'static str;
/// Target triple or host key this provider supports.
fn host_key(&self) -> &str;
/// Map logical name to linker arguments (for example `["-lc"]`).
fn resolve_link_args(&self, logical: &str) -> Result<Vec<String>, LibraryResolveError>;
/// Optional: search paths to pass the linker when the logical name is a path.
fn resolve_search_paths(&self, logical: &str) -> Vec<std::path::PathBuf>;
}

The reference CLI must ship at least one provider:

Provider idHostLogical names
c-posixLinux / macOS tier-1libc, libpthread, libm, paths to .so / .dylib

msvc / WinAPI providers are Proposed and out of scope for stdlib Standard (platform tier matrix).

Future providers (Rust rlib, Swift, etc.) must implement ExternalLibrary without changing Beskid source syntax—only manifest/link metadata and CLI selection.

LibraryResolveError must surface as CLI diagnostics with the logical name, provider id, and host key so authors can fix Project.proj link entries.

  • Trait + closed registry implementation: compiler/crates/beskid_analysis/src/external_library/ (trait_def.rs, providers.rs, registry.rs).
  • Closed provider list: compiler/crates/beskid_analysis/src/external_library/registry.rs::default_registry ships c-posix (+ posix alias) only; per ADR D-TOOL-FLI-0002.
  • C / POSIX mapping table: compiler/crates/beskid_analysis/src/external_library/providers.rs::C_POSIX_LOGICAL_NAMES (e.g. c -> -lc, m -> -lm, pthread -> -lpthread); canonicalization strips lib prefix and .so/.dylib/.a suffixes.
  • Tests: external_library::providers::tests and external_library::registry::tests (in-tree unit tests). End-to-end coverage in compiler/crates/beskid_tests/src/cli/import_lib.rs.