-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Write out
AIR_CRATE_NAMES
at build time
- Loading branch information
1 parent
6f93b9f
commit e26893f
Showing
7 changed files
with
90 additions
and
15 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
use std::env; | ||
use std::fs; | ||
use std::path::Path; | ||
|
||
extern crate cargo_metadata; | ||
|
||
fn main() { | ||
write_workspace_crate_names(); | ||
} | ||
|
||
/// Write out a constant array of air crate names as `AIR_CRATE_NAMES` at build time | ||
fn write_workspace_crate_names() { | ||
let dir = env::var_os("OUT_DIR").unwrap(); | ||
let path = Path::new(&dir).join("crates.rs"); | ||
|
||
// Equivalent to `cargo metadata --no-deps` | ||
let mut cmd = cargo_metadata::MetadataCommand::new(); | ||
cmd.no_deps(); | ||
let metadata = cmd.exec().unwrap(); | ||
|
||
let packages: Vec<String> = metadata | ||
.workspace_packages() | ||
.iter() | ||
.map(|package| package.name.clone()) | ||
.map(|package| String::from("\"") + package.as_str() + "\",") | ||
.collect(); | ||
|
||
let packages = packages.join(" "); | ||
|
||
let contents = format!("pub(crate) const AIR_CRATE_NAMES: &[&str] = &[{packages}];"); | ||
|
||
fs::write(&path, contents).unwrap(); | ||
println!("cargo::rerun-if-changed=build.rs"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Generates `AIR_CRATE_NAMES`, a const array of the crate names in the air workspace, | ||
// see `lsp/src/build.rs` | ||
include!(concat!(env!("OUT_DIR"), "/crates.rs")); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters