cargo-emit-0.2.1/.cargo_vcs_info.json 0000644 00000000112 00000000001 0013055 0 ustar {
"git": {
"sha1": "95b11849379994ba0b5b5ed921a4e373c041d5f1"
}
}
cargo-emit-0.2.1/CHANGELOG.md 0000644 0000000 0000000 00000005006 00726746425 0013515 0 ustar 0000000 0000000 # Changelog [![Crates.io][crate-badge]][crate]
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog] and this project adheres to
[Semantic Versioning].
## [Unreleased]
## [0.2.1] - 2021-09-01
### Fixed
- Added `#[allow(clippy::explicit_write)]` to prevent false-positives.
- Added `examples/macros.rs` file and corresponding `cargo clippy --example "macros" -- -D warnings` CI job to prevent future clippy issues.
## [0.2.0] - 2021-08-31
### Fixed
- Fixed recursion in `rustc_link_search!(…)`.
- Removed redundant `$x:literal` macro patterns.
### Added
- [`rustc_link_arg!`](https://docs.rs/cargo-emit/0.2.0/cargo_emit/macro.rustc_link_arg.html)
- [`rustc_link_arg_bin!`](https://docs.rs/cargo-emit/0.2.0/cargo_emit/macro.rustc_link_arg_bin.html)
- [`rustc_link_arg_bins!`](https://docs.rs/cargo-emit/0.2.0/cargo_emit/macro.rustc_link_arg_bins.html)
- 40 snapshot tests (using [insta](https://crates.io/crates/insta))
- Optional `to:` parameter for writing into a `std::fmt::Write` or `io::fmt::Write`.
# Removed
- `#![no_std]`, since the project never worked on no_std to begin with.
## [0.1.1] - 2019-12-15
### Fixed
- Links to docs for specific macros.
## 0.1.0 - 2019-12-15
### Added
- [`pair!`](https://docs.rs/cargo-emit/0.1.0/cargo_emit/macro.pair.html)
- [`rerun_if_changed!`](https://docs.rs/cargo-emit/0.1.0/cargo_emit/macro.rerun_if_changed.html)
- [`rerun_if_env_changed!`](https://docs.rs/cargo-emit/0.1.0/cargo_emit/macro.rerun_if_env_changed.html)
- [`rustc_cdylib_link_arg!`](https://docs.rs/cargo-emit/0.1.0/cargo_emit/macro.rustc_cdylib_link_arg.html)
- [`rustc_cfg!`](https://docs.rs/cargo-emit/0.1.0/cargo_emit/macro.rustc_cfg.html)
- [`rustc_env!`](https://docs.rs/cargo-emit/0.1.0/cargo_emit/macro.rustc_env.html)
- [`rustc_flags!`](https://docs.rs/cargo-emit/0.1.0/cargo_emit/macro.rustc_flags.html)
- [`rustc_link_lib!`](https://docs.rs/cargo-emit/0.1.0/cargo_emit/macro.rustc_link_lib.html)
- [`rustc_link_search!`](https://docs.rs/cargo-emit/0.1.0/cargo_emit/macro.rustc_link_search.html)
- [`warning!`](https://docs.rs/cargo-emit/0.1.0/cargo_emit/macro.warning.html)
[crate]: https://crates.io/crates/cargo-emit
[crate-badge]: https://img.shields.io/crates/v/cargo-emit.svg
[Keep a Changelog]: http://keepachangelog.com/en/1.0.0/
[Semantic Versioning]: http://semver.org/spec/v2.0.0.html
[Unreleased]: https://github.com/nvzqz/static-assertions-rs/compare/v0.1.1...HEAD
[0.1.1]: https://github.com/nvzqz/static-assertions-rs/compare/v0.1.0...v0.1.1
cargo-emit-0.2.1/Cargo.lock 0000644 00000014010 00000000001 0011032 0 ustar # This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "autocfg"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a"
[[package]]
name = "cargo-emit"
version = "0.2.1"
dependencies = [
"insta",
]
[[package]]
name = "console"
version = "0.14.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3993e6445baa160675931ec041a5e03ca84b9c6e32a056150d3aa2bdda0a1f45"
dependencies = [
"encode_unicode",
"lazy_static",
"libc",
"terminal_size",
"winapi",
]
[[package]]
name = "dtoa"
version = "0.4.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "56899898ce76aaf4a0f24d914c97ea6ed976d42fec6ad33fcbb0a1103e07b2b0"
[[package]]
name = "encode_unicode"
version = "0.3.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f"
[[package]]
name = "hashbrown"
version = "0.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e"
[[package]]
name = "indexmap"
version = "1.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bc633605454125dec4b66843673f01c7df2b89479b32e0ed634e43a91cff62a5"
dependencies = [
"autocfg",
"hashbrown",
]
[[package]]
name = "insta"
version = "1.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "58019516c1403ac45b106c9fc4e8fcbd77a78e98b014c619d1506338902ccfa4"
dependencies = [
"console",
"lazy_static",
"serde",
"serde_json",
"serde_yaml",
"similar",
"uuid",
]
[[package]]
name = "itoa"
version = "0.4.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4"
[[package]]
name = "lazy_static"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "libc"
version = "0.2.101"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3cb00336871be5ed2c8ed44b60ae9959dc5b9f08539422ed43f09e34ecaeba21"
[[package]]
name = "linked-hash-map"
version = "0.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7fb9b38af92608140b86b693604b9ffcc5824240a484d1ecd4795bacb2fe88f3"
[[package]]
name = "proc-macro2"
version = "1.0.29"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b9f5105d4fdaab20335ca9565e106a5d9b82b6219b5ba735731124ac6711d23d"
dependencies = [
"unicode-xid",
]
[[package]]
name = "quote"
version = "1.0.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7"
dependencies = [
"proc-macro2",
]
[[package]]
name = "ryu"
version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e"
[[package]]
name = "serde"
version = "1.0.130"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f12d06de37cf59146fbdecab66aa99f9fe4f78722e3607577a5375d66bd0c913"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.130"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d7bc1a1ab1961464eae040d96713baa5a724a8152c1222492465b54322ec508b"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "serde_json"
version = "1.0.67"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a7f9e390c27c3c0ce8bc5d725f6e4d30a29d26659494aa4b17535f7522c5c950"
dependencies = [
"itoa",
"ryu",
"serde",
]
[[package]]
name = "serde_yaml"
version = "0.8.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ad104641f3c958dab30eb3010e834c2622d1f3f4c530fef1dee20ad9485f3c09"
dependencies = [
"dtoa",
"indexmap",
"serde",
"yaml-rust",
]
[[package]]
name = "similar"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1ad1d488a557b235fc46dae55512ffbfc429d2482b08b4d9435ab07384ca8aec"
[[package]]
name = "syn"
version = "1.0.75"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b7f58f7e8eaa0009c5fec437aabf511bd9933e4b2d7407bd05273c01a8906ea7"
dependencies = [
"proc-macro2",
"quote",
"unicode-xid",
]
[[package]]
name = "terminal_size"
version = "0.1.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "633c1a546cee861a1a6d0dc69ebeca693bf4296661ba7852b9d21d159e0506df"
dependencies = [
"libc",
"winapi",
]
[[package]]
name = "unicode-xid"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3"
[[package]]
name = "uuid"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7"
[[package]]
name = "winapi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
dependencies = [
"winapi-i686-pc-windows-gnu",
"winapi-x86_64-pc-windows-gnu",
]
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
name = "yaml-rust"
version = "0.4.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "56c1936c4cc7a1c9ab21a1ebb602eb942ba868cbd44a99cb7cdc5892335e1c85"
dependencies = [
"linked-hash-map",
]
cargo-emit-0.2.1/Cargo.toml 0000644 00000002143 00000000001 0011061 0 ustar # 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 believe there's an error in this file please file an
# issue against the rust-lang/cargo repository. If you're
# editing this file be aware that the upstream Cargo.toml
# will likely look very different (and much more reasonable)
[package]
edition = "2018"
name = "cargo-emit"
version = "0.2.1"
authors = ["Nikolai Vazquez", "Vincent Esche"]
include = ["Cargo.toml", "src", "README.md", "CHANGELOG.md", "LICENSE*"]
description = "Talk to Cargo easily at build time."
homepage = "https://github.com/nvzqz/cargo-emit"
documentation = "https://docs.rs/cargo-emit"
readme = "README.md"
keywords = ["cargo", "build", "print", "warn"]
categories = ["development-tools::build-utils", "no-std", "rust-patterns"]
license = "MIT OR Apache-2.0"
repository = "https://github.com/nvzqz/cargo-emit"
[dev-dependencies.insta]
version = "1.7.2"
cargo-emit-0.2.1/Cargo.toml.orig 0000644 0000000 0000000 00000001117 00726746425 0014572 0 ustar 0000000 0000000 [package]
name = "cargo-emit"
version = "0.2.1"
authors = ["Nikolai Vazquez", "Vincent Esche"]
license = "MIT OR Apache-2.0"
readme = "README.md"
homepage = "https://github.com/nvzqz/cargo-emit"
repository = "https://github.com/nvzqz/cargo-emit"
documentation = "https://docs.rs/cargo-emit"
description = "Talk to Cargo easily at build time."
categories = ["development-tools::build-utils", "no-std", "rust-patterns"]
keywords = ["cargo", "build", "print", "warn"]
include = ["Cargo.toml", "src", "README.md", "CHANGELOG.md", "LICENSE*"]
edition = "2018"
[dev-dependencies]
insta = "1.7.2"
cargo-emit-0.2.1/LICENSE-APACHE 0000644 0000000 0000000 00000026136 00726746425 0013637 0 ustar 0000000 0000000
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
cargo-emit-0.2.1/LICENSE-MIT 0000644 0000000 0000000 00000002060 00726746425 0013335 0 ustar 0000000 0000000 MIT License
Copyright (c) 2019 Nikolai Vazquez
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.
cargo-emit-0.2.1/README.md 0000644 0000000 0000000 00000011320 00726746425 0013157 0 ustar 0000000 0000000
Talk to Cargo easily at build time, brought to you by [Nikolai Vazquez].
This library provides:
- Convenience macros for communicating with Cargo during the [`build.rs`]
phrase. Cargo listens to certain [build script outputs] that dictate how
it should behave.
- An accessible location for seeing what script build outputs are available
to emit.
- Protection against typos that can be made when printing these formatted
outputs directly yourself. Mistyping macro names will result in a compile
failure.
[Nikolai Vazquez]: https://twitter.com/NikolaiVazquez
[`build.rs`]: https://doc.rust-lang.org/cargo/reference/build-scripts.html
[build script outputs]: https://doc.rust-lang.org/cargo/reference/build-scripts.html#outputs-of-the-build-script
## Usage
This crate exposes the following macros:
| Macro | Output |
|----------------------------------------|---------------------------------------|
| [`pair!($key, $value)`] | `cargo:$key=$value` |
| [`rerun_if_changed!($path)`] | `cargo:rerun-if-changed=$path` |
| [`rerun_if_env_changed!($key)`] | `cargo:rerun-if-env-changed=$key` |
| [`rustc_cdylib_link_arg!($flag)`] | `cargo:rustc-cdylib-link-arg=$flag` |
| [`rustc_cfg!($feature)`] | `cargo:rustc-cfg=$feature` |
| [`rustc_env!($key, $value)`] | `cargo:rustc-env=$key=$value` |
| [`rustc_flags!($flags)`] | `cargo:rustc-flags=$flags` |
| [`rustc_link_arg!($arg)`] | `cargo:rustc-link-arg=$arg` |
| [`rustc_link_arg_bin!($bin => $arg)`] | `cargo:rustc-link-arg-bin=$bin=$arg` |
| [`rustc_link_arg_bins!($arg)`] | `cargo:rustc-link-arg-bins=$arg` |
| [`rustc_link_lib!($name => $kind)`] | `cargo:rustc-link-lib=$kind=$name` |
| [`rustc_link_search!($path => $kind)`] | `cargo:rustc-link-search=$kind=$path` |
| [`warning!($message)`] | `cargo:warning=$message` |
[`pair!($key, $value)`]: https://docs.rs/cargo-emit/latest/cargo_emit/macro.pair.html
[`rerun_if_changed!($path)`]: https://docs.rs/cargo-emit/latest/cargo_emit/macro.rerun_if_changed.html
[`rerun_if_env_changed!($key)`]: https://docs.rs/cargo-emit/latest/cargo_emit/macro.rerun_if_env_changed.html
[`rustc_cdylib_link_arg!($flag)`]: https://docs.rs/cargo-emit/latest/cargo_emit/macro.rustc_cdylib_link_arg.html
[`rustc_cfg!($feature)`]: https://docs.rs/cargo-emit/latest/cargo_emit/macro.rustc_cfg.html
[`rustc_env!($key, $value)`]: https://docs.rs/cargo-emit/latest/cargo_emit/macro.rustc_env.html
[`rustc_flags!($flags)`]: https://docs.rs/cargo-emit/latest/cargo_emit/macro.rustc_flags.html
[`rustc_link_arg!($arg)`]: https://docs.rs/cargo-emit/latest/cargo_emit/macro.rustc_link_arg.html
[`rustc_link_arg_bin!($bin => $arg)`]: https://docs.rs/cargo-emit/latest/cargo_emit/macro.rustc_link_arg_bin.html
[`rustc_link_arg_bins!($arg)`]: https://docs.rs/cargo-emit/latest/cargo_emit/macro.rustc_link_arg_bins.html
[`rustc_link_lib!($name => $kind)`]: https://docs.rs/cargo-emit/latest/cargo_emit/macro.rustc_link_lib.html
[`rustc_link_search!($path => $kind)`]: https://docs.rs/cargo-emit/latest/cargo_emit/macro.rustc_link_search.html
[`warning!($message)`]: https://docs.rs/cargo-emit/latest/cargo_emit/macro.warning.html
## License
This project is released under either:
- [MIT License](https://github.com/nvzqz/cargo-emit/blob/master/LICENSE-MIT)
- [Apache License (Version 2.0)](https://github.com/nvzqz/cargo-emit/blob/master/LICENSE-APACHE)
cargo-emit-0.2.1/src/lib.rs 0000644 0000000 0000000 00000010420 00726746425 0013603 0 ustar 0000000 0000000 //!
//!
//! Talk to Cargo easily at build time, brought to you by [Nikolai Vazquez].
//!
//! This library provides:
//!
//! - Convenience macros for communicating with Cargo during the [`build.rs`]
//! phrase. Cargo listens to certain [build script outputs] that dictate how
//! it should behave.
//!
//! - An accessible location for seeing what script build outputs are available
//! to emit.
//!
//! - Protection against typos that can be made when printing these formatted
//! outputs directly yourself. Mistyping macro names will result in a compile
//! failure.
//!
//! # Usage
//!
//! This crate is available [on crates.io][crate] and can be used by adding the
//! following to your project's [`Cargo.toml`]:
//!
//! ```toml
//! [build-dependencies]
//! cargo-emit = "0.1"
//! ```
//!
//! and something like this to your [`build.rs`]:
//!
//! ```
//! # let should_warn = true;
//! if should_warn {
//! cargo_emit::warning!("(C-3PO voice) We're doomed");
//! }
//! ```
//!
//! **Note:** This library is meant to be used with [Rust 2018 edition][2018],
//! so that `cargo_emit::` can be used to prefix macro calls.
//!
//! # Compatibility
//!
//! This crate is compatible with Rust 1.31+ in order to use the
//! `$crate::macro!` feature introduced in [Rust 2018][2018].
//!
//! # Examples
//!
//! Very thorough examples are provided in the docs for
//! [each individual macro](#macros).
//!
//! # Donate
//!
//! This project is made freely available (as in free beer), but unfortunately
//! not all beer is free! So, if you would like to buy me a beer (or coffee or
//! *more*), then consider supporting my work that's benefited your project
//! and thousands of others.
//!
//!
//!
//!
//!
//!
//!
//!
//! [Nikolai Vazquez]: https://twitter.com/NikolaiVazquez
//! [build script outputs]: https://doc.rust-lang.org/cargo/reference/build-scripts.html#outputs-of-the-build-script
//! [2018]: https://blog.rust-lang.org/2018/12/06/Rust-1.31-and-rust-2018.html#rust-2018
//! [crate]: https://crates.io/crates/cargo-emit
//! [`Cargo.toml`]: https://doc.rust-lang.org/cargo/reference/manifest.html
//! [`build.rs`]: https://doc.rust-lang.org/cargo/reference/build-scripts.html
#![doc(html_root_url = "https://docs.rs/cargo-emit/0.1.1")]
#![doc(
html_logo_url = "https://raw.githubusercontent.com/nvzqz/cargo-emit/assets/logo.svg?sanitize=true"
)]
#![deny(missing_docs)]
/// `cargo:$key=$value`
mod pair;
/// `cargo:rerun-if-changed=$path`
mod rerun_if_changed;
/// `cargo:rerun-if-env-changed=$key`
mod rerun_if_env_changed;
/// `cargo:rustc-cdylib-link-arg=$flag`
mod rustc_cdylib_link_arg;
/// `cargo:rustc-cfg=$feature`
mod rustc_cfg;
/// `cargo:rustc-env=$key=$value`
mod rustc_env;
/// `cargo:rustc-flags=$flags`
mod rustc_flags;
/// `cargo:rustc-link-arg=$arg`
mod rustc_link_arg;
/// `cargo:rustc-link-arg-bin=$bin=$arg`
mod rustc_link_arg_bin;
/// `cargo:rustc-link-arg-bins=$arg`
mod rustc_link_arg_bins;
/// `cargo:rustc-link-lib=$kind=$name`
mod rustc_link_lib;
/// `cargo:rustc-link-search=$kind=$path`
mod rustc_link_search;
/// `cargo:warning=$message`
mod warning;
#[cfg(test)]
fn capture_output(f: F) -> String
where
F: FnOnce(&mut String),
{
let mut output = String::new();
f(&mut output);
output
}
cargo-emit-0.2.1/src/pair.rs 0000644 0000000 0000000 00000007422 00726746425 0014000 0 ustar 0000000 0000000 /// Emits a `$key`/`$value` pair to Cargo based on [build script outputs].
///
/// This is equivalent to:
///
/// ```
/// println!("cargo:$key=$value");
/// ```
///
/// This is the base macro upon which the other macros are built.
///
/// # Examples
///
/// This can be used to emit arbitrary user-defined metadata.
///
/// ```
/// cargo_emit::pair!("root", "/path/to/root");
/// ```
///
/// or, in case you want it to emit to a custom stream:
///
/// ```
/// let mut stdout = std::io::stdout();
/// cargo_emit::pair!(
/// to: stdout,
/// "root", "/path/to/root"
/// );
/// ```
///
/// The `$key` and `$value` parameters get concatenated into a single formatting
/// string. Formatting runtime values can be done by passing subsequent values.
///
/// ```
/// let name = "foo";
/// cargo_emit::pair!("{lib}dir", "/path/to/{lib}", lib = name);
/// ```
///
/// [build script outputs]: https://doc.rust-lang.org/cargo/reference/build-scripts.html#outputs-of-the-build-script
#[macro_export]
macro_rules! pair {
(to: $stream:expr, $key:expr, $value:expr $(, $($args:tt)*)?) => {{
#[allow(unused_imports)]
use std::{fmt::Write as _, io::Write as _};
#[allow(clippy::explicit_write)]
writeln!($stream, concat!("cargo:", $key, "=", $value) $(, $($args)*)?).unwrap()
}};
($key:expr, $value:expr $(, $($args:tt)*)?) => {
$crate::pair!(to: std::io::stdout(), $key, $value $(, $($args)*)?);
};
}
#[cfg(test)]
mod tests {
#[test]
fn single_literal() {
insta::assert_display_snapshot!(
crate::capture_output(|output| {
crate::pair!(
to: output,
"KEY", "VALUE"
);
}),
@"cargo:KEY=VALUE\n"
);
}
#[test]
fn single_with_key_formatted_by_index() {
insta::assert_display_snapshot!(
crate::capture_output(|output| {
crate::pair!(
to: output,
"{}", "VALUE", "KEY"
);
}),
@"cargo:KEY=VALUE\n"
);
}
#[test]
fn single_with_key_formatted_by_name() {
insta::assert_display_snapshot!(
crate::capture_output(|output| {
crate::pair!(
to: output,
"{key}", "VALUE", key = "KEY"
);
}),
@"cargo:KEY=VALUE\n"
);
}
#[test]
fn single_with_value_formatted_by_index() {
insta::assert_display_snapshot!(
crate::capture_output(|output| {
crate::pair!(
to: output,
"KEY", "{}", "VALUE"
);
}),
@"cargo:KEY=VALUE\n"
);
}
#[test]
fn single_with_value_formatted_by_name() {
insta::assert_display_snapshot!(
crate::capture_output(|output| {
crate::pair!(
to: output,
"KEY", "{value}", value = "VALUE"
);
}),
@"cargo:KEY=VALUE\n"
);
}
#[test]
fn single_with_key_and_value_formatted_by_index() {
insta::assert_display_snapshot!(
crate::capture_output(|output| {
crate::pair!(
to: output,
"{}", "{}", "KEY", "VALUE"
);
}),
@"cargo:KEY=VALUE\n"
);
}
#[test]
fn single_with_key_and_value_formatted_by_name() {
insta::assert_display_snapshot!(
crate::capture_output(|output| {
crate::pair!(
to: output,
"{key}", "{value}", key = "KEY", value = "VALUE"
);
}),
@"cargo:KEY=VALUE\n"
);
}
}
cargo-emit-0.2.1/src/rerun_if_changed.rs 0000644 0000000 0000000 00000011455 00726746425 0016330 0 ustar 0000000 0000000 /// Tells Cargo to run again if the file or directory at `$path` changes.
///
/// This is equivalent to:
///
/// ```
/// println!("cargo:rerun-if-changed=$path");
/// ```
///
/// `$path` is a path to a file or directory which indicates that the build
/// script should be re-run if it changes (detected by a more-recent
/// last-modified timestamp on the file). Normally build scripts are re-run if
/// any file inside the crate root changes, but this can be used to scope
/// changes to just a small set of files. (If this path points to a directory
/// the entire directory will not be traversed for changes -- only changes to
/// the timestamp of the directory itself (which corresponds to some types of
/// changes within the directory, depending on platform) will trigger a rebuild.
/// To request a re-run on any changes within an entire directory, print a line
/// for the directory and another line for everything inside it, recursively.)
/// Note that if the build script itself (or one of its dependencies) changes,
/// then it's rebuilt and rerun unconditionally, so
/// `rerun_if_changed!("build.rs")` is almost always redundant (unless you want
/// to ignore changes in all other files except for `build.rs`).
///
/// # Examples
///
/// This is useful for tracking build-dependent files that Cargo does not
/// already know.
///
/// ```
/// cargo_emit::rerun_if_changed!(
/// "/path/to/resource1",
/// "/path/to/resource2",
/// );
/// ```
///
/// or, in case you want it to emit to a custom stream:
///
/// ```
/// let mut stdout = std::io::stdout();
/// // ..
/// cargo_emit::rerun_if_changed!(
/// to: stdout,
/// "/path/to/resource1",
/// "/path/to/resource2",
/// );
/// ```
#[macro_export]
macro_rules! rerun_if_changed {
(to: $stream:expr, $($path:expr),+ $(,)?) => {
$($crate::pair!(to: $stream, "rerun-if-changed", "{}", $path);)+
};
($($path:expr),+ $(,)?) => {
$crate::rerun_if_changed!(to: std::io::stdout(), $($path),+);
};
}
#[cfg(test)]
mod tests {
use std::path::PathBuf;
#[test]
fn single_literal() {
insta::assert_display_snapshot!(
crate::capture_output(|output| {
crate::rerun_if_changed!(
to: output,
"/path/to/resource"
);
}),
@"cargo:rerun-if-changed=/path/to/resource\n"
);
}
#[test]
fn single_expression() {
insta::assert_display_snapshot!(
crate::capture_output(|output| {
crate::rerun_if_changed!(
to: output,
PathBuf::from("/path/to/resource").display()
);
}),
@"cargo:rerun-if-changed=/path/to/resource\n"
);
}
#[test]
fn multiple_literals() {
insta::assert_display_snapshot!(
crate::capture_output(|output| {
crate::rerun_if_changed!(
to: output,
"/path/to/resource1",
"/path/to/resource2",
"/path/to/resource3",
"/path/to/resource4",
);
}),
@"cargo:rerun-if-changed=/path/to/resource1\n\
cargo:rerun-if-changed=/path/to/resource2\n\
cargo:rerun-if-changed=/path/to/resource3\n\
cargo:rerun-if-changed=/path/to/resource4\n"
);
}
#[test]
fn multiple_expressions() {
insta::assert_display_snapshot!(
crate::capture_output(|output| {
crate::rerun_if_changed!(
to: output,
PathBuf::from("/path/to/resource1").display(),
PathBuf::from("/path/to/resource2").display(),
PathBuf::from("/path/to/resource3").display(),
PathBuf::from("/path/to/resource4").display(),
);
}),
@"cargo:rerun-if-changed=/path/to/resource1\n\
cargo:rerun-if-changed=/path/to/resource2\n\
cargo:rerun-if-changed=/path/to/resource3\n\
cargo:rerun-if-changed=/path/to/resource4\n"
);
}
#[test]
fn multiple_mixed() {
insta::assert_display_snapshot!(
crate::capture_output(|output| {
crate::rerun_if_changed!(
to: output,
"/path/to/resource1",
PathBuf::from("/path/to/resource2").display(),
"/path/to/resource3",
PathBuf::from("/path/to/resource4").display(),
);
}),
@"cargo:rerun-if-changed=/path/to/resource1\n\
cargo:rerun-if-changed=/path/to/resource2\n\
cargo:rerun-if-changed=/path/to/resource3\n\
cargo:rerun-if-changed=/path/to/resource4\n"
);
}
}
cargo-emit-0.2.1/src/rerun_if_env_changed.rs 0000644 0000000 0000000 00000004725 00726746425 0017202 0 ustar 0000000 0000000 /// Tells Cargo to run again if the file or directory at `$key` changes.
///
/// This is equivalent to:
///
/// ```
/// println!("cargo:rerun-if-env-changed=$key");
/// ```
///
/// `$key` is the name of an environment variable which indicates that if the
/// environment variable's value changes the build script should be rerun. This
/// basically behaves the same as [`rerun_if_changed!`] except that it works
/// with environment variables instead. Note that the environment variables here
/// are intended for global environment variables like `CC` and such, it's not
/// necessary to use this for env vars like `TARGET` that Cargo sets. Also note
/// that if [`rerun_if_env_changed!`] is used then Cargo will only rerun the
/// build script if those environment variables change or if files printed out
/// by [`rerun_if_changed!`] change.
///
/// # Examples
///
/// This is useful for tracking build-dependent files that Cargo does not
/// already know.
///
/// ```
/// cargo_emit::rerun_if_env_changed!("MY_DEPENDENCY", "PATH");
/// ```
///
/// or, in case you want it to emit to a custom stream:
///
/// ```
/// let mut stdout = std::io::stdout();
/// cargo_emit::rerun_if_env_changed!(
/// to: stdout,
/// "MY_DEPENDENCY", "PATH"
/// );
/// ```
///
/// [`rerun_if_changed!`]: macro.rerun_if_changed.html
/// [`rerun_if_env_changed!`]: macro.rerun_if_env_changed.html
#[macro_export]
macro_rules! rerun_if_env_changed {
(to: $stream:expr, $($key:expr),+ $(,)?) => {
$($crate::pair!(to: $stream, "rerun-if-env-changed", "{}", $key);)+
};
($($key:expr),+ $(,)?) => {
$crate::rerun_if_env_changed!(to: std::io::stdout(), "{}", $($key),+);
};
}
#[cfg(test)]
mod tests {
#[test]
fn single() {
insta::assert_display_snapshot!(
crate::capture_output(|output| {
crate::rerun_if_env_changed!(
to: output,
"KEY"
);
}),
@"cargo:rerun-if-env-changed=KEY\n"
);
}
#[test]
fn multiple() {
insta::assert_display_snapshot!(
crate::capture_output(|output| {
crate::rerun_if_env_changed!(
to: output,
"KEY1",
"KEY2",
"KEY3",
);
}),
@"cargo:rerun-if-env-changed=KEY1\n\
cargo:rerun-if-env-changed=KEY2\n\
cargo:rerun-if-env-changed=KEY3\n"
);
}
}
cargo-emit-0.2.1/src/rustc_cdylib_link_arg.rs 0000644 0000000 0000000 00000003254 00726746425 0017400 0 ustar 0000000 0000000 /// Tells Cargo to pass `-C link-arg=$flag` to the compiler.
///
/// This is equivalent to:
///
/// ```
/// println!("cargo:rustc-cdylib-link-arg=$flag");
/// ```
///
/// # Examples
///
/// Runtime arguments can be passed directly.
///
/// ```
/// let flag1 = // ...
/// # "";
/// let flag2 = // ...
/// # "";
/// cargo_emit::rustc_cdylib_link_arg!(flag1, flag2);
/// ```
///
/// or, in case you want it to emit to a custom stream:
///
/// ```
/// let flag1 = // ...
/// # "";
/// let flag2 = // ...
/// # "";
/// let mut stdout = std::io::stdout();
/// cargo_emit::rustc_cdylib_link_arg!(
/// to: stdout,
/// flag1, flag2
/// );
/// ```
#[macro_export]
macro_rules! rustc_cdylib_link_arg {
(to: $stream:expr, $($flag:expr),+ $(,)?) => {
$($crate::pair!(to: $stream, "rustc-cdylib-link-arg", "{}", $flag);)+
};
($($flag:expr),+ $(,)?) => {
$crate::rustc_cdylib_link_arg!(to: std::io::stdout(), $($flag),+);
};
}
#[cfg(test)]
mod tests {
#[test]
fn single() {
insta::assert_display_snapshot!(
crate::capture_output(|output| {
crate::rustc_cdylib_link_arg!(
to: output,
"ARG"
);
}),
@"cargo:rustc-cdylib-link-arg=ARG\n"
);
}
#[test]
fn multiple() {
insta::assert_display_snapshot!(
crate::capture_output(|output| {
crate::rustc_cdylib_link_arg!(
to: output,
"ARG1",
"ARG2",
);
}),
@"cargo:rustc-cdylib-link-arg=ARG1\n\
cargo:rustc-cdylib-link-arg=ARG2\n"
);
}
}
cargo-emit-0.2.1/src/rustc_cfg.rs 0000644 0000000 0000000 00000003472 00726746425 0015025 0 ustar 0000000 0000000 /// Tells Cargo to enable a `$feature`.
///
/// This is equivalent to:
///
/// ```
/// println!("cargo:rustc-cfg=$feature");
/// ```
///
/// # Examples
///
/// Useful for conditionally enabling certain code to run.
///
/// ```
/// # struct Cargo;
/// # impl Cargo {
/// # fn can_bench(&self) -> bool { true }
/// # }
/// # let cargo = Cargo;
/// if cargo.can_bench() {
/// cargo_emit::rustc_cfg!("bench");
/// }
/// ```
///
/// or, in case you want it to emit to a custom stream:
///
/// ```
/// # struct Cargo;
/// # impl Cargo {
/// # fn can_bench(&self) -> bool { true }
/// # }
/// # let cargo = Cargo;
/// let mut stdout = std::io::stdout();
/// if cargo.can_bench() {
/// cargo_emit::rustc_cfg!(
/// to: stdout,
/// "bench"
/// );
/// }
/// ```
///
/// Then outside of `build.rs`:
///
/// ```
/// #[cfg(bench)]
/// mod benches {
/// // ...
/// }
/// ```
#[macro_export]
macro_rules! rustc_cfg {
(to: $stream:expr, $feature:expr $(, $($args:tt)*)?) => {
$crate::pair!(to: $stream, "rustc-cfg", $feature $(, $($args)+)?);
};
($feature:expr $(, $($args:tt)*)?) => {
$crate::rustc_cfg!(to: std::io::stdout(), $feature $(, $($args)+)?);
};
}
#[cfg(test)]
mod tests {
#[test]
fn literal() {
insta::assert_display_snapshot!(
crate::capture_output(|output| {
crate::rustc_cfg!(
to: output,
"CFG"
);
}),
@"cargo:rustc-cfg=CFG\n"
);
}
#[test]
fn formatted() {
insta::assert_display_snapshot!(
crate::capture_output(|output| {
crate::rustc_cfg!(
to: output,
"{}", "CFG"
);
}),
@"cargo:rustc-cfg=CFG\n"
);
}
}
cargo-emit-0.2.1/src/rustc_env.rs 0000644 0000000 0000000 00000007233 00726746425 0015055 0 ustar 0000000 0000000 /// Tells Cargo to assign `$key` for the environment variable for `$key`.
///
/// This is equivalent to:
///
/// ```
/// println!("cargo:rustc-env=$key=$value");
/// ```
///
/// # Examples
///
/// Useful for injecting environment variables during the build.
///
/// The `$key` and `$value` parameters get concatenated into a single formatting
/// string. Formatting runtime values can be done by passing subsequent values.
///
/// ```
/// let git_rev_hash = //
/// # "0000111122223333444455556666777788889999";
/// cargo_emit::rustc_env!("MY_HASH", "{}", git_rev_hash);
/// ```
///
/// or, in case you want it to emit to a custom stream:
///
/// ```
/// let mut stdout = std::io::stdout();
/// let git_rev_hash = // ...
/// # "0000111122223333444455556666777788889999";
/// cargo_emit::rustc_env!(
/// to: stdout,
/// "MY_HASH", "{}", git_rev_hash
/// );
/// ```
#[macro_export]
macro_rules! rustc_env {
(to: $stream:expr, $key:expr, $value:expr $(, $($args:tt)*)?) => {
$crate::pair!(to: $stream, "rustc-env", concat!($key, "=", $value) $(, $($args)+)?);
};
($key:expr, $value:expr $(, $($args:tt)*)?) => {
$crate::rustc_env!(to: std::io::stdout(), $key, $value $(, $($args)+)?);
};
}
#[cfg(test)]
mod tests {
#[test]
fn single_literal() {
insta::assert_display_snapshot!(
crate::capture_output(|output| {
crate::rustc_env!(
to: output,
"KEY", "VALUE"
);
}),
@"cargo:rustc-env=KEY=VALUE\n"
);
}
#[test]
fn single_with_key_formatted_by_index() {
insta::assert_display_snapshot!(
crate::capture_output(|output| {
crate::rustc_env!(
to: output,
"{}", "VALUE", "KEY"
);
}),
@"cargo:rustc-env=KEY=VALUE\n"
);
}
#[test]
fn single_with_key_formatted_by_name() {
insta::assert_display_snapshot!(
crate::capture_output(|output| {
crate::rustc_env!(
to: output,
"{key}", "VALUE", key = "KEY"
);
}),
@"cargo:rustc-env=KEY=VALUE\n"
);
}
#[test]
fn single_with_value_formatted_by_index() {
insta::assert_display_snapshot!(
crate::capture_output(|output| {
crate::rustc_env!(
to: output,
"KEY", "{}", "VALUE"
);
}),
@"cargo:rustc-env=KEY=VALUE\n"
);
}
#[test]
fn single_with_value_formatted_by_name() {
insta::assert_display_snapshot!(
crate::capture_output(|output| {
crate::rustc_env!(
to: output,
"KEY", "{value}", value = "VALUE"
);
}),
@"cargo:rustc-env=KEY=VALUE\n"
);
}
#[test]
fn single_with_key_and_value_formatted_by_index() {
insta::assert_display_snapshot!(
crate::capture_output(|output| {
crate::rustc_env!(
to: output,
"{}", "{}", "KEY", "VALUE"
);
}),
@"cargo:rustc-env=KEY=VALUE\n"
);
}
#[test]
fn single_with_key_and_value_formatted_by_name() {
insta::assert_display_snapshot!(
crate::capture_output(|output| {
crate::rustc_env!(
to: output,
"{key}", "{value}", key = "KEY", value = "VALUE"
);
}),
@"cargo:rustc-env=KEY=VALUE\n"
);
}
}
cargo-emit-0.2.1/src/rustc_flags.rs 0000644 0000000 0000000 00000003134 00726746425 0015355 0 ustar 0000000 0000000 /// Tells Cargo to pass `$flags` to the compiler.
///
/// As of this writing, only `-l` and `-L` flags are supported.
///
/// This is equivalent to:
///
/// ```
/// println!("cargo:rustc-flags=$flags");
/// ```
///
/// # Examples
///
/// The `$flags` get concatenated into a single formatting
/// string. Formatting runtime values can be done by passing subsequent values.
///
/// ```
/// cargo_emit::rustc_flags!("-l pthread");
/// ```
///
/// or, in case you want it to emit to a custom stream:
///
/// ```
/// let mut stdout = std::io::stdout();
/// cargo_emit::rustc_flags!(
/// to: stdout,
/// "-l pthread"
/// );
/// ```
#[macro_export]
macro_rules! rustc_flags {
(to: $stream:expr, $($flags:expr),+ $(,)?) => {
$($crate::pair!(to: $stream, "rustc-flags", "{}", $flags);)+
};
($($flags:expr),+ $(,)?) => {
$crate::rustc_flags!(to: std::io::stdout(), $($flags),+);
};
}
#[cfg(test)]
mod tests {
#[test]
fn single() {
insta::assert_display_snapshot!(
crate::capture_output(|output| {
crate::rustc_flags!(
to: output,
"FLAG"
);
}),
@"cargo:rustc-flags=FLAG\n"
);
}
#[test]
fn multiple() {
insta::assert_display_snapshot!(
crate::capture_output(|output| {
crate::rustc_flags!(
to: output,
"FLAG1",
"FLAG2",
);
}),
@"cargo:rustc-flags=FLAG1\n\
cargo:rustc-flags=FLAG2\n"
);
}
}
cargo-emit-0.2.1/src/rustc_link_arg.rs 0000644 0000000 0000000 00000003460 00726746425 0016051 0 ustar 0000000 0000000 /// 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.
///
/// This is equivalent to:
///
/// ```
/// println!("cargo:rustc-link-arg=$flag");
/// ```
///
/// # Examples
///
/// ```
/// let flag1 = // ...
/// # "";
/// let flag2 = // ...
/// # "";
/// cargo_emit::rustc_link_arg!(
/// flag1, flag2
/// );
/// ```
///
/// or, in case you want it to emit to a custom stream:
///
/// ```
/// let flag1 = // ...
/// # "";
/// let flag2 = // ...
/// # "";
/// let mut stdout = std::io::stdout();
/// cargo_emit::rustc_link_arg!(
/// to: stdout,
/// flag1, flag2
/// );
/// ```
#[macro_export]
macro_rules! rustc_link_arg {
(to: $stream:expr, $($flag:expr),+ $(,)?) => {
$($crate::pair!(to: $stream, "rustc-link-arg", "{}", $flag);)+
};
($($flag:expr),+ $(,)?) => {
$crate::rustc_link_arg!(to: std::io::stdout(), $($flag),+);
};
}
#[cfg(test)]
mod tests {
#[test]
fn single() {
insta::assert_display_snapshot!(
crate::capture_output(|output| {
crate::rustc_link_arg!(
to: output,
"ARG"
);
}),
@"cargo:rustc-link-arg=ARG
"
);
}
#[test]
fn multiple() {
insta::assert_display_snapshot!(
crate::capture_output(|output| {
crate::rustc_link_arg!(
to: output,
"ARG1",
"ARG2"
);
}),
@r###"
cargo:rustc-link-arg=ARG1
cargo:rustc-link-arg=ARG2
"###
);
}
}
cargo-emit-0.2.1/src/rustc_link_arg_bin.rs 0000644 0000000 0000000 00000004070 00726746425 0016677 0 ustar 0000000 0000000 /// 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.
///
/// This is equivalent to:
///
/// ```
/// println!("cargo:rustc-link-arg-bin=$bin=$flag");
/// ```
///
/// # Examples
///
/// ```
/// cargo_emit::rustc_link_arg_bin!(
/// "hello_world" => "-Wall"
/// );
/// ```
///
/// or, in case you want it to emit to a custom stream:
///
/// ```
/// let mut stdout = std::io::stdout();
/// cargo_emit::rustc_link_arg_bin!(
/// to: stdout,
/// "hello_world" => "-Wall"
/// );
/// ```
#[macro_export]
macro_rules! rustc_link_arg_bin {
(to: $stream:expr, $bin:expr => $flags:expr $(,)?) => {
$crate::pair!(to: $stream, "rustc-link-arg-bin", "{}={}", $bin, $flags);
};
(to: $stream:expr, $($bin:expr=> $flags:expr),+ $(,)?) => { {
$($crate::rustc_link_arg_bin!(to: $stream, $bin => $flags);)+
} };
($bin:expr => $flags:expr $(,)?) => {
$crate::rustc_link_arg_bin!(to: std::io::stdout(), $bin => $flags);
};
($($bin:expr=> $flags:expr),+ $(,)?) => { {
$crate::rustc_link_arg_bin!(to: std::io::stdout(), $($bin=> $flags),+);
} };
}
#[cfg(test)]
mod tests {
#[test]
fn single() {
insta::assert_display_snapshot!(
crate::capture_output(|output| {
crate::rustc_link_arg_bin!(
to: output,
"BIN" => "FLAGS"
);
}),
@"cargo:rustc-link-arg-bin=BIN=FLAGS
"
);
}
#[test]
fn multiple() {
insta::assert_display_snapshot!(
crate::capture_output(|output| {
crate::rustc_link_arg_bin!(
to: output,
"BIN1" => "FLAGS1",
"BIN2" => "FLAGS2",
);
}),
@r###"
cargo:rustc-link-arg-bin=BIN1=FLAGS1
cargo:rustc-link-arg-bin=BIN2=FLAGS2
"###
);
}
}
cargo-emit-0.2.1/src/rustc_link_arg_bins.rs 0000644 0000000 0000000 00000003451 00726746425 0017064 0 ustar 0000000 0000000 /// 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.
///
/// This is equivalent to:
///
/// ```
/// println!("cargo:rustc-link-arg-bins=$flag");
/// ```
///
/// # Examples
///
/// ```
/// let flag1 = // ...
/// # "";
/// let flag2 = // ...
/// # "";
/// cargo_emit::rustc_link_arg_bins!(
/// flag1, flag2
/// );
/// ```
///
/// or, in case you want it to emit to a custom stream:
///
/// ```
/// let flag1 = // ...
/// # "";
/// let flag2 = // ...
/// # "";
/// let mut stdout = std::io::stdout();
/// cargo_emit::rustc_link_arg_bins!(
/// to: stdout,
/// flag1, flag2
/// );
/// ```
#[macro_export]
macro_rules! rustc_link_arg_bins {
(to: $stream:expr, $($flag:expr),+ $(,)?) => {
$($crate::pair!(to: $stream, "rustc-link-arg-bins", "{}", $flag);)+
};
($($flag:expr),+ $(,)?) => {
$crate::rustc_link_arg_bins!(to: std::io::stdout(), $($flag),+);
};
}
#[cfg(test)]
mod tests {
#[test]
fn single() {
insta::assert_display_snapshot!(
crate::capture_output(|output| {
crate::rustc_link_arg_bins!(
to: output,
"ARG"
);
}),
@"cargo:rustc-link-arg-bins=ARG
"
);
}
#[test]
fn multiple() {
insta::assert_display_snapshot!(
crate::capture_output(|output| {
crate::rustc_link_arg_bins!(
to: output,
"ARG1",
"ARG2"
);
}),
@r###"
cargo:rustc-link-arg-bins=ARG1
cargo:rustc-link-arg-bins=ARG2
"###
);
}
}
cargo-emit-0.2.1/src/rustc_link_lib.rs 0000644 0000000 0000000 00000006715 00726746425 0016054 0 ustar 0000000 0000000 /// Tells Cargo to pass `$lib` to the compiler as a `-l` flag.
///
/// This is equivalent to:
///
/// ```
/// println!("cargo:rustc-link-lib=[$kind=]$name");
/// ```
///
/// # Examples
///
/// Useful for telling the linker what libraries should be linked.
///
/// ```
/// cargo_emit::rustc_link_lib!(
/// "ssl", // same as `=> "dylib"`
/// "ruby" => "static",
/// "CoreFoundation" => "framework",
/// );
/// ```
///
/// or, in case you want it to emit to a custom stream:
///
/// ```
/// let mut stdout = std::io::stdout();
/// cargo_emit::rustc_link_lib!(
/// to: stdout,
/// "ssl", // same as `=> "dylib"`
/// "ruby" => "static",
/// "CoreFoundation" => "framework",
/// );
/// ```
#[macro_export]
macro_rules! rustc_link_lib {
(to: $stream:expr, $name:expr $(,)?) => {
$crate::pair!(to: $stream, "rustc-link-lib", "{}", $name);
};
(to: $stream:expr, $name:expr => $kind:expr $(,)?) => {
$crate::pair!(to: $stream, "rustc-link-lib", "{}={}", $kind, $name);
};
(to: $stream:expr, $($name:expr $(=> $kind:expr)?),+ $(,)?) => { {
$($crate::rustc_link_lib!(to: $stream, $name $(=> $kind)?);)+
} };
($name:expr $(,)?) => {
$crate::rustc_link_lib!(to: std::io::stdout(), $name);
};
($name:expr => $kind:expr $(,)?) => {
$crate::rustc_link_lib!(to: std::io::stdout(), $name => $kind);
};
($($name:expr $(=> $kind:expr)?),+ $(,)?) => { {
$crate::rustc_link_lib!(to: std::io::stdout(), $($name $(=> $kind)?),+);
} };
}
#[cfg(test)]
mod tests {
#[test]
fn single_name_literal() {
insta::assert_display_snapshot!(
crate::capture_output(|output| {
crate::rustc_link_lib!(
to: output,
"NAME"
);
}),
@"cargo:rustc-link-lib=NAME\n"
);
}
#[test]
fn single_name_expression() {
insta::assert_display_snapshot!(
crate::capture_output(|output| {
let name = "NAME";
crate::rustc_link_lib!(
to: output,
name
);
}),
@"cargo:rustc-link-lib=NAME\n"
);
}
#[test]
fn single_name_literal_with_kind() {
insta::assert_display_snapshot!(
crate::capture_output(|output| {
crate::rustc_link_lib!(
to: output,
"NAME" => "KIND"
);
}),
@"cargo:rustc-link-lib=KIND=NAME\n"
);
}
#[test]
fn single_name_expression_with_kind() {
insta::assert_display_snapshot!(
crate::capture_output(|output| {
let name = "NAME";
let kind = "KIND";
crate::rustc_link_lib!(
to: output,
name => kind
);
}),
@"cargo:rustc-link-lib=KIND=NAME\n"
);
}
#[test]
fn multiple_name_expression_with_kind() {
insta::assert_display_snapshot!(
crate::capture_output(|output| {
let name2 = "NAME2";
let kind2 = "KIND2";
crate::rustc_link_lib!(
to: output,
"NAME1" => "KIND1",
name2 => kind2,
);
}),
@"cargo:rustc-link-lib=KIND1=NAME1\n\
cargo:rustc-link-lib=KIND2=NAME2\n"
);
}
}
cargo-emit-0.2.1/src/rustc_link_search.rs 0000644 0000000 0000000 00000006745 00726746425 0016556 0 ustar 0000000 0000000 /// Tells Cargo to pass `$path` to the compiler as a `-L` flag.
///
/// This is equivalent to:
///
/// ```
/// println!("cargo:rustc-link-search=[$kind=]$path");
/// ```
///
/// # Examples
///
/// Useful for telling the linker where a path can be found.
///
/// ```
/// cargo_emit::rustc_link_search!(
/// "path/to/ssl/lib/", // same as `=> "all"`
/// "path/to/ruby/lib/" => "native",
/// );
/// ```
///
/// or, in case you want it to emit to a custom stream:
///
/// ```
/// let mut stdout = std::io::stdout();
/// cargo_emit::rustc_link_search!(
/// to: stdout,
/// "path/to/ssl/lib/", // same as `=> "all"`
/// "path/to/ruby/lib/" => "native",
/// );
/// ```
#[macro_export]
macro_rules! rustc_link_search {
(to: $stream:expr, $path:expr $(,)?) => {
$crate::pair!(to: $stream, "rustc-link-search", "{}", $path);
};
(to: $stream:expr, $path:expr => $kind:expr $(,)?) => {
$crate::pair!(to: $stream, "rustc-link-search", "{}={}", $kind, $path);
};
(to: $stream:expr, $($path:expr $(=> $kind:expr)?),+ $(,)?) => { {
$($crate::rustc_link_search!(to: $stream, $path $(=> $kind)?);)+
} };
($path:expr $(,)?) => {
$crate::rustc_link_search!(to: std::io::stdout(), $path);
};
($path:expr => $kind:expr $(,)?) => {
$crate::rustc_link_search!(to: std::io::stdout(), $path => $kind);
};
($($path:expr $(=> $kind:expr)?),+ $(,)?) => { {
$crate::rustc_link_search!(to: std::io::stdout(), $($path $(=> $kind)?),+);
} };
}
#[cfg(test)]
mod tests {
#[test]
fn single_name_literal() {
insta::assert_display_snapshot!(
crate::capture_output(|output| {
crate::rustc_link_search!(
to: output,
"PATH"
);
}),
@"cargo:rustc-link-search=PATH\n"
);
}
#[test]
fn single_name_expression() {
insta::assert_display_snapshot!(
crate::capture_output(|output| {
let path = "PATH";
crate::rustc_link_search!(
to: output,
path
);
}),
@"cargo:rustc-link-search=PATH\n"
);
}
#[test]
fn single_name_literal_with_kind() {
insta::assert_display_snapshot!(
crate::capture_output(|output| {
crate::rustc_link_search!(
to: output,
"PATH" => "KIND"
);
}),
@"cargo:rustc-link-search=KIND=PATH\n"
);
}
#[test]
fn single_name_expression_with_kind() {
insta::assert_display_snapshot!(
crate::capture_output(|output| {
let path = "PATH";
let kind = "KIND";
crate::rustc_link_search!(
to: output,
path => kind
);
}),
@"cargo:rustc-link-search=KIND=PATH\n"
);
}
#[test]
fn multiple_name_expression_with_kind() {
insta::assert_display_snapshot!(
crate::capture_output(|output| {
let path2 = "PATH2";
let kind2 = "KIND2";
crate::rustc_link_search!(
to: output,
"PATH1" => "KIND1",
path2 => kind2,
);
}),
@"cargo:rustc-link-search=KIND1=PATH1\n\
cargo:rustc-link-search=KIND2=PATH2\n"
);
}
}
cargo-emit-0.2.1/src/warning.rs 0000644 0000000 0000000 00000004427 00726746425 0014514 0 ustar 0000000 0000000 /// Tells Cargo to print the formatted `warning` message.
///
/// This is equivalent to:
///
/// ```
/// println!("cargo:warning=$args");
/// ```
///
/// # Examples
///
/// Useful for showing when something expected (but not critical) has failed.
///
/// ```
/// match std::env::current_dir() {
/// Ok(dir) => { /* ... */ }
/// Err(error) => cargo_emit::warning!(
/// "Something suspicious is happening: {}",
/// error,
/// ),
/// }
/// ```
///
/// or, in case you want it to emit to a custom stream:
///
/// ```
/// let mut stdout = std::io::stdout();
/// match std::env::current_dir() {
/// Ok(dir) => { /* ... */ }
/// Err(error) => cargo_emit::warning!(
/// to: stdout,
/// "Something suspicious is happening: {}",
/// error,
/// ),
/// }
/// ```
///
/// Assuming you're building `my-crate`, you will see:
///
/// ```sh
/// $ cargo build
/// Compiling my-crate v0.1.0 (/path/to/my-crate)
/// warning: Something suspicious is happening: ...
/// ```
#[macro_export]
macro_rules! warning {
(to: $stream:expr, $($args:tt)+) => {
$crate::pair!(to: $stream, "warning", $($args)+)
};
($($args:tt)+) => {
$crate::warning!(to: std::io::stdout(), $($args)+)
};
}
#[cfg(test)]
mod tests {
#[test]
fn single_literal() {
insta::assert_display_snapshot!(
crate::capture_output(|output| {
crate::warning!(
to: output,
"WARNING"
);
}),
@"cargo:warning=WARNING\n"
);
}
#[test]
fn single_formatted_by_index() {
// Formatted argument:
insta::assert_display_snapshot!(
crate::capture_output(|output| {
crate::warning!(
to: output,
"{}", "WARNING"
);
}),
@"cargo:warning=WARNING\n"
);
}
#[test]
fn single_formatted_by_key() {
// Formatted argument:
insta::assert_display_snapshot!(
crate::capture_output(|output| {
crate::warning!(
to: output,
"{warning}", warning = "WARNING"
);
}),
@"cargo:warning=WARNING\n"
);
}
}