1
1
mirror of https://github.com/oxalica/nil.git synced 2024-11-25 18:41:40 +03:00

Merge code path and fix build with Nix 2.24

This commit is contained in:
oxalica 2024-08-05 14:24:30 -04:00
parent 4843496eb5
commit 01a62046a7

View File

@ -114,34 +114,33 @@ fn dump_builtin_infos() -> Vec<BuiltinInfo> {
.arg("__dump-language") .arg("__dump-language")
.json::<DumpLanguage>() .json::<DumpLanguage>()
{ {
return std::iter::empty() let builtins = match lang {
.chain( DumpLanguage::V2 { builtins } => builtins,
lang.builtins DumpLanguage::V1 {
.into_iter() mut builtins,
.map(|(name, builtin)| BuiltinInfo { constants,
name, } => {
kind: "Function".into(), builtins.extend(constants);
doc: builtin.doc, builtins
args: builtin.args, }
impure_only: false, };
experimental_feature: builtin.experimental_feature, return builtins
}), .into_iter()
) .map(|(name, builtin)| BuiltinInfo {
.chain(lang.constants.into_iter().map(|(name, constant)| { name,
let kind = if constant.type_.eq_ignore_ascii_case("set") { kind: if !builtin.args.is_empty() {
"Function"
} else if builtin.type_.is_some_and(|s| s.eq_ignore_ascii_case("set")) {
"Attrset" "Attrset"
} else { } else {
"Const" "Const"
};
BuiltinInfo {
name,
kind: kind.into(),
doc: constant.doc,
args: Vec::new(),
impure_only: constant.impure_only,
experimental_feature: None,
} }
})) .into(),
doc: builtin.doc,
args: builtin.args,
impure_only: builtin.impure_only,
experimental_feature: builtin.experimental_feature,
})
.collect(); .collect();
} }
@ -200,19 +199,18 @@ struct BuiltinInfo {
} }
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize)]
struct DumpLanguage { #[serde(untagged)]
builtins: DumpBuiltins, enum DumpLanguage {
constants: BTreeMap<String, DumpConstant>, // Nix < 2.24
} V1 {
builtins: DumpBuiltins,
#[derive(Debug, Deserialize)] constants: DumpBuiltins,
#[serde(rename_all = "kebab-case")] },
struct DumpConstant { // Nix >= 2.24
doc: String, V2 {
impure_only: bool, #[serde(flatten)]
// TODO builtins: BTreeMap<String, DumpBuiltin>,
#[serde(rename = "type")] },
type_: String,
} }
// Keep names sorted. // Keep names sorted.
@ -221,8 +219,13 @@ type DumpBuiltins = BTreeMap<String, DumpBuiltin>;
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize)]
#[serde(rename_all = "kebab-case")] #[serde(rename_all = "kebab-case")]
struct DumpBuiltin { struct DumpBuiltin {
#[serde(default)]
args: Vec<String>, args: Vec<String>,
doc: String, doc: String,
#[serde(default)] #[serde(default)]
experimental_feature: Option<String>, experimental_feature: Option<String>,
#[serde(default)]
impure_only: bool,
#[serde(rename = "type")]
type_: Option<String>,
} }