mirror of
https://github.com/nushell/nushell
synced 2025-01-12 13:19:01 +00:00
Extract build.rs
This commit is contained in:
parent
fe66b4c8ea
commit
87dbd3d5ac
15 changed files with 143 additions and 38 deletions
16
Cargo.lock
generated
16
Cargo.lock
generated
|
@ -1922,6 +1922,7 @@ dependencies = [
|
||||||
"nom 5.0.1",
|
"nom 5.0.1",
|
||||||
"nom-tracable",
|
"nom-tracable",
|
||||||
"nom_locate",
|
"nom_locate",
|
||||||
|
"nu-build",
|
||||||
"nu-errors",
|
"nu-errors",
|
||||||
"nu-parser",
|
"nu-parser",
|
||||||
"nu-protocol",
|
"nu-protocol",
|
||||||
|
@ -1970,6 +1971,16 @@ dependencies = [
|
||||||
"which",
|
"which",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "nu-build"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"lazy_static 1.4.0",
|
||||||
|
"serde 1.0.103",
|
||||||
|
"serde_json",
|
||||||
|
"toml 0.5.5",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "nu-errors"
|
name = "nu-errors"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
@ -1980,6 +1991,7 @@ dependencies = [
|
||||||
"language-reporting",
|
"language-reporting",
|
||||||
"nom 5.0.1",
|
"nom 5.0.1",
|
||||||
"nom_locate",
|
"nom_locate",
|
||||||
|
"nu-build",
|
||||||
"nu-source",
|
"nu-source",
|
||||||
"num-bigint",
|
"num-bigint",
|
||||||
"num-traits 0.2.10",
|
"num-traits 0.2.10",
|
||||||
|
@ -2006,6 +2018,7 @@ dependencies = [
|
||||||
"nom 5.0.1",
|
"nom 5.0.1",
|
||||||
"nom-tracable",
|
"nom-tracable",
|
||||||
"nom_locate",
|
"nom_locate",
|
||||||
|
"nu-build",
|
||||||
"nu-errors",
|
"nu-errors",
|
||||||
"nu-protocol",
|
"nu-protocol",
|
||||||
"nu-source",
|
"nu-source",
|
||||||
|
@ -2035,6 +2048,7 @@ dependencies = [
|
||||||
"nom 5.0.1",
|
"nom 5.0.1",
|
||||||
"nom-tracable",
|
"nom-tracable",
|
||||||
"nom_locate",
|
"nom_locate",
|
||||||
|
"nu-build",
|
||||||
"nu-errors",
|
"nu-errors",
|
||||||
"nu-source",
|
"nu-source",
|
||||||
"num-bigint",
|
"num-bigint",
|
||||||
|
@ -2058,6 +2072,7 @@ dependencies = [
|
||||||
"language-reporting",
|
"language-reporting",
|
||||||
"nom-tracable",
|
"nom-tracable",
|
||||||
"nom_locate",
|
"nom_locate",
|
||||||
|
"nu-build",
|
||||||
"pretty",
|
"pretty",
|
||||||
"serde 1.0.103",
|
"serde 1.0.103",
|
||||||
"termcolor",
|
"termcolor",
|
||||||
|
@ -2070,6 +2085,7 @@ dependencies = [
|
||||||
"ansi_term 0.12.1",
|
"ansi_term 0.12.1",
|
||||||
"crossterm",
|
"crossterm",
|
||||||
"nu",
|
"nu",
|
||||||
|
"nu-build",
|
||||||
"nu-protocol",
|
"nu-protocol",
|
||||||
"nu-source",
|
"nu-source",
|
||||||
"syntect",
|
"syntect",
|
||||||
|
|
|
@ -13,7 +13,7 @@ documentation = "https://book.nushell.sh"
|
||||||
|
|
||||||
[workspace]
|
[workspace]
|
||||||
|
|
||||||
members = ["crates/nu-errors", "crates/nu-source", "crates/nu-textview", "crates/nu-protocol", "crates/nu-parser"]
|
members = ["crates/nu-errors", "crates/nu-source", "crates/nu-textview", "crates/nu-protocol", "crates/nu-parser", "crates/nu-build"]
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
@ -126,6 +126,7 @@ pretty_assertions = "0.6.1"
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
toml = "0.5.5"
|
toml = "0.5.5"
|
||||||
serde = { version = "1.0.102", features = ["derive"] }
|
serde = { version = "1.0.102", features = ["derive"] }
|
||||||
|
nu-build = { version = "0.1.0", path = "./crates/nu-build" }
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
name = "nu"
|
name = "nu"
|
||||||
|
|
38
build.rs
38
build.rs
|
@ -1,39 +1,3 @@
|
||||||
use serde::Deserialize;
|
|
||||||
use std::collections::HashMap;
|
|
||||||
use std::collections::HashSet;
|
|
||||||
use std::env;
|
|
||||||
use std::path::Path;
|
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
|
||||||
struct Feature {
|
|
||||||
#[allow(unused)]
|
|
||||||
description: String,
|
|
||||||
enabled: bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
let input = env::var("CARGO_MANIFEST_DIR").unwrap();
|
nu_build::build()
|
||||||
let all_on = env::var("NUSHELL_ENABLE_ALL_FLAGS").is_ok();
|
|
||||||
let flags: HashSet<String> = env::var("NUSHELL_ENABLE_FLAGS")
|
|
||||||
.map(|s| s.split(",").map(|s| s.to_string()).collect())
|
|
||||||
.unwrap_or_else(|_| HashSet::new());
|
|
||||||
|
|
||||||
if all_on && !flags.is_empty() {
|
|
||||||
println!(
|
|
||||||
"cargo:warning={}",
|
|
||||||
"Both NUSHELL_ENABLE_ALL_FLAGS and NUSHELL_ENABLE_FLAGS were set. You don't need both."
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
let path = Path::new(&input).join("features.toml");
|
|
||||||
|
|
||||||
let toml: HashMap<String, Feature> = toml::from_str(&std::fs::read_to_string(path)?)?;
|
|
||||||
|
|
||||||
for (key, value) in toml.iter() {
|
|
||||||
if value.enabled == true || all_on || flags.contains(key) {
|
|
||||||
println!("cargo:rustc-cfg={}", key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
13
crates/nu-build/Cargo.toml
Normal file
13
crates/nu-build/Cargo.toml
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
[package]
|
||||||
|
name = "nu-build"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["Yehuda Katz <wycats@gmail.com>"]
|
||||||
|
edition = "2018"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
serde = { version = "1.0.102", features = ["derive"] }
|
||||||
|
lazy_static = "1.2.0"
|
||||||
|
serde_json = "1.0.35"
|
||||||
|
toml = "0.5.5"
|
82
crates/nu-build/src/lib.rs
Normal file
82
crates/nu-build/src/lib.rs
Normal file
|
@ -0,0 +1,82 @@
|
||||||
|
use lazy_static::lazy_static;
|
||||||
|
use serde::Deserialize;
|
||||||
|
use std::collections::BTreeMap;
|
||||||
|
use std::collections::HashMap;
|
||||||
|
use std::collections::HashSet;
|
||||||
|
use std::env;
|
||||||
|
use std::path::{Path, PathBuf};
|
||||||
|
use std::sync::Mutex;
|
||||||
|
|
||||||
|
lazy_static! {
|
||||||
|
static ref WORKSPACES: Mutex<BTreeMap<String, &'static Path>> = Mutex::new(BTreeMap::new());
|
||||||
|
}
|
||||||
|
|
||||||
|
// got from https://github.com/mitsuhiko/insta/blob/b113499249584cb650150d2d01ed96ee66db6b30/src/runtime.rs#L67-L88
|
||||||
|
|
||||||
|
fn get_cargo_workspace(manifest_dir: &str) -> Option<&Path> {
|
||||||
|
let mut workspaces = WORKSPACES.lock().unwrap();
|
||||||
|
if let Some(rv) = workspaces.get(manifest_dir) {
|
||||||
|
Some(rv)
|
||||||
|
} else {
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
struct Manifest {
|
||||||
|
workspace_root: String,
|
||||||
|
}
|
||||||
|
let output = std::process::Command::new(env!("CARGO"))
|
||||||
|
.arg("metadata")
|
||||||
|
.arg("--format-version=1")
|
||||||
|
.current_dir(manifest_dir)
|
||||||
|
.output()
|
||||||
|
.unwrap();
|
||||||
|
let manifest: Manifest = serde_json::from_slice(&output.stdout).unwrap();
|
||||||
|
let path = Box::leak(Box::new(PathBuf::from(manifest.workspace_root)));
|
||||||
|
workspaces.insert(manifest_dir.to_string(), path.as_path());
|
||||||
|
workspaces.get(manifest_dir).map(|w| *w)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
struct Feature {
|
||||||
|
#[allow(unused)]
|
||||||
|
description: String,
|
||||||
|
enabled: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn build() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
let input = env::var("CARGO_MANIFEST_DIR").unwrap();
|
||||||
|
|
||||||
|
let all_on = env::var("NUSHELL_ENABLE_ALL_FLAGS").is_ok();
|
||||||
|
let flags: HashSet<String> = env::var("NUSHELL_ENABLE_FLAGS")
|
||||||
|
.map(|s| s.split(",").map(|s| s.to_string()).collect())
|
||||||
|
.unwrap_or_else(|_| HashSet::new());
|
||||||
|
|
||||||
|
if all_on && !flags.is_empty() {
|
||||||
|
println!(
|
||||||
|
"cargo:warning={}",
|
||||||
|
"Both NUSHELL_ENABLE_ALL_FLAGS and NUSHELL_ENABLE_FLAGS were set. You don't need both."
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
let workspace = match get_cargo_workspace(&input) {
|
||||||
|
// If the crate is being downloaded from crates.io, it won't have a workspace root, and that's ok
|
||||||
|
None => return Ok(()),
|
||||||
|
Some(workspace) => workspace,
|
||||||
|
};
|
||||||
|
|
||||||
|
let path = Path::new(&workspace).join("features.toml");
|
||||||
|
|
||||||
|
// If the crate is being downloaded from crates.io, it won't have a features.toml, and that's ok
|
||||||
|
if !path.exists() {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
|
let toml: HashMap<String, Feature> = toml::from_str(&std::fs::read_to_string(path)?)?;
|
||||||
|
|
||||||
|
for (key, value) in toml.iter() {
|
||||||
|
if value.enabled == true || all_on || flags.contains(key) {
|
||||||
|
println!("cargo:rustc-cfg={}", key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
|
@ -24,3 +24,6 @@ subprocess = "0.1.18"
|
||||||
serde_yaml = "0.8"
|
serde_yaml = "0.8"
|
||||||
toml = "0.5.5"
|
toml = "0.5.5"
|
||||||
serde_json = "1.0.41"
|
serde_json = "1.0.41"
|
||||||
|
|
||||||
|
[build-dependencies]
|
||||||
|
nu-build = { version = "0.1.0", path = "../nu-build" }
|
||||||
|
|
3
crates/nu-errors/build.rs
Normal file
3
crates/nu-errors/build.rs
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
nu_build::build()
|
||||||
|
}
|
|
@ -35,3 +35,6 @@ unicode-xid = "0.2.0"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
pretty_assertions = "0.6.1"
|
pretty_assertions = "0.6.1"
|
||||||
|
|
||||||
|
[build-dependencies]
|
||||||
|
nu-build = { version = "0.1.0", path = "../nu-build" }
|
||||||
|
|
3
crates/nu-parser/build.rs
Normal file
3
crates/nu-parser/build.rs
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
nu_build::build()
|
||||||
|
}
|
|
@ -33,3 +33,5 @@ serde_yaml = "0.8"
|
||||||
toml = "0.5.5"
|
toml = "0.5.5"
|
||||||
serde_json = "1.0.41"
|
serde_json = "1.0.41"
|
||||||
|
|
||||||
|
[build-dependencies]
|
||||||
|
nu-build = { version = "0.1.0", path = "../nu-build" }
|
||||||
|
|
3
crates/nu-protocol/build.rs
Normal file
3
crates/nu-protocol/build.rs
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
nu_build::build()
|
||||||
|
}
|
|
@ -18,3 +18,6 @@ nom-tracable = "0.4.1"
|
||||||
language-reporting = "0.4.0"
|
language-reporting = "0.4.0"
|
||||||
termcolor = "1.0.5"
|
termcolor = "1.0.5"
|
||||||
pretty = "0.5.2"
|
pretty = "0.5.2"
|
||||||
|
|
||||||
|
[build-dependencies]
|
||||||
|
nu-build = { version = "0.1.0", path = "../nu-build" }
|
||||||
|
|
3
crates/nu-source/build.rs
Normal file
3
crates/nu-source/build.rs
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
nu_build::build()
|
||||||
|
}
|
|
@ -20,3 +20,6 @@ nu = { path = "../.." }
|
||||||
nu-protocol = { path = "../nu-protocol" }
|
nu-protocol = { path = "../nu-protocol" }
|
||||||
nu-source = { path = "../nu-source" }
|
nu-source = { path = "../nu-source" }
|
||||||
url = "2.1.0"
|
url = "2.1.0"
|
||||||
|
|
||||||
|
[build-dependencies]
|
||||||
|
nu-build = { version = "0.1.0", path = "../nu-build" }
|
||||||
|
|
3
crates/nu-textview/build.rs
Normal file
3
crates/nu-textview/build.rs
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
nu_build::build()
|
||||||
|
}
|
Loading…
Reference in a new issue