A syntax extension for Rust that runs pkg-config
at build-time to figure how
how to link native dependencies.
```rust
extern crate link_config = "link-config";
link_config!("libcurl")
extern { fn curleasyinit() -> *mut (); }
fn main() { let handle = unsafe { curleasyinit() }; // ... } ```
An invocation of the link_config!
macro will generate two extern blocks that
look like:
```rust // foo.rs link_config!("mylib")
// foo-expanded.rs
extern {}
extern {} ```
This means that a dynamic dependency is the default, but a static dependency can be specified via:
$ rustc foo.rs --cfg 'statik="mylib"'
The full syntax for an invocation is currently:
rust
link_config!("foo", ["bar", "baz"])
The library being linked is called foo
and both bar
/baz
are options to the
link_config!
macro itself. The currently known options are:
only_static
- Only emit a block for a static linkage, and enable it by
default.only_dylib
- Only emit a block for a dynamic linkage, and enable it by
default.favor_static
- Instead of emiting not(statik = "mylib")
, emit
not(dylib = "mylib")
, favoring the static block by default.system_static
- Allow system dependencies to be statically linked. This is
not allowed by default.When linking native libraries, this syntax extension is interested in answering three questions:
This library is not interested in various platform-specific flags to the linker and other various configuration options that are not always necessary.
To answer these questions, this library currently shells out to pkg-config
at
build time with the --libs
option and filters the return value to answer the
questions above. For static linking the tool is invoked with --static
The syntax extension then generates an extern
block with appropriate #[link]
and #[cfg]
attributes.
pkg-config
like LLVM or postgres.pkgconf
as a fallback if
pkg-config
is not available.link-config
is primarily distributed under the terms of both the MIT license
and the Apache License (Version 2.0), with portions covered by various BSD-like
licenses.
See LICENSE-APACHE, and LICENSE-MIT for details.