Initial commit

All input and output functions are raw. Improved APIs will be added incrementally.
This commit is contained in:
2025-03-24 19:48:04 -07:00
commit f29350924b
20 changed files with 726 additions and 0 deletions
+7
View File
@@ -0,0 +1,7 @@
# OS Files
*~
._*
.DS_Store
# Rust
/target
+2
View File
@@ -0,0 +1,2 @@
hard_tabs = true
wrap_comments = true
+9
View File
@@ -0,0 +1,9 @@
{
"recommendations": [
"vadimcn.vscode-lldb",
"barbosshack.crates-io",
"usernamehw.errorlens",
"tamasfe.even-better-toml",
"rust-lang.rust-analyzer",
]
}
+33
View File
@@ -0,0 +1,33 @@
{
// VSCode
"editor.detectIndentation": false,
"editor.insertSpaces": false,
"editor.tabSize": 4,
"files.exclude": {
"**/target": true,
"**/Cargo.lock": true,
},
"files.insertFinalNewline": true,
"files.trimFinalNewlines": true,
"files.trimTrailingWhitespace": true,
"files.watcherExclude": {
"**/.git/**": true,
"**/target/**": true,
},
// Extensions
"crates.listPreReleases": true,
"evenBetterToml.formatter.alignComments": true,
"evenBetterToml.formatter.alignEntries": false,
"evenBetterToml.formatter.allowedBlankLines": 1,
"evenBetterToml.formatter.arrayAutoExpand": true,
"evenBetterToml.formatter.arrayTrailingComma": true,
"evenBetterToml.formatter.columnWidth": 80,
"evenBetterToml.formatter.reorderKeys": true,
"evenBetterToml.formatter.trailingNewline": true,
"rust-analyzer.imports.granularity.enforce": true,
"rust-analyzer.imports.granularity.group": "module",
"rust-analyzer.imports.group.enable": true,
"rust-analyzer.imports.merge.glob": false,
"rust-analyzer.imports.preferNoStd": true,
"rust-analyzer.showUnlinkedFileNotification": false,
}
+6
View File
@@ -0,0 +1,6 @@
How to Contribute
=================
We'd love to accept your patches and contributions to this project.
We just need you to follow the Contributor License Agreement outlined
in the latest v0.0.x of https://github.com/Skrunix/license
Generated
+23
View File
@@ -0,0 +1,23 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "architect"
version = "0.0.0"
dependencies = [
"paste",
]
[[package]]
name = "paste"
version = "1.0.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a"
[[package]]
name = "sample"
version = "0.0.0"
dependencies = [
"architect",
]
+23
View File
@@ -0,0 +1,23 @@
[workspace]
members = ["architect", "sample"]
resolver = "2"
[workspace.package]
authors = []
edition = "2024"
license-file = "LICENSE.md"
rust-version = "1.85.0"
[workspace.lints.rust]
unsafe_code = "forbid"
[profile.release]
codegen-units = 1
lto = "fat"
opt-level = 3
strip = "debuginfo"
[workspace.dependencies]
architect = { path = "architect", version = "=0.0.0", default-features = false }
paste = { version = "^1", default-features = false }
+7
View File
@@ -0,0 +1,7 @@
Skrunix Software License
========================
Permission to use, copy, modify, and/or distribute this software is
outlined in the latest v0.0.x of https://github.com/Skrunix/license
THE SOFTWARE IS PROVIDED "AS IS"
+11
View File
@@ -0,0 +1,11 @@
# Architect
A library for build scripts to interface with cargo. It is intended that you add this this library to your `[build-dependencies]`
## Various builds
- build: `cargo hack --feature-powerset build`
- clippy: `cargo hack --feature-powerset clippy -- -D warnings`
- fmt: `cargo fmt --check`
- docs: `RUSTDOCFLAGS="--cfg docsrs" cargo +nightly doc --all-features`
- publish: `cargo publish --dry-run -p architect`
+18
View File
@@ -0,0 +1,18 @@
[package]
name = "architect"
version = "0.0.0"
categories = ["development-tools::build-utils"]
description = "A cargo interface for build scripts"
repository = "https://github.com/QuantumShade/architect"
authors.workspace = true
edition.workspace = true
license-file.workspace = true
rust-version.workspace = true
[lints]
workspace = true
[dependencies]
paste = { workspace = true }
+5
View File
@@ -0,0 +1,5 @@
# architect
[![Crates Version](https://img.shields.io/crates/v/architect.svg)](https://crates.io/crates/architect)
A library for build scripts to interface with cargo. It is intended that you add this this library to your `[build-dependencies]`
+2
View File
@@ -0,0 +1,2 @@
/// Raw access for any missing APIs, these may be deleted at any time.
pub mod raw;
+245
View File
@@ -0,0 +1,245 @@
//! <https://doc.rust-lang.org/cargo/reference/environment-variables.html#environment-variables-cargo-sets-for-build-scripts>
//!
//! Cargo sets several environment variables when build scripts are run.
use std::env;
use std::ffi::OsString;
macro_rules! decl_var_os {
($($(#[$meta:meta])* $env:ident)*) => {
$(paste::paste! {
$(#[$meta])*
pub fn [<$env:lower _os>]() -> Option<OsString> {
env::var_os(stringify!($env))
}
})*
};
}
decl_var_os! {
/// Path to the `cargo` binary performing the build.
CARGO
/// The directory containing the manifest for the package being built (the package containing the build script). Also note that this is the value of the current working directory of the build script when it starts.
CARGO_MANIFEST_DIR
/// The path to the manifest of your package.
CARGO_MANIFEST_PATH
/// The manifest `links` value.
CARGO_MANIFEST_LINKS
/// Contains parameters needed for Cargos [jobserver] implementation to parallelize subprocesses. Rustc or cargo invocations from build.rs can already read `CARGO_MAKEFLAGS`, but GNU Make requires the flags to be specified either directly as arguments, or through the `MAKEFLAGS` environment variable. Currently Cargo doesnt set the `MAKEFLAGS` variable, but its free for build scripts invoking GNU Make to set it to the contents of `CARGO_MAKEFLAGS`.
///
/// [jobserver]: https://www.gnu.org/software/make/manual/html_node/Job-Slots.html
CARGO_MAKEFLAGS
/// The folder in which all output and intermediate artifacts should be placed. This folder is inside the build directory for the package being built, and it is unique for the package in question.
OUT_DIR
/// The target triple that is being compiled for. Native code should be compiled for this triple. See the [Target Triple] description for more information.
///
/// [Target Triple]: https://doc.rust-lang.org/cargo/appendix/glossary.html#target
TARGET
/// The host triple of the Rust compiler.
HOST
/// The parallelism specified as the top-level parallelism. This can be useful to pass a `-j` parameter to a system like `make`. Note that care should be taken when interpreting this environment variable. For historical purposes this is still provided but recent versions of Cargo, for example, do not need to run `make -j`, and instead can set the `MAKEFLAGS` env var to the content of `CARGO_MAKEFLAGS` to activate the use of Cargos GNU Make compatible [jobserver] for sub-make invocations.
///
/// [jobserver]: https://www.gnu.org/software/make/manual/html_node/Job-Slots.html
NUM_JOBS
/// Values of the corresponding variables for the profile currently being built.
OPT_LEVEL
/// Values of the corresponding variables for the profile currently being built.
DEBUG
/// `release` for release builds, `debug` for other builds. This is determined based on if the [profile] inherits from the [dev] or [release] profile. Using this environment variable is not recommended. Using other environment variables like `OPT_LEVEL` provide a more correct view of the actual settings being used.
///
/// [profile]: https://doc.rust-lang.org/cargo/reference/profiles.html
/// [dev]: https://doc.rust-lang.org/cargo/reference/profiles.html#dev
/// [release]: https://doc.rust-lang.org/cargo/reference/profiles.html#release
PROFILE
/// The compiler and documentation generator that Cargo has resolved to use, passed to the build script so it might use it as well.
RUSTC
/// The compiler and documentation generator that Cargo has resolved to use, passed to the build script so it might use it as well.
RUSTDOC
/// The `rustc` wrapper, if any, that Cargo is using. See [build.rustc-wrapper].
///
/// [build.rustc-wrapper]: https://doc.rust-lang.org/cargo/reference/config.html#buildrustc-wrapper
RUSTC_WRAPPER
/// The `rustc` wrapper, if any, that Cargo is using for workspace members. See [build.rustc-workspace-wrapper].
///
/// [build.rustc-workspace-wrapper]: https://doc.rust-lang.org/cargo/reference/config.html#buildrustc-workspace-wrapper
RUSTC_WORKSPACE_WRAPPER
/// The path to the linker binary that Cargo has resolved to use for the current target, if specified. The linker can be changed by editing `.cargo/config.toml`; see the documentation about [cargo configuration] for more information.
///
/// [cargo configuration]: https://doc.rust-lang.org/cargo/reference/config.html
RUSTC_LINKER
/// Extra flags that Cargo invokes `rustc` with, separated by a `0x1f` character (ASCII Unit Separator). See [build.rustflags]. Note that since Rust 1.55, `RUSTFLAGS` is removed from the environment; scripts should use `CARGO_ENCODED_RUSTFLAGS` instead.
///
/// [build.rustflags]: https://doc.rust-lang.org/cargo/reference/config.html#buildrustflags
CARGO_ENCODED_RUSTFLAGS
/// Each activated feature of the package being built.
CARGO_CFG_FEATURE
/// Set on [unix-like platforms].
///
/// [unix-like platforms]: https://doc.rust-lang.org/reference/conditional-compilation.html#unix-and-windows
CARGO_CFG_UNIX
/// Set on [windows-like platforms].
///
/// [windows-like platforms]: https://doc.rust-lang.org/reference/conditional-compilation.html#unix-and-windows
CARGO_CFG_WINDOWS
/// The [target family].
///
/// [target family]: https://doc.rust-lang.org/reference/conditional-compilation.html#target_family
CARGO_CFG_TARGET_FAMILY
/// The [target operating system].
///
/// [target operating system]: https://doc.rust-lang.org/reference/conditional-compilation.html#target_os
CARGO_CFG_TARGET_OS
/// The CPU [target architecture].
///
/// [target architecture]: https://doc.rust-lang.org/reference/conditional-compilation.html#target_arch
CARGO_CFG_TARGET_ARCH
/// The [target vendor].
///
/// [target vendor]: https://doc.rust-lang.org/reference/conditional-compilation.html#target_vendor
CARGO_CFG_TARGET_VENDOR
/// The [target environment] ABI.
///
/// [target environment]: https://doc.rust-lang.org/reference/conditional-compilation.html#target_env
CARGO_CFG_TARGET_ENV
/// The [target ABI].
///
/// [target ABI]: https://doc.rust-lang.org/reference/conditional-compilation.html#target_abi
CARGO_CFG_TARGET_ABI
/// The CPU [pointer width].
///
/// [pointer width]: https://doc.rust-lang.org/reference/conditional-compilation.html#target_pointer_width
CARGO_CFG_TARGET_POINTER_WIDTH
/// The CPU [target endianness].
///
/// [target endianness]: https://doc.rust-lang.org/reference/conditional-compilation.html#target_endian
CARGO_CFG_TARGET_ENDIAN
/// List of CPU [target features] enabled.
///
/// [target features]: https://doc.rust-lang.org/reference/conditional-compilation.html#target_feature
CARGO_CFG_TARGET_FEATURE
/// The full version of your package.
CARGO_PKG_VERSION
/// The major version of your package.
CARGO_PKG_VERSION_MAJOR
/// The minor version of your package.
CARGO_PKG_VERSION_MINOR
/// The patch version of your package.
CARGO_PKG_VERSION_PATCH
/// The pre-release version of your package.
CARGO_PKG_VERSION_PRE
/// Colon separated list of authors from the manifest of your package.
CARGO_PKG_AUTHORS
/// The name of your package.
CARGO_PKG_NAME
/// The description from the manifest of your package.
CARGO_PKG_DESCRIPTION
/// The home page from the manifest of your package.
CARGO_PKG_HOMEPAGE
/// The repository from the manifest of your package.
CARGO_PKG_REPOSITORY
/// The license from the manifest of your package.
CARGO_PKG_LICENSE
/// The license file from the manifest of your package.
CARGO_PKG_LICENSE_FILE
/// The Rust version from the manifest of your package. Note that this is the minimum Rust version supported by the package, not the current Rust version.
CARGO_PKG_RUST_VERSION
/// Path to the README file of your package.
CARGO_PKG_README
}
/// For each activated feature of the package being built, this environment
/// variable will be present where `<name>` is the name of the feature
/// uppercased and having `-` translated to `_`.
pub fn cargo_feature(name: &str) -> bool {
env::var_os(format!(
"CARGO_FEATURE_{}",
name.to_uppercase().replace('-', "_")
))
.is_some()
}
/// For each activated feature of the package being built, this environment
/// variable will be present where `<name>` is the name of the feature
/// uppercased and having `-` translated to `_`.
pub fn cargo_features() -> Vec<String> {
env::vars_os()
.filter_map(|(var, _)| {
var.into_string()
.ok()?
.strip_prefix("CARGO_FEATURE_")
.map(ToOwned::to_owned)
})
.collect()
}
/// For each [configuration option] of the package being built, this environment
/// variable will contain the value of the configuration, where `<cfg>` is the
/// name of the configuration uppercased and having `-` translated to `_`.
/// Boolean configurations are present if they are set, and not present
/// otherwise. Configurations with multiple values are joined to a single
/// variable with the values delimited by `,`. This includes values built-in to
/// the compiler (which can be seen with `rustc --print=cfg`) and values set by
/// build scripts and extra flags passed to `rustc` (such as those defined in
/// `RUSTFLAGS`). Some examples of what these variables are:
///
/// [configuration option]: https://doc.rust-lang.org/reference/conditional-compilation.html
pub fn cargo_cfg_os(cfg: &str) -> Option<OsString> {
env::var_os(format!(
"CARGO_CFG_{}",
cfg.to_uppercase().replace('-', "_")
))
}
/// For each [configuration option] of the package being built, this environment
/// variable will contain the value of the configuration, where `<cfg>` is the
/// name of the configuration uppercased and having `-` translated to `_`.
/// Boolean configurations are present if they are set, and not present
/// otherwise. Configurations with multiple values are joined to a single
/// variable with the values delimited by `,`. This includes values built-in to
/// the compiler (which can be seen with `rustc --print=cfg`) and values set by
/// build scripts and extra flags passed to `rustc` (such as those defined in
/// `RUSTFLAGS`). Some examples of what these variables are:
///
/// [configuration option]: https://doc.rust-lang.org/reference/conditional-compilation.html
pub fn cargo_cfgs_os() -> Vec<(String, OsString)> {
env::vars_os()
.filter_map(|(var, value)| {
var.into_string()
.ok()?
.strip_prefix("CARGO_CFG_")
.map(|k| (k.to_owned(), value))
})
.collect()
}
/// For more information about this set of environment variables, see build
/// script documentation about [links].
///
/// [links]: https://doc.rust-lang.org/cargo/reference/build-scripts.html#the-links-manifest-key
pub fn cargo_dep_os(name: &str, key: &str) -> Option<OsString> {
env::var_os(format!(
"DEP_{}_{}",
name.to_uppercase().replace('-', "_"),
key.to_uppercase().replace('-', "_")
))
}
/// For more information about this set of environment variables, see build
/// script documentation about [links].
///
/// [links]: https://doc.rust-lang.org/cargo/reference/build-scripts.html#the-links-manifest-key
pub fn cargo_deps_os() -> Vec<(String, String, OsString)> {
env::vars_os()
.filter_map(|(var, value)| {
var.into_string()
.ok()?
.strip_prefix("DEP_")
.and_then(|s| s.split_once('_'))
.map(|(d, k)| (d.to_owned(), k.to_owned(), value))
})
.collect()
}
+2
View File
@@ -0,0 +1,2 @@
pub mod input;
pub mod output;
+2
View File
@@ -0,0 +1,2 @@
/// Raw access for any missing APIs, these may be deleted at any time.
pub mod raw;
+302
View File
@@ -0,0 +1,302 @@
//! <https://doc.rust-lang.org/cargo/reference/build-scripts.html#outputs-of-the-build-script>
//!
//! Build scripts communicate with Cargo by printing to stdout. Cargo will
//! interpret each line that starts with `cargo::` as an instruction that will
//! influence compilation of the package. All other lines are ignored.
//!
//! > The order of `cargo::` instructions printed by the build script may affect
//! > the order of arguments that `cargo` passes to `rustc`. In turn, the order
//! > of arguments passed to `rustc` may affect the order of arguments passed to
//! > the linker. Therefore, you will want to pay attention to the order of the
//! > build scripts instructions. For example, if object `foo` needs to link
//! > against library `bar`, you may want to make sure that library `bar`s
//! > [`cargo::rustc-link-lib`] instruction appears _after_ instructions to link
//! > object `foo`.
/// The `rustc-link-arg` instruction tells Cargo to pass the [`-C link-arg=FLAG`
/// option] to the compiler, but only when building supported targets
/// (benchmarks, binaries, `cdylib` crates, examples, and tests). Its usage is
/// highly platform specific. It is useful to set the shared library version or
/// linker script.
///
/// [`cargo::rustc-link-lib`]: https://doc.rust-lang.org/cargo/reference/build-scripts.html#rustc-link-lib
/// [`-C link-arg=FLAG` option]: https://doc.rust-lang.org/rustc/codegen-options/index.html#link-arg
pub fn rustc_link_arg(flag: &str) {
println!("cargo::rustc-link-arg={flag}");
}
/// The `rustc-link-arg-bin` instruction tells Cargo to pass the [`-C
/// link-arg=FLAG` option] to the compiler, but only when building the binary
/// target with name `BIN`. Its usage is highly platform specific. It is useful
/// to set a linker script or other linker options.
///
/// [`-C link-arg=FLAG` option]: https://doc.rust-lang.org/rustc/codegen-options/index.html#link-arg
pub fn rustc_link_arg_bin(bin: &str, flag: &str) {
println!("cargo::rustc-link-arg-bin={bin}={flag}");
}
/// The `rustc-link-arg-bins` instruction tells Cargo to pass the [`-C
/// link-arg=FLAG` option] to the compiler, but only when building a binary
/// target. Its usage is highly platform specific. It is useful to set a linker
/// script or other linker options.
///
/// [`-C link-arg=FLAG` option]: https://doc.rust-lang.org/rustc/codegen-options/index.html#link-arg
pub fn rustc_link_arg_bins(flag: &str) {
println!("cargo::rustc-link-arg-bins={flag}");
}
/// The `rustc-link-lib` instruction tells Cargo to link the given library using
/// the compilers [`-l` flag]. This is typically used to link a native library
/// using [FFI].
///
/// The `LIB` string is passed directly to rustc, so it supports any syntax that
/// `-l` does. Currently the fully supported syntax for `LIB` is
/// `[KIND[:MODIFIERS]=]NAME[:RENAME]`.
///
/// The `-l` flag is only passed to the library target of the package, unless
/// there is no library target, in which case it is passed to all targets. This
/// is done because all other targets have an implicit dependency on the library
/// target, and the given library to link should only be included once. This
/// means that if a package has both a library and a binary target, the
/// _library_ has access to the symbols from the given lib, and the binary
/// should access them through the library targets public API.
///
/// The optional `KIND` may be one of `dylib`, `static`, or `framework`. See the
/// [rustc book] for more detail.
///
/// [`-l` flag]: https://doc.rust-lang.org/rustc/command-line-arguments.html#option-l-link-lib
/// [FFI]: https://doc.rust-lang.org/nomicon/ffi.html
/// [rustc book]: https://doc.rust-lang.org/rustc/command-line-arguments.html#option-l-link-lib
pub fn rustc_link_lib(lib: &str) {
println!("cargo::rustc-link-lib={lib}")
}
/// The `rustc-link-arg-tests` instruction tells Cargo to pass the [`-C
/// link-arg=FLAG` option] to the compiler, but only when building a tests
/// target.
///
/// [`-C link-arg=FLAG` option]: https://doc.rust-lang.org/rustc/codegen-options/index.html#link-arg
pub fn rustc_link_arg_tests(flag: &str) {
println!("cargo::rustc-link-arg-tests={flag}")
}
/// The `rustc-link-arg-examples` instruction tells Cargo to pass the [`-C
/// link-arg=FLAG` option] to the compiler, but only when building an examples
/// target.
///
/// [`-C link-arg=FLAG` option]: https://doc.rust-lang.org/rustc/codegen-options/index.html#link-arg
pub fn rustc_link_arg_examples(flag: &str) {
println!("cargo::rustc-link-arg-examples={flag}")
}
/// The `rustc-link-arg-benches` instruction tells Cargo to pass the [`-C
/// link-arg=FLAG` option] to the compiler, but only when building a benchmark
/// target.
///
/// [`-C link-arg=FLAG` option]: https://doc.rust-lang.org/rustc/codegen-options/index.html#link-arg
pub fn rustc_link_arg_benches(flag: &str) {
println!("cargo::rustc-link-arg-benches={flag}")
}
/// The `rustc-link-search` instruction tells Cargo to pass the [`-L` flag] to
/// the compiler to add a directory to the library search path.
///
/// The optional `KIND` may be one of `dependency`, `crate`, `native`,
/// `framework`, or `all`. See the [rustc book] for more detail.
///
/// These paths are also added to the [dynamic library search path environment
/// variable] if they are within the `OUT_DIR`. Depending on this behavior is
/// discouraged since this makes it difficult to use the resulting binary. In
/// general, it is best to avoid creating dynamic libraries in a build script
/// (using existing system libraries is fine).
///
/// [`-L` flag]: https://doc.rust-lang.org/rustc/command-line-arguments.html#option-l-search-path
/// [rustc book]: https://doc.rust-lang.org/rustc/command-line-arguments.html#option-l-search-path
/// [dynamic library search path environment variable]: https://doc.rust-lang.org/cargo/reference/environment-variables.html#dynamic-library-paths
pub fn rustc_link_search(kind: Option<&str>, path: &str) {
if let Some(kind) = kind {
println!("cargo::rustc-link-search={kind}={path}")
} else {
println!("cargo::rustc-link-search={path}")
}
}
/// The `rustc-flags` instruction tells Cargo to pass the given space-separated
/// flags to the compiler. This only allows the `-l` and `-L` flags, and is
/// equivalent to using [`rustc-link-lib`] and [`rustc-link-search`].
///
/// [`rustc-link-lib`]: https://doc.rust-lang.org/cargo/reference/build-scripts.html#rustc-link-lib
/// [`rustc-link-search`]: https://doc.rust-lang.org/cargo/reference/build-scripts.html#rustc-link-search
pub fn rustc_flags(flags: &[&str]) {
println!("cargo::rustc-flags={}", flags.join(" "))
}
/// The `rustc-cfg` instruction tells Cargo to pass the given value to the
/// [`--cfg` flag] to the compiler. This may be used for compile-time detection
/// of features to enable [conditional compilation]. Custom cfgs must either be
/// expected using the [`cargo::rustc-check-cfg`] instruction or usage will need
/// to allow the [`unexpected_cfgs`] lint to avoid unexpected cfgs warnings.
///
/// Note that this does _not_ affect Cargos dependency resolution. This cannot
/// be used to enable an optional dependency, or enable other Cargo features.
///
/// Be aware that [`Cargo features`] use the form `feature="foo"`. `cfg` values
/// passed with this flag are not restricted to that form, and may provide just
/// a single identifier, or any arbitrary key/value pair. For example, emitting
/// `cargo::rustc-cfg=abc` will then allow code to use `#[cfg(abc)]` (note the
/// lack of `feature=`). Or an arbitrary key/value pair may be used with an `=`
/// symbol like `cargo::rustc-cfg=my_component="foo"`. The key should be a Rust
/// identifier, the value should be a string.
///
/// [`--cfg` flag]: https://doc.rust-lang.org/rustc/command-line-arguments.html#option-cfg
/// [conditional compilation]: https://doc.rust-lang.org/reference/conditional-compilation.html
/// [`cargo::rustc-check-cfg`]: https://doc.rust-lang.org/cargo/reference/build-scripts.html#rustc-check-cfg
/// [`unexpected_cfgs`]: https://doc.rust-lang.org/rustc/lints/listing/warn-by-default.html#unexpected-cfgs
/// [`Cargo features`]: https://doc.rust-lang.org/cargo/reference/features.html
pub fn rustc_cfg(key: &str, value: Option<&str>) {
if let Some(value) = value {
println!("cargo::rustc-cfg={key}=\"{value}\"")
} else {
println!("cargo::rustc-cfg={key}")
}
}
/// Add to the list of expected config names and values that is used when
/// checking the reachable cfg expressions with the [`unexpected_cfgs`] lint.
///
/// The syntax of CHECK_CFG mirrors the rustc [`--check-cfg` flag], see
/// [Checking conditional configurations] for more details.
///
/// The instruction can be used like this:
///
/// // build.rs
/// println!("cargo::rustc-check-cfg=cfg(foo, values(\"bar\"))");
/// if foo_bar_condition {
/// println!("cargo::rustc-cfg=foo=\"bar\"");
/// }
///
/// Note that all possible cfgs should be defined, regardless of which cfgs are
/// currently enabled. This includes all possible values of a given cfg name.
///
/// It is recommended to group the `cargo::rustc-check-cfg` and
/// [`cargo::rustc-cfg`] instructions as closely as possible in order to avoid
/// typos, missing check-cfg, stale cfgs…
///
/// See also the [conditional compilation] example.
///
/// [`unexpected_cfgs`]: https://doc.rust-lang.org/rustc/lints/listing/warn-by-default.html#unexpected-cfgs
/// [`--check-cfg` flag]: https://doc.rust-lang.org/rustc/command-line-arguments.html#option-check-cfg
/// [Checking conditional configurations]: https://doc.rust-lang.org/rustc/check-cfg.html
/// [`cargo::rustc-cfg`]: https://doc.rust-lang.org/rustc/command-line-arguments.html#option-cfg
/// [conditional compilation]: https://doc.rust-lang.org/cargo/reference/build-script-examples.html#conditional-compilation
pub fn rustc_check_cfg(check_cfg: &str) {
println!("cargo::rustc-check-cfg={check_cfg}")
}
/// The `rustc-env` instruction tells Cargo to set the given environment
/// variable when compiling the package. The value can be then retrieved by the
/// [`env!` macro] in the compiled crate. This is useful for embedding
/// additional metadata in crates code, such as the hash of git HEAD or the
/// unique identifier of a continuous integration server.
///
/// See also the [environment variables automatically included by Cargo].
///
/// > Note: These environment variables are also set when running an executable
/// > with `cargo run` or `cargo test`. However, this usage is discouraged since
/// > it ties the executable to Cargos execution environment. Normally, these
/// > environment variables should only be checked at compile-time with the
/// > `env!` macro.
///
/// [`env!` macro]: https://doc.rust-lang.org/std/macro.env.html
/// [environment variables automatically included by Cargo]: https://doc.rust-lang.org/cargo/reference/environment-variables.html#environment-variables-cargo-sets-for-crates
pub fn rustc_env(var: &str, value: &str) {
println!("cargo::rustc-env={var}={value}")
}
/// The `rustc-cdylib-link-arg` instruction tells Cargo to pass the [`-C
/// link-arg=FLAG` option] to the compiler, but only when building a `cdylib`
/// library target. Its usage is highly platform specific. It is useful to set
/// the shared library version or the runtime-path.
///
/// [`-C link-arg=FLAG` option]: https://doc.rust-lang.org/rustc/codegen-options/index.html#link-arg
pub fn rustc_cdylib_link_arg(flag: &str) {
println!("cargo::rustc-cdylib-link-arg={flag}")
}
/// The `error` instruction tells Cargo to display an error after the build
/// script has finished running, and then fail the build.
///
/// > Note: Build script libraries should carefully consider if they want to use
/// > `cargo::error` versus returning a `Result`. It may be better to return a
/// > `Result`, and allow the caller to decide if the error is fatal or not. The
/// > caller can then decide whether or not to display the `Err` variant using
/// > `cargo::error`.
pub fn error(message: &str) {
println!("cargo::error={message}")
}
/// The `warning` instruction tells Cargo to display a warning after the build
/// script has finished running. Warnings are only shown for `path` dependencies
/// (that is, those youre working on locally), so for example warnings printed
/// out in [crates.io] crates are not emitted by default, unless the build
/// fails. The `-vv` “very verbose” flag may be used to have Cargo display
/// warnings for all crates.
///
/// [crates.io]: https://crates.io/
pub fn warning(message: &str) {
println!("cargo::warning={message}")
}
/// The `rerun-if-changed` instruction tells Cargo to re-run the build script if
/// the file at the given path has changed. Currently, Cargo only uses the
/// filesystem last-modified “mtime” timestamp to determine if the file has
/// changed. It compares against an internal cached timestamp of when the build
/// script last ran.
///
/// If the path points to a directory, it will scan the entire directory for any
/// modifications.
///
/// If the build script inherently does not need to re-run under any
/// circumstance, then emitting `cargo::rerun-if-changed=build.rs` is a simple
/// way to prevent it from being re-run (otherwise, the default if no `rerun-if`
/// instructions are emitted is to scan the entire package directory for
/// changes). Cargo automatically handles whether or not the script itself needs
/// to be recompiled, and of course the script will be re-run after it has been
/// recompiled. Otherwise, specifying `build.rs` is redundant and unnecessary.
pub fn rerun_if_changed(path: &str) {
println!("cargo::rerun-if-changed={path}")
}
/// The `rerun-if-env-changed` instruction tells Cargo to re-run the build
/// script if the value of an environment variable of the given name has
/// changed.
///
/// Note that the environment variables here are intended for global environment
/// variables like `CC` and such, it is not possible to use this for environment
/// variables like `TARGET` that [Cargo sets for build scripts]. The environment
/// variables in use are those received by `cargo` invocations, not those
/// received by the executable of the build script.
///
/// [Cargo sets for build scripts]: https://doc.rust-lang.org/cargo/reference/environment-variables.html#environment-variables-cargo-sets-for-build-scripts
pub fn rerun_if_env_changed(name: &str) {
println!("cargo::rerun-if-env-changed={name}")
}
/// Build scripts can generate an arbitrary set of metadata in the form of
/// key-value pairs. This metadata is set with the `cargo::metadata=KEY=VALUE`
/// instruction.
///
/// The metadata is passed to the build scripts of *dependent* packages. For
/// example, if the package `foo` depends on `bar`, which links `baz`, then if
/// `bar` generates `key=value` as part of its build script metadata, then the
/// build script of `foo` will have the environment variables
/// `DEP_BAZ_KEY=value` (note that the value of the `links` key is used). See
/// the [“Using another `sys` crate”] for an example of how this can be used.
///
/// Note that metadata is only passed to immediate dependents, not transitive
/// dependents.
///
/// [“Using another `sys` crate”]: https://doc.rust-lang.org/cargo/reference/build-script-examples.html#using-another-sys-crate
pub fn metadata(key: &str, value: &str) {
println!("cargo::metadata={key}={value}")
}
+2
View File
@@ -0,0 +1,2 @@
[toolchain]
channel = "stable"
+14
View File
@@ -0,0 +1,14 @@
[package]
name = "sample"
version = "0.0.0"
authors.workspace = true
edition.workspace = true
license-file.workspace = true
rust-version.workspace = true
[lints]
workspace = true
[build-dependencies]
architect = { workspace = true }
+13
View File
@@ -0,0 +1,13 @@
fn main() {
for (k, v) in std::env::vars() {
architect::output::raw::warning(&format!("{k}={v}"));
}
let manifest_path = architect::input::raw::cargo_manifest_path_os().unwrap();
architect::output::raw::warning(&format!("Manifest Path: {manifest_path:?}"));
let arch = architect::input::raw::cargo_cfg_target_arch_os().unwrap();
let os = architect::input::raw::cargo_cfg_target_os_os().unwrap();
let endian = architect::input::raw::cargo_cfg_target_endian_os().unwrap();
architect::output::raw::warning(&format!("Target: {arch:?} {os:?} ({endian:?})"));
}
View File