cdylib-link-lines-0.1.5/.cargo_vcs_info.json0000644000000001360000000000100143500ustar { "git": { "sha1": "a10b8e07e18d81bfce7c8d83ec18d855c53232de" }, "path_in_vcs": "" }cdylib-link-lines-0.1.5/.gitignore000064400000000000000000000000441046102023000151260ustar 00000000000000/target **/*.rs.bk Cargo.lock .idea cdylib-link-lines-0.1.5/Cargo.toml0000644000000014000000000000100123410ustar # THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility # with all versions of Cargo and also rewrite `path` dependencies # to registry (e.g., crates.io) dependencies. # # If you are reading this file be aware that the original Cargo.toml # will likely look very different (and much more reasonable). # See Cargo.toml.orig for the original contents. [package] edition = "2018" name = "cdylib-link-lines" version = "0.1.5" authors = ["Luca Barbato "] description = "Collection of link-lines useful to build correct cdylibs on targets" readme = "README.md" license = "MIT" repository = "https://github.com/lu-zero/cdylib-link-lines" cdylib-link-lines-0.1.5/Cargo.toml.orig000064400000000000000000000004551046102023000160330ustar 00000000000000[package] name = "cdylib-link-lines" version = "0.1.5" description = "Collection of link-lines useful to build correct cdylibs on targets" authors = ["Luca Barbato "] repository = "https://github.com/lu-zero/cdylib-link-lines" edition = "2018" license = "MIT" readme = "README.md" cdylib-link-lines-0.1.5/LICENSE000064400000000000000000000020551046102023000141470ustar 00000000000000MIT License Copyright (c) 2019 Luca Barbato Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. cdylib-link-lines-0.1.5/README.md000064400000000000000000000020241046102023000144150ustar 00000000000000# link-line helper to build correct cdylibs [![LICENSE](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE) ## Supported targets - Linux and Android - macOS and iOS - Windows (gnu) ## Usage ### build.rs Add the crate to your [build-dependencies](https://doc.rust-lang.org/cargo/reference/manifest.html#dependency-sections), in your `build.rs`, call `metabuild()`. ``` toml [build-dependencies] cdylib-link-lines = "0.1" ``` ``` rust fn main() { cdylib_link_lines::metabuild(); } ``` ### metabuild If you are using the `metabuild` [unstable feature](https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#metabuild) ``` toml cargo-features = ["metabuild"] [package] name = "mypackage" ... metabuild = ["cdylib-link-lines"] [build-dependencies] cdylib-link-lines = "0.1" ``` ## Credits Helper spun off [crav1e](https://github.com/lu-zero/crav1e), contains code written by Luca Barbato and Derek Buitenhuis. Synchronized with the [cargo-c](https://github.com/lu-zero/cargo-c) 0.9 logic thanks to Ivan Enderlin. cdylib-link-lines-0.1.5/src/lib.rs000064400000000000000000000054101046102023000150430ustar 00000000000000use std::env; use std::path::PathBuf; pub fn metabuild() { let arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap(); let os = env::var("CARGO_CFG_TARGET_OS").unwrap(); let env = env::var("CARGO_CFG_TARGET_ENV").unwrap(); // We do not care about `_pre` and such. let major = env::var("CARGO_PKG_VERSION_MAJOR").unwrap(); let minor = env::var("CARGO_PKG_VERSION_MINOR").unwrap(); let patch = env::var("CARGO_PKG_VERSION_PATCH").unwrap(); // Give the priority to [`cargo-c`](https://github.com/lu-zero/cargo-c) in case of. let prefix = PathBuf::from(env::var_os("CARGO_C_PREFIX").unwrap_or("/usr/local".into())); let libdir = env::var_os("CARGO_C_LIBDIR").map_or(prefix.join("lib"), Into::into); let target_dir = env::var_os("CARGO_TARGET_DIR").map_or( { let manifest_dir = PathBuf::from(env::var_os("CARGO_MANIFEST_DIR").unwrap()); manifest_dir .join("target") .join(std::env::var("PROFILE").unwrap()) }, Into::into, ); let name = env::var_os("CARGO_PKG_NAME").unwrap(); let name = name.to_str().expect("pkg name is not valid UTF-8"); let lines = shared_object_link_args( &name, &major, &minor, &patch, &arch, &os, &env, libdir, target_dir, ); for line in lines { println!("cargo:rustc-cdylib-link-arg={}", line); } } /// Return a list of linker arguments useful to produce a /// platform-correct dynamic library. pub fn shared_object_link_args( name: &str, major: &str, minor: &str, patch: &str, _arch: &str, os: &str, env: &str, libdir: PathBuf, target_dir: PathBuf, ) -> Vec { let mut lines = Vec::new(); match (os, env) { ("android", _) => { lines.push(format!("-Wl,-soname,lib{}.so", name)); } ("linux", _) | ("freebsd", _) | ("dragonfly", _) | ("netbsd", _) => { lines.push(format!("-Wl,-soname,lib{}.so.{}", name, major)); } ("macos", _) | ("ios", _) => { lines.push(format!( "-Wl,-install_name,{1}/lib{0}.{2}.{3}.{4}.dylib,-current_version,{2}.{3}.{4},-compatibility_version,{2}", name, libdir.display(), major, minor, patch, )); } ("windows", "gnu") => { // This is only set up to work on GNU toolchain versions of Rust lines.push(format!( "-Wl,--out-implib,{}", target_dir.join(format!("{}.dll.a", name)).display() )); lines.push(format!( "-Wl,--output-def,{}", target_dir.join(format!("{}.def", name)).display() )); } _ => {} } lines }