Compare commits
5 commits
a6dcbb6eaf
...
25af468680
| Author | SHA1 | Date | |
|---|---|---|---|
| 25af468680 | |||
| 54511d9c23 | |||
| 70ce1b2b9e | |||
| 46baf3cd2e | |||
| 32cd7e0587 |
44 changed files with 738 additions and 1219 deletions
571
Cargo.lock
generated
571
Cargo.lock
generated
|
|
@ -11,152 +11,12 @@ dependencies = [
|
|||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anstyle"
|
||||
version = "1.0.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "940b3a0ca603d1eade50a4846a2afffd5ef57a9feac2c0e2ec2e14f9ead76000"
|
||||
|
||||
[[package]]
|
||||
name = "anyhow"
|
||||
version = "1.0.102"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7f202df86484c868dbad7eaa557ef785d5c66295e41b460ef922eca0723b842c"
|
||||
|
||||
[[package]]
|
||||
name = "aquamarine"
|
||||
version = "0.1.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a941c39708478e8eea39243b5983f1c42d2717b3620ee91f4a52115fd02ac43f"
|
||||
dependencies = [
|
||||
"itertools 0.9.0",
|
||||
"proc-macro-error",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 1.0.109",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "atty"
|
||||
version = "0.2.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
|
||||
dependencies = [
|
||||
"hermit-abi",
|
||||
"libc",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "autocfg"
|
||||
version = "1.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8"
|
||||
|
||||
[[package]]
|
||||
name = "autocxx"
|
||||
version = "0.30.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5ae6bbbec65d053b6fd803a4d63d21d0bd4a92f84f917847f216fec8bb8ae6ae"
|
||||
dependencies = [
|
||||
"aquamarine",
|
||||
"autocxx-macro",
|
||||
"cxx",
|
||||
"moveit",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "autocxx-bindgen"
|
||||
version = "0.73.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ecaaf84d9cf1a772409c0abdac7d2477a31fd890dbdf606d8f684dc60129aa94"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"cexpr",
|
||||
"clang-sys",
|
||||
"itertools 0.13.0",
|
||||
"log",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"regex",
|
||||
"rustc-hash",
|
||||
"shlex",
|
||||
"syn 2.0.117",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "autocxx-build"
|
||||
version = "0.30.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b16fa879472d80dc40ca826a59347772b3f15e69a7a74df41c4935942f62cf30"
|
||||
dependencies = [
|
||||
"autocxx-engine",
|
||||
"env_logger",
|
||||
"indexmap 1.9.3",
|
||||
"syn 2.0.117",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "autocxx-engine"
|
||||
version = "0.30.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9866b109f7091a3470a49906d35c7f34597828be8885508e9395d1194f8283ca"
|
||||
dependencies = [
|
||||
"aquamarine",
|
||||
"autocxx-bindgen",
|
||||
"autocxx-parser",
|
||||
"cc",
|
||||
"cxx-gen",
|
||||
"indexmap 1.9.3",
|
||||
"indoc",
|
||||
"itertools 0.10.5",
|
||||
"log",
|
||||
"miette",
|
||||
"once_cell",
|
||||
"prettyplease",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"regex",
|
||||
"regex_static",
|
||||
"rustversion",
|
||||
"serde_json",
|
||||
"syn 2.0.117",
|
||||
"tempfile",
|
||||
"thiserror",
|
||||
"version_check",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "autocxx-macro"
|
||||
version = "0.30.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c26712d744702e6fe61fdc618cc107a581a009ec8bfaffc67707d82501dbd907"
|
||||
dependencies = [
|
||||
"autocxx-parser",
|
||||
"proc-macro-error",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.117",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "autocxx-parser"
|
||||
version = "0.30.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6bcfc473ec409e612fb0e0c5c4a1b5b7611eca2bac71bc27b3cda98f15a25124"
|
||||
dependencies = [
|
||||
"indexmap 1.9.3",
|
||||
"itertools 0.10.5",
|
||||
"log",
|
||||
"once_cell",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"syn 2.0.117",
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bindgen"
|
||||
version = "0.72.1"
|
||||
|
|
@ -173,7 +33,7 @@ dependencies = [
|
|||
"regex",
|
||||
"rustc-hash",
|
||||
"shlex",
|
||||
"syn 2.0.117",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -218,43 +78,6 @@ dependencies = [
|
|||
"libloading",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap"
|
||||
version = "4.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b193af5b67834b676abd72466a96c1024e6a6ad978a1f484bd90b85c94041351"
|
||||
dependencies = [
|
||||
"clap_builder",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap_builder"
|
||||
version = "4.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "714a53001bf66416adb0e2ef5ac857140e7dc3a0c48fb28b2f10762fc4b5069f"
|
||||
dependencies = [
|
||||
"anstyle",
|
||||
"clap_lex",
|
||||
"strsim",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap_lex"
|
||||
version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c8d4a3bb8b1e0c1050499d1815f5ab16d04f0959b233085fb31653fbfc9d98f9"
|
||||
|
||||
[[package]]
|
||||
name = "codespan-reporting"
|
||||
version = "0.13.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "af491d569909a7e4dee0ad7db7f5341fef5c614d5b8ec8cf765732aba3cff681"
|
||||
dependencies = [
|
||||
"serde",
|
||||
"termcolor",
|
||||
"unicode-width 0.2.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ctor"
|
||||
version = "0.6.3"
|
||||
|
|
@ -271,81 +94,6 @@ version = "0.0.7"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "52560adf09603e58c9a7ee1fe1dcb95a16927b17c127f0ac02d6e768a0e25bc1"
|
||||
|
||||
[[package]]
|
||||
name = "cxx"
|
||||
version = "1.0.194"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "747d8437319e3a2f43d93b341c137927ca70c0f5dabeea7a005a73665e247c7e"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"cxx-build",
|
||||
"cxxbridge-cmd",
|
||||
"cxxbridge-flags",
|
||||
"cxxbridge-macro",
|
||||
"foldhash 0.2.0",
|
||||
"link-cplusplus",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cxx-build"
|
||||
version = "1.0.194"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b0f4697d190a142477b16aef7da8a99bfdc41e7e8b1687583c0d23a79c7afc1e"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"codespan-reporting",
|
||||
"indexmap 2.13.0",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"scratch",
|
||||
"syn 2.0.117",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cxx-gen"
|
||||
version = "0.7.194"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "035b6c61a944483e8a4b2ad4fb8b13830d63491bd004943716ad16d85dcc64bc"
|
||||
dependencies = [
|
||||
"codespan-reporting",
|
||||
"indexmap 2.13.0",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.117",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cxxbridge-cmd"
|
||||
version = "1.0.194"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d0956799fa8678d4c50eed028f2de1c0552ae183c76e976cf7ca8c4e36a7c328"
|
||||
dependencies = [
|
||||
"clap",
|
||||
"codespan-reporting",
|
||||
"indexmap 2.13.0",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.117",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cxxbridge-flags"
|
||||
version = "1.0.194"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "23384a836ab4f0ad98ace7e3955ad2de39de42378ab487dc28d3990392cb283a"
|
||||
|
||||
[[package]]
|
||||
name = "cxxbridge-macro"
|
||||
version = "1.0.194"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e6acc6b5822b9526adfb4fc377b67128fdd60aac757cc4a741a6278603f763cf"
|
||||
dependencies = [
|
||||
"indexmap 2.13.0",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.117",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "doxygen-bindgen"
|
||||
version = "0.1.3"
|
||||
|
|
@ -376,19 +124,6 @@ version = "1.15.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719"
|
||||
|
||||
[[package]]
|
||||
name = "env_logger"
|
||||
version = "0.9.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a12e6657c4c97ebab115a42dcee77225f7f482cdd841cf7088c657a42e9e00e7"
|
||||
dependencies = [
|
||||
"atty",
|
||||
"humantime",
|
||||
"log",
|
||||
"regex",
|
||||
"termcolor",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "equivalent"
|
||||
version = "1.0.2"
|
||||
|
|
@ -423,12 +158,6 @@ version = "0.1.5"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2"
|
||||
|
||||
[[package]]
|
||||
name = "foldhash"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "77ce24cb58228fbb8aa041425bb1050850ac19177686ea6e0f41a70416f56fdb"
|
||||
|
||||
[[package]]
|
||||
name = "futures-core"
|
||||
version = "0.3.32"
|
||||
|
|
@ -483,19 +212,13 @@ version = "0.3.3"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0cc23270f6e1808e30a928bdc84dea0b9b4136a8bc82338574f23baf47bbd280"
|
||||
|
||||
[[package]]
|
||||
name = "hashbrown"
|
||||
version = "0.12.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888"
|
||||
|
||||
[[package]]
|
||||
name = "hashbrown"
|
||||
version = "0.15.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1"
|
||||
dependencies = [
|
||||
"foldhash 0.1.5",
|
||||
"foldhash",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -510,38 +233,12 @@ version = "0.5.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
|
||||
|
||||
[[package]]
|
||||
name = "hermit-abi"
|
||||
version = "0.1.19"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "humantime"
|
||||
version = "2.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "135b12329e5e3ce057a9f972339ea52bc954fe1e9358ef27f95e89716fbc5424"
|
||||
|
||||
[[package]]
|
||||
name = "id-arena"
|
||||
version = "2.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3d3067d79b975e8844ca9eb072e16b31c3c1c36928edf9c6789548c524d0d954"
|
||||
|
||||
[[package]]
|
||||
name = "indexmap"
|
||||
version = "1.9.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"hashbrown 0.12.3",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "indexmap"
|
||||
version = "2.13.0"
|
||||
|
|
@ -554,30 +251,6 @@ dependencies = [
|
|||
"serde_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "indoc"
|
||||
version = "1.0.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bfa799dd5ed20a7e349f3b4639aa80d74549c81716d9ec4f994c9b5815598306"
|
||||
|
||||
[[package]]
|
||||
name = "itertools"
|
||||
version = "0.9.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "284f18f85651fe11e8a991b2adb42cb078325c996ed026d994719efcfca1d54b"
|
||||
dependencies = [
|
||||
"either",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "itertools"
|
||||
version = "0.10.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473"
|
||||
dependencies = [
|
||||
"either",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "itertools"
|
||||
version = "0.13.0"
|
||||
|
|
@ -624,15 +297,6 @@ dependencies = [
|
|||
"windows-link",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "link-cplusplus"
|
||||
version = "1.0.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7f78c730aaa7d0b9336a299029ea49f9ee53b0ed06e9202e8cb7db9bae7b8c82"
|
||||
dependencies = [
|
||||
"cc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "linux-raw-sys"
|
||||
version = "0.12.1"
|
||||
|
|
@ -660,44 +324,12 @@ version = "2.8.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79"
|
||||
|
||||
[[package]]
|
||||
name = "miette"
|
||||
version = "5.10.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "59bb584eaeeab6bd0226ccf3509a69d7936d148cf3d036ad350abe35e8c6856e"
|
||||
dependencies = [
|
||||
"miette-derive",
|
||||
"once_cell",
|
||||
"thiserror",
|
||||
"unicode-width 0.1.14",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "miette-derive"
|
||||
version = "5.10.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "49e7bc1560b95a3c4a25d03de42fe76ca718ab92d1a22a55b9b4cf67b3ae635c"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.117",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "minimal-lexical"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
|
||||
|
||||
[[package]]
|
||||
name = "moveit"
|
||||
version = "0.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "87d7335204cb6ef7bd647fa6db0be3e4d7aa25b5823a7aa030027ddf512cefba"
|
||||
dependencies = [
|
||||
"cxx",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "nixide"
|
||||
version = "0.1.0"
|
||||
|
|
@ -714,11 +346,10 @@ dependencies = [
|
|||
name = "nixide-sys"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"autocxx",
|
||||
"autocxx-build",
|
||||
"bindgen",
|
||||
"cc",
|
||||
"doxygen-bindgen",
|
||||
"heck",
|
||||
"itertools 0.14.0",
|
||||
"pkg-config",
|
||||
"serial_test",
|
||||
|
|
@ -782,31 +413,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "479ca8adacdd7ce8f1fb39ce9ecccbfe93a3f1344b3d0d97f20bc0196208f62b"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"syn 2.0.117",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro-error"
|
||||
version = "1.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c"
|
||||
dependencies = [
|
||||
"proc-macro-error-attr",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 1.0.109",
|
||||
"version_check",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro-error-attr"
|
||||
version = "1.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"version_check",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -851,7 +458,7 @@ dependencies = [
|
|||
"aho-corasick",
|
||||
"memchr",
|
||||
"regex-automata",
|
||||
"regex-syntax 0.8.10",
|
||||
"regex-syntax",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -862,55 +469,15 @@ checksum = "6e1dd4122fc1595e8162618945476892eefca7b88c52820e74af6262213cae8f"
|
|||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
"regex-syntax 0.8.10",
|
||||
"regex-syntax",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-syntax"
|
||||
version = "0.6.29"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1"
|
||||
|
||||
[[package]]
|
||||
name = "regex-syntax"
|
||||
version = "0.8.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dc897dd8d9e8bd1ed8cdad82b5966c3e0ecae09fb1907d58efaa013543185d0a"
|
||||
|
||||
[[package]]
|
||||
name = "regex_static"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6126d61c5e4b41929098f73b42fc1d257116cc95d19739248c51591f77cc0021"
|
||||
dependencies = [
|
||||
"once_cell",
|
||||
"regex",
|
||||
"regex_static_macro",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex_static_impl"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9c3755019886a70e772e6360b0b58501d75cf7dc17a53e08aa97e59ecb2c2bc5"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"regex-syntax 0.6.29",
|
||||
"syn 1.0.109",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex_static_macro"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "79b15495fd034158635bc8b762a132dfc83864d6992aeda1ffabf01b03b611a1"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"regex_static_impl",
|
||||
"syn 1.0.109",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustc-hash"
|
||||
version = "2.1.1"
|
||||
|
|
@ -930,12 +497,6 @@ dependencies = [
|
|||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustversion"
|
||||
version = "1.0.22"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d"
|
||||
|
||||
[[package]]
|
||||
name = "scc"
|
||||
version = "2.4.0"
|
||||
|
|
@ -951,12 +512,6 @@ version = "1.2.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
|
||||
|
||||
[[package]]
|
||||
name = "scratch"
|
||||
version = "1.0.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d68f2ec51b097e4c1a75b681a8bec621909b5e91f15bb7b840c4f2f7b01148b2"
|
||||
|
||||
[[package]]
|
||||
name = "sdd"
|
||||
version = "3.0.10"
|
||||
|
|
@ -976,7 +531,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e"
|
||||
dependencies = [
|
||||
"serde_core",
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -996,7 +550,7 @@ checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79"
|
|||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.117",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -1035,7 +589,7 @@ checksum = "0a7d91949b85b0d2fb687445e448b40d322b6b3e4af6b44a29b21d9a5f33e6d9"
|
|||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.117",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -1062,23 +616,6 @@ version = "0.3.3"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4af28eeb7c18ac2dbdb255d40bee63f203120e1db6b0024b177746ebec7049c1"
|
||||
|
||||
[[package]]
|
||||
name = "strsim"
|
||||
version = "0.11.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.109"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.117"
|
||||
|
|
@ -1103,65 +640,18 @@ dependencies = [
|
|||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "termcolor"
|
||||
version = "1.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755"
|
||||
dependencies = [
|
||||
"winapi-util",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
version = "1.0.69"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52"
|
||||
dependencies = [
|
||||
"thiserror-impl",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror-impl"
|
||||
version = "1.0.69"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.117",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.24"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-width"
|
||||
version = "0.1.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-width"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b4ac048d71ede7ee76d585517add45da530660ef4390e49b098733c6e897f254"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-xid"
|
||||
version = "0.2.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853"
|
||||
|
||||
[[package]]
|
||||
name = "version_check"
|
||||
version = "0.9.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
|
||||
|
||||
[[package]]
|
||||
name = "wasip2"
|
||||
version = "1.0.2+wasi-0.2.9"
|
||||
|
|
@ -1197,7 +687,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "bb0e353e6a2fbdc176932bbaab493762eb1255a7900fe0fea1a2f96c296cc909"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"indexmap 2.13.0",
|
||||
"indexmap",
|
||||
"wasm-encoder",
|
||||
"wasmparser",
|
||||
]
|
||||
|
|
@ -1210,41 +700,10 @@ checksum = "47b807c72e1bac69382b3a6fb3dbe8ea4c0ed87ff5629b8685ae6b9a611028fe"
|
|||
dependencies = [
|
||||
"bitflags",
|
||||
"hashbrown 0.15.5",
|
||||
"indexmap 2.13.0",
|
||||
"indexmap",
|
||||
"semver",
|
||||
]
|
||||
|
||||
[[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-util"
|
||||
version = "0.1.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22"
|
||||
dependencies = [
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
[[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 = "windows-link"
|
||||
version = "0.2.1"
|
||||
|
|
@ -1288,9 +747,9 @@ checksum = "b7c566e0f4b284dd6561c786d9cb0142da491f46a9fbed79ea69cdad5db17f21"
|
|||
dependencies = [
|
||||
"anyhow",
|
||||
"heck",
|
||||
"indexmap 2.13.0",
|
||||
"indexmap",
|
||||
"prettyplease",
|
||||
"syn 2.0.117",
|
||||
"syn",
|
||||
"wasm-metadata",
|
||||
"wit-bindgen-core",
|
||||
"wit-component",
|
||||
|
|
@ -1306,7 +765,7 @@ dependencies = [
|
|||
"prettyplease",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.117",
|
||||
"syn",
|
||||
"wit-bindgen-core",
|
||||
"wit-bindgen-rust",
|
||||
]
|
||||
|
|
@ -1319,7 +778,7 @@ checksum = "9d66ea20e9553b30172b5e831994e35fbde2d165325bec84fc43dbf6f4eb9cb2"
|
|||
dependencies = [
|
||||
"anyhow",
|
||||
"bitflags",
|
||||
"indexmap 2.13.0",
|
||||
"indexmap",
|
||||
"log",
|
||||
"serde",
|
||||
"serde_derive",
|
||||
|
|
@ -1338,7 +797,7 @@ checksum = "ecc8ac4bc1dc3381b7f59c34f00b67e18f910c2c0f50015669dde7def656a736"
|
|||
dependencies = [
|
||||
"anyhow",
|
||||
"id-arena",
|
||||
"indexmap 2.13.0",
|
||||
"indexmap",
|
||||
"log",
|
||||
"semver",
|
||||
"serde",
|
||||
|
|
|
|||
3
TODO.md
Normal file
3
TODO.md
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
- [ ] rename all `::std::os::raw` instances to ``::core::ffi`
|
||||
|
||||
- [ ] I probably don't need my implementations of `NixError` and `NixVerbosity` now, I could just re-export them for sys
|
||||
52
flake.nix
52
flake.nix
|
|
@ -96,32 +96,6 @@
|
|||
nixForBindings
|
||||
];
|
||||
|
||||
# bindgen uses clang to generate bindings, but it doesn't know where to
|
||||
# find our stdenv cc's headers, so when it's gcc, we need to tell it.
|
||||
postConfigure = lib.optionalString pkgs.stdenv.cc.isGNU ''
|
||||
#!/usr/bin/env bash
|
||||
# REF: https://github.com/nixops4/nix-bindings-rust/blob/main/bindgen-gcc.sh
|
||||
# Rust bindgen uses Clang to generate bindings, but that means that it can't
|
||||
# find the "system" or compiler headers when the stdenv compiler is GCC.
|
||||
# This script tells it where to find them.
|
||||
|
||||
echo "Extending BINDGEN_EXTRA_CLANG_ARGS with system include paths..." 2>&1
|
||||
BINDGEN_EXTRA_CLANG_ARGS="$${BINDGEN_EXTRA_CLANG_ARGS:-}"
|
||||
export BINDGEN_EXTRA_CLANG_ARGS
|
||||
include_paths=$(
|
||||
echo | $NIX_CC_UNWRAPPED -v -E -x c - 2>&1 \
|
||||
| awk '/#include <...> search starts here:/{flag=1;next} \
|
||||
/End of search list./{flag=0} \
|
||||
flag==1 {print $1}'
|
||||
)
|
||||
for path in $include_paths; do
|
||||
echo " - $path" 2>&1
|
||||
BINDGEN_EXTRA_CLANG_ARGS="$BINDGEN_EXTRA_CLANG_ARGS -I$path"
|
||||
done
|
||||
'';
|
||||
|
||||
shellHook = postConfigure;
|
||||
|
||||
env = let
|
||||
inherit (llvmPackages) llvm libclang;
|
||||
in {
|
||||
|
|
@ -181,32 +155,6 @@
|
|||
nixForBindings
|
||||
];
|
||||
|
||||
# bindgen uses clang to generate bindings, but it doesn't know where to
|
||||
# find our stdenv cc's headers, so when it's gcc, we need to tell it.
|
||||
postConfigure = lib.optionalString pkgs.stdenv.cc.isGNU ''
|
||||
#!/usr/bin/env bash
|
||||
# REF: https://github.com/nixops4/nix-bindings-rust/blob/main/bindgen-gcc.sh
|
||||
# Rust bindgen uses Clang to generate bindings, but that means that it can't
|
||||
# find the "system" or compiler headers when the stdenv compiler is GCC.
|
||||
# This script tells it where to find them.
|
||||
|
||||
echo "Extending BINDGEN_EXTRA_CLANG_ARGS with system include paths..." 2>&1
|
||||
BINDGEN_EXTRA_CLANG_ARGS="$${BINDGEN_EXTRA_CLANG_ARGS:-}"
|
||||
export BINDGEN_EXTRA_CLANG_ARGS
|
||||
include_paths=$(
|
||||
echo | $NIX_CC_UNWRAPPED -v -E -x c - 2>&1 \
|
||||
| awk '/#include <...> search starts here:/{flag=1;next} \
|
||||
/End of search list./{flag=0} \
|
||||
flag==1 {print $1}'
|
||||
)
|
||||
for path in $include_paths; do
|
||||
echo " - $path" 2>&1
|
||||
BINDGEN_EXTRA_CLANG_ARGS="$BINDGEN_EXTRA_CLANG_ARGS -I$path"
|
||||
done
|
||||
'';
|
||||
|
||||
shellHook = postConfigure;
|
||||
|
||||
env = let
|
||||
inherit (llvmPackages) llvm libclang;
|
||||
in {
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ build = "build.rs"
|
|||
targets = [ "x86_64-unknown-linux-gnu" ]
|
||||
|
||||
[lib]
|
||||
path = "lib.rs"
|
||||
path = "src/lib.rs"
|
||||
|
||||
# NOTE: `[features]` have a 1-1 correspondence to the
|
||||
# NOTE: shared libraries produced by the Nix C API.
|
||||
|
|
@ -28,15 +28,14 @@ nix-flake-c = []
|
|||
nix-main-c = []
|
||||
|
||||
[build-dependencies]
|
||||
itertools = "0.14.0"
|
||||
heck = "0.5.0"
|
||||
|
||||
# rust-bindgen
|
||||
bindgen = { default-features = false, features = [ "logging", "runtime" ], version = "0.72.1" }
|
||||
doxygen-bindgen = "0.1.3"
|
||||
itertools = "0.14.0"
|
||||
pkg-config.workspace = true
|
||||
cc.workspace = true
|
||||
autocxx-build = "0.30.0"
|
||||
|
||||
[dev-dependencies]
|
||||
serial_test = "3.4.0"
|
||||
|
||||
[dependencies]
|
||||
autocxx = "0.30.0"
|
||||
|
|
|
|||
|
|
@ -1,7 +1,11 @@
|
|||
use std::env;
|
||||
use std::fs;
|
||||
use std::path::PathBuf;
|
||||
use std::{env, fs};
|
||||
|
||||
use bindgen::callbacks::ParseCallbacks;
|
||||
use bindgen::RustEdition;
|
||||
use bindgen::callbacks::{ItemKind, ParseCallbacks};
|
||||
use heck::ToSnekCase;
|
||||
use heck::ToUpperCamelCase;
|
||||
use itertools::Itertools;
|
||||
|
||||
#[derive(Debug)]
|
||||
|
|
@ -19,7 +23,57 @@ impl ParseCallbacks for DoxygenCallbacks {
|
|||
}
|
||||
}
|
||||
|
||||
// WARNING: NOTE: the random panic occurs when you're missing imports!!
|
||||
/// Bindfmt is just the name im giving to the callbacks
|
||||
/// that handle renaming C/C++ tokens.
|
||||
#[derive(Debug)]
|
||||
struct BindfmtCallbacks;
|
||||
|
||||
#[inline]
|
||||
fn strip_variant_prefix(
|
||||
prefix: &'static str,
|
||||
enum_name: &str,
|
||||
variant: &str,
|
||||
) -> Result<String, String> {
|
||||
variant
|
||||
.strip_prefix(prefix)
|
||||
.map(str::to_owned)
|
||||
.ok_or(format!(
|
||||
"[bindfmt] enum {enum_name} expected prefix \"{prefix}\" but got {}",
|
||||
&variant
|
||||
))
|
||||
}
|
||||
|
||||
impl ParseCallbacks for BindfmtCallbacks {
|
||||
fn enum_variant_name(
|
||||
&self,
|
||||
_enum_name: Option<&str>,
|
||||
_original_variant_name: &str,
|
||||
_variant_value: bindgen::callbacks::EnumVariantValue,
|
||||
) -> Option<String> {
|
||||
let variant = _original_variant_name.to_upper_camel_case();
|
||||
|
||||
_enum_name.map(|enum_name| match enum_name.to_upper_camel_case().as_ref() {
|
||||
"NixVerbosity" => strip_variant_prefix("NixLvl", enum_name, &variant).unwrap(),
|
||||
"NixErr" => strip_variant_prefix("NixErr", enum_name, &variant)
|
||||
.or_else(|_| strip_variant_prefix("Nix", enum_name, &variant))
|
||||
.unwrap(),
|
||||
"ValueType" => strip_variant_prefix("NixType", enum_name, &variant).unwrap(),
|
||||
_ => variant,
|
||||
})
|
||||
}
|
||||
|
||||
fn item_name(&self, _item_info: bindgen::callbacks::ItemInfo) -> Option<String> {
|
||||
Some(match _item_info.kind {
|
||||
ItemKind::Type => _item_info.name.to_upper_camel_case(),
|
||||
_ => _item_info.name.to_snek_case(),
|
||||
})
|
||||
}
|
||||
|
||||
fn include_file(&self, _filename: &str) {
|
||||
eprintln!("[debug] including file: {}", _filename);
|
||||
}
|
||||
}
|
||||
|
||||
const LIBS: &[&'static str] = &[
|
||||
#[cfg(feature = "nix-util-c")]
|
||||
"nix-util-c",
|
||||
|
|
@ -36,14 +90,8 @@ const LIBS: &[&'static str] = &[
|
|||
];
|
||||
|
||||
fn main() {
|
||||
// Invalidate the built crate if the binding headers change
|
||||
// println!("cargo::rerun-if-changed=include");
|
||||
|
||||
let lib_args: Vec<String> = vec![ /* EXTRA ARGS */ ]
|
||||
.into_iter()
|
||||
.map(|s: &str| s.to_owned())
|
||||
.chain(
|
||||
LIBS.iter()
|
||||
let include_paths: Vec<PathBuf> = LIBS
|
||||
.iter()
|
||||
.map(|&name| {
|
||||
let lib = pkg_config::probe_library(name)
|
||||
.expect(&format!("Unable to find .pc file for {}", name));
|
||||
|
|
@ -53,25 +101,50 @@ fn main() {
|
|||
}
|
||||
|
||||
lib.include_paths
|
||||
.into_iter()
|
||||
.map(|p| format!("-I{}", p.display()))
|
||||
})
|
||||
.flatten(),
|
||||
)
|
||||
.flatten()
|
||||
.unique()
|
||||
.collect();
|
||||
|
||||
dbg!(&lib_args);
|
||||
let clang_args: Vec<String> = vec!["-x", "c++", "-std=c++23"]
|
||||
.into_iter()
|
||||
.map(|s: &str| s.to_owned())
|
||||
.chain(include_paths.iter().map(|p| format!("-I{}", p.display())))
|
||||
.collect();
|
||||
|
||||
dbg!(&clang_args);
|
||||
|
||||
let mut builder = bindgen::Builder::default()
|
||||
// .enable_cxx_namespaces()
|
||||
.clang_args(lib_args)
|
||||
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
|
||||
.rust_edition(RustEdition::Edition2024)
|
||||
.clang_args(clang_args)
|
||||
// Add `doxygen_bindgen` callbacks
|
||||
.parse_callbacks(Box::new(DoxygenCallbacks))
|
||||
.parse_callbacks(Box::new(BindfmtCallbacks))
|
||||
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
|
||||
// Format generated bindings with rustfmt
|
||||
.formatter(bindgen::Formatter::Rustfmt)
|
||||
.rustfmt_configuration_file(std::fs::canonicalize("rustfmt.toml").ok());
|
||||
.rustfmt_configuration_file(std::fs::canonicalize("rustfmt.toml").ok())
|
||||
.allowlist_file(r".*nix_api_[a-z]+\.h")
|
||||
// Wrap all unsafe operations in unsafe blocks
|
||||
.layout_tests(true)
|
||||
.use_core() // use ::core instead of ::std
|
||||
.ctypes_prefix("::core::ffi") // use ::core::ffi instead of ::std::os::raw
|
||||
.time_phases(true)
|
||||
.wrap_unsafe_ops(true)
|
||||
.trust_clang_mangling(true)
|
||||
.respect_cxx_access_specs(true)
|
||||
.default_enum_style(bindgen::EnumVariation::Rust { non_exhaustive: false })
|
||||
.translate_enum_integer_types(false)
|
||||
.size_t_is_usize(true)
|
||||
.use_distinct_char16_t(false)
|
||||
.generate_comments(false)
|
||||
.generate_cstr(true) // use &CStr instead of &[u8]
|
||||
.fit_macro_constants(true)
|
||||
.explicit_padding(true)
|
||||
.enable_cxx_namespaces()
|
||||
.represent_cxx_operators(true)
|
||||
.enable_function_attribute_detection()
|
||||
.raw_line("/** These bindings were auto-generated for the Nixide project (https://github.com/cry128/nixide) */");
|
||||
|
||||
// Register the input headers we would like to generate bindings for
|
||||
builder = LIBS
|
||||
|
|
@ -80,7 +153,7 @@ fn main() {
|
|||
let path = format!("include/{}.h", lib.strip_suffix("-c").unwrap());
|
||||
assert!(fs::exists(&path).unwrap());
|
||||
// Invalidate the built crate if the binding headers change
|
||||
// println!("cargo::rerun-if-changed={path}");
|
||||
println!("cargo::rerun-if-changed={path}");
|
||||
path
|
||||
})
|
||||
.fold(builder, |builder, path| builder.header(path));
|
||||
|
|
|
|||
|
|
@ -1,17 +0,0 @@
|
|||
//! # nixide-sys
|
||||
//!
|
||||
//! Unsafe direct FFI bindings to libnix C API.
|
||||
//!
|
||||
//! ## Safety
|
||||
//!
|
||||
//! These bindings are generated automatically and map directly to the C API.
|
||||
//! They are unsafe to use directly. Prefer using the high-level safe API in the
|
||||
//! parent crate unless you know what you're doing.
|
||||
|
||||
#![allow(non_upper_case_globals)]
|
||||
#![allow(non_camel_case_types)]
|
||||
#![allow(non_snake_case)]
|
||||
#![allow(rustdoc::bare_urls)]
|
||||
#![allow(rustdoc::invalid_html_tags)]
|
||||
|
||||
include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
|
||||
8
nixide-sys/src/exts/expr.rs
Normal file
8
nixide-sys/src/exts/expr.rs
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
use std::fmt::{Debug, Display, Formatter, Result as FmtResult};
|
||||
|
||||
impl Display for crate::ValueType {
|
||||
#[inline]
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
|
||||
Debug::fmt(self, f)
|
||||
}
|
||||
}
|
||||
1
nixide-sys/src/exts/fetchers.rs
Normal file
1
nixide-sys/src/exts/fetchers.rs
Normal file
|
|
@ -0,0 +1 @@
|
|||
use std::fmt::{Debug, Display, Formatter, Result as FmtResult};
|
||||
1
nixide-sys/src/exts/flake.rs
Normal file
1
nixide-sys/src/exts/flake.rs
Normal file
|
|
@ -0,0 +1 @@
|
|||
use std::fmt::{Debug, Display, Formatter, Result as FmtResult};
|
||||
1
nixide-sys/src/exts/main.rs
Normal file
1
nixide-sys/src/exts/main.rs
Normal file
|
|
@ -0,0 +1 @@
|
|||
use std::fmt::{Debug, Display, Formatter, Result as FmtResult};
|
||||
31
nixide-sys/src/exts/mod.rs
Normal file
31
nixide-sys/src/exts/mod.rs
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
#![allow(unused_imports)]
|
||||
|
||||
#[cfg(feature = "nix-expr-c")]
|
||||
mod expr;
|
||||
#[cfg(feature = "nix-expr-c")]
|
||||
pub use expr::*;
|
||||
|
||||
#[cfg(feature = "nix-fetchers-c")]
|
||||
mod fetchers;
|
||||
#[cfg(feature = "nix-fetchers-c")]
|
||||
pub use fetchers::*;
|
||||
|
||||
#[cfg(feature = "nix-flake-c")]
|
||||
mod flake;
|
||||
#[cfg(feature = "nix-flake-c")]
|
||||
pub use flake::*;
|
||||
|
||||
#[cfg(feature = "nix-main-c")]
|
||||
mod main;
|
||||
#[cfg(feature = "nix-main-c")]
|
||||
pub use main::*;
|
||||
|
||||
#[cfg(feature = "nix-store-c")]
|
||||
mod store;
|
||||
#[cfg(feature = "nix-store-c")]
|
||||
pub use store::*;
|
||||
|
||||
#[cfg(feature = "nix-util-c")]
|
||||
mod util;
|
||||
#[cfg(feature = "nix-util-c")]
|
||||
pub use util::*;
|
||||
1
nixide-sys/src/exts/store.rs
Normal file
1
nixide-sys/src/exts/store.rs
Normal file
|
|
@ -0,0 +1 @@
|
|||
use std::fmt::{Debug, Display, Formatter, Result as FmtResult};
|
||||
15
nixide-sys/src/exts/util.rs
Normal file
15
nixide-sys/src/exts/util.rs
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
use std::fmt::{Debug, Display, Formatter, Result as FmtResult};
|
||||
|
||||
impl Display for crate::NixErr {
|
||||
#[inline]
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
|
||||
Debug::fmt(self, f)
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for crate::NixVerbosity {
|
||||
#[inline]
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
|
||||
Debug::fmt(self, f)
|
||||
}
|
||||
}
|
||||
27
nixide-sys/src/lib.rs
Normal file
27
nixide-sys/src/lib.rs
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
//! # nixide-sys
|
||||
//!
|
||||
//! Unsafe direct FFI bindings to `libnix` C API.
|
||||
//!
|
||||
//! ## Safety
|
||||
//!
|
||||
//! These bindings are generated automatically and map directly to the C API.
|
||||
//! They are unsafe to use directly. Prefer using the high-level safe API in the
|
||||
//! parent crate unless you know what you're doing.
|
||||
//!
|
||||
//! The [nixide] crate should also act as good explanation of how
|
||||
//! these bindings, and hence `libnix` itself, are expected to be used.
|
||||
|
||||
mod bindings {
|
||||
#![allow(non_upper_case_globals)]
|
||||
#![allow(non_camel_case_types)]
|
||||
#![allow(non_snake_case)]
|
||||
#![allow(rustdoc::bare_urls)]
|
||||
#![allow(rustdoc::invalid_html_tags)]
|
||||
|
||||
include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
|
||||
}
|
||||
pub use bindings::root::*;
|
||||
|
||||
mod exts;
|
||||
#[allow(unused_imports)]
|
||||
pub use exts::*;
|
||||
2
nixide-sys/tests/README.md
Normal file
2
nixide-sys/tests/README.md
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
# `nixide-sys/tests`
|
||||
These tests are modified from the ones provided by [github:nixops4/nix-bindings-rust](https://github.com/nixops4/nix-bindings-rust)
|
||||
|
|
@ -1,13 +1,12 @@
|
|||
#![cfg(feature = "nix-expr-c")]
|
||||
#![cfg(test)]
|
||||
|
||||
use std::{
|
||||
ffi::{CStr, CString},
|
||||
ptr,
|
||||
};
|
||||
use std::ffi::{CStr, CString};
|
||||
use std::ptr;
|
||||
|
||||
use serial_test::serial;
|
||||
|
||||
use nixide_sys::*;
|
||||
use serial_test::serial;
|
||||
|
||||
#[test]
|
||||
#[serial]
|
||||
|
|
@ -16,13 +15,13 @@ fn eval_init_and_state_build() {
|
|||
let ctx = nix_c_context_create();
|
||||
assert!(!ctx.is_null());
|
||||
let err = nix_libutil_init(ctx);
|
||||
assert_eq!(err, nix_err_NIX_OK, "nix_libutil_init failed: {err}");
|
||||
assert_eq!(err, NixErr::Ok, "nix_libutil_init failed: {err}");
|
||||
|
||||
let err = nix_libstore_init(ctx);
|
||||
assert_eq!(err, nix_err_NIX_OK, "nix_libstore_init failed: {err}");
|
||||
assert_eq!(err, NixErr::Ok, "nix_libstore_init failed: {err}");
|
||||
|
||||
let err = nix_libexpr_init(ctx);
|
||||
assert_eq!(err, nix_err_NIX_OK, "nix_libexpr_init failed: {err}");
|
||||
assert_eq!(err, NixErr::Ok, "nix_libexpr_init failed: {err}");
|
||||
|
||||
let store = nix_store_open(ctx, std::ptr::null(), std::ptr::null_mut());
|
||||
assert!(!store.is_null());
|
||||
|
|
@ -31,7 +30,7 @@ fn eval_init_and_state_build() {
|
|||
assert!(!builder.is_null());
|
||||
|
||||
let load_err = nix_eval_state_builder_load(ctx, builder);
|
||||
assert_eq!(load_err, nix_err_NIX_OK);
|
||||
assert_eq!(load_err, NixErr::Ok);
|
||||
|
||||
let state = nix_eval_state_build(ctx, builder);
|
||||
assert!(!state.is_null());
|
||||
|
|
@ -51,20 +50,20 @@ fn eval_simple_expression() {
|
|||
assert!(!ctx.is_null());
|
||||
|
||||
let err = nix_libutil_init(ctx);
|
||||
assert_eq!(err, nix_err_NIX_OK, "nix_libutil_init failed: {err}");
|
||||
assert_eq!(err, NixErr::Ok, "nix_libutil_init failed: {err}");
|
||||
|
||||
let err = nix_libstore_init(ctx);
|
||||
assert_eq!(err, nix_err_NIX_OK, "nix_libstore_init failed: {err}");
|
||||
assert_eq!(err, NixErr::Ok, "nix_libstore_init failed: {err}");
|
||||
|
||||
let err = nix_libexpr_init(ctx);
|
||||
assert_eq!(err, nix_err_NIX_OK, "nix_libexpr_init failed: {err}");
|
||||
assert_eq!(err, NixErr::Ok, "nix_libexpr_init failed: {err}");
|
||||
|
||||
let store = nix_store_open(ctx, std::ptr::null(), std::ptr::null_mut());
|
||||
assert!(!store.is_null());
|
||||
|
||||
let builder = nix_eval_state_builder_new(ctx, store);
|
||||
assert!(!builder.is_null());
|
||||
assert_eq!(nix_eval_state_builder_load(ctx, builder), nix_err_NIX_OK);
|
||||
assert_eq!(nix_eval_state_builder_load(ctx, builder), NixErr::Ok);
|
||||
|
||||
let state = nix_eval_state_build(ctx, builder);
|
||||
assert!(!state.is_null());
|
||||
|
|
@ -76,11 +75,11 @@ fn eval_simple_expression() {
|
|||
assert!(!value.is_null());
|
||||
|
||||
let eval_err = nix_expr_eval_from_string(ctx, state, expr.as_ptr(), path.as_ptr(), value);
|
||||
assert_eq!(eval_err, nix_err_NIX_OK);
|
||||
assert_eq!(eval_err, NixErr::Ok);
|
||||
|
||||
// Force the value (should not be a thunk)
|
||||
let force_err = nix_value_force(ctx, state, value);
|
||||
assert_eq!(force_err, nix_err_NIX_OK);
|
||||
assert_eq!(force_err, NixErr::Ok);
|
||||
|
||||
nix_state_free(state);
|
||||
nix_eval_state_builder_free(builder);
|
||||
|
|
@ -96,25 +95,25 @@ fn value_construction_and_inspection() {
|
|||
let ctx = nix_c_context_create();
|
||||
assert!(!ctx.is_null());
|
||||
let err = nix_libutil_init(ctx);
|
||||
assert_eq!(err, nix_err_NIX_OK);
|
||||
assert_eq!(err, NixErr::Ok);
|
||||
let err = nix_libstore_init(ctx);
|
||||
assert_eq!(err, nix_err_NIX_OK);
|
||||
assert_eq!(err, NixErr::Ok);
|
||||
let err = nix_libexpr_init(ctx);
|
||||
assert_eq!(err, nix_err_NIX_OK);
|
||||
assert_eq!(err, NixErr::Ok);
|
||||
|
||||
let store = nix_store_open(ctx, ptr::null(), ptr::null_mut());
|
||||
assert!(!store.is_null());
|
||||
let builder = nix_eval_state_builder_new(ctx, store);
|
||||
assert!(!builder.is_null());
|
||||
assert_eq!(nix_eval_state_builder_load(ctx, builder), nix_err_NIX_OK);
|
||||
assert_eq!(nix_eval_state_builder_load(ctx, builder), NixErr::Ok);
|
||||
let state = nix_eval_state_build(ctx, builder);
|
||||
assert!(!state.is_null());
|
||||
|
||||
// Int
|
||||
let int_val = nix_alloc_value(ctx, state);
|
||||
assert!(!int_val.is_null());
|
||||
assert_eq!(nix_init_int(ctx, int_val, 42), nix_err_NIX_OK);
|
||||
assert_eq!(nix_get_type(ctx, int_val), ValueType_NIX_TYPE_INT);
|
||||
assert_eq!(nix_init_int(ctx, int_val, 42), NixErr::Ok);
|
||||
assert_eq!(nix_get_type(ctx, int_val), ValueType::Int);
|
||||
assert_eq!(nix_get_int(ctx, int_val), 42);
|
||||
|
||||
// Float
|
||||
|
|
@ -122,30 +121,30 @@ fn value_construction_and_inspection() {
|
|||
assert!(!float_val.is_null());
|
||||
assert_eq!(
|
||||
nix_init_float(ctx, float_val, std::f64::consts::PI),
|
||||
nix_err_NIX_OK
|
||||
NixErr::Ok
|
||||
);
|
||||
assert_eq!(nix_get_type(ctx, float_val), ValueType_NIX_TYPE_FLOAT);
|
||||
assert_eq!(nix_get_type(ctx, float_val), ValueType::Float);
|
||||
assert!((nix_get_float(ctx, float_val) - std::f64::consts::PI).abs() < 1e-10);
|
||||
|
||||
// Bool
|
||||
let bool_val = nix_alloc_value(ctx, state);
|
||||
assert!(!bool_val.is_null());
|
||||
assert_eq!(nix_init_bool(ctx, bool_val, true), nix_err_NIX_OK);
|
||||
assert_eq!(nix_get_type(ctx, bool_val), ValueType_NIX_TYPE_BOOL);
|
||||
assert_eq!(nix_init_bool(ctx, bool_val, true), NixErr::Ok);
|
||||
assert_eq!(nix_get_type(ctx, bool_val), ValueType::Bool);
|
||||
assert!(nix_get_bool(ctx, bool_val));
|
||||
|
||||
// Null
|
||||
let null_val = nix_alloc_value(ctx, state);
|
||||
assert!(!null_val.is_null());
|
||||
assert_eq!(nix_init_null(ctx, null_val), nix_err_NIX_OK);
|
||||
assert_eq!(nix_get_type(ctx, null_val), ValueType_NIX_TYPE_NULL);
|
||||
assert_eq!(nix_init_null(ctx, null_val), NixErr::Ok);
|
||||
assert_eq!(nix_get_type(ctx, null_val), ValueType::Null);
|
||||
|
||||
// String
|
||||
let string_val = nix_alloc_value(ctx, state);
|
||||
assert!(!string_val.is_null());
|
||||
let s = CString::new("hello world").unwrap();
|
||||
assert_eq!(nix_init_string(ctx, string_val, s.as_ptr()), nix_err_NIX_OK);
|
||||
assert_eq!(nix_get_type(ctx, string_val), ValueType_NIX_TYPE_STRING);
|
||||
assert_eq!(nix_init_string(ctx, string_val, s.as_ptr()), NixErr::Ok);
|
||||
assert_eq!(nix_get_type(ctx, string_val), ValueType::String);
|
||||
extern "C" fn string_cb(
|
||||
start: *const ::std::os::raw::c_char,
|
||||
n: ::std::os::raw::c_uint,
|
||||
|
|
@ -159,7 +158,7 @@ fn value_construction_and_inspection() {
|
|||
let mut got: Option<String> = None;
|
||||
assert_eq!(
|
||||
nix_get_string(ctx, string_val, Some(string_cb), (&raw mut got).cast()),
|
||||
nix_err_NIX_OK
|
||||
NixErr::Ok
|
||||
);
|
||||
assert_eq!(got.as_deref(), Some("hello world"));
|
||||
|
||||
|
|
@ -169,9 +168,9 @@ fn value_construction_and_inspection() {
|
|||
let p = CString::new("/nix/store/foo").unwrap();
|
||||
assert_eq!(
|
||||
nix_init_path_string(ctx, state, path_val, p.as_ptr()),
|
||||
nix_err_NIX_OK
|
||||
NixErr::Ok
|
||||
);
|
||||
assert_eq!(nix_get_type(ctx, path_val), ValueType_NIX_TYPE_PATH);
|
||||
assert_eq!(nix_get_type(ctx, path_val), ValueType::Path);
|
||||
let path_ptr = nix_get_path_string(ctx, path_val);
|
||||
assert!(!path_ptr.is_null());
|
||||
let path_str = CStr::from_ptr(path_ptr).to_string_lossy();
|
||||
|
|
@ -192,17 +191,17 @@ fn list_and_attrset_manipulation() {
|
|||
let ctx = nix_c_context_create();
|
||||
assert!(!ctx.is_null());
|
||||
let err = nix_libutil_init(ctx);
|
||||
assert_eq!(err, nix_err_NIX_OK);
|
||||
assert_eq!(err, NixErr::Ok);
|
||||
let err = nix_libstore_init(ctx);
|
||||
assert_eq!(err, nix_err_NIX_OK);
|
||||
assert_eq!(err, NixErr::Ok);
|
||||
let err = nix_libexpr_init(ctx);
|
||||
assert_eq!(err, nix_err_NIX_OK);
|
||||
assert_eq!(err, NixErr::Ok);
|
||||
|
||||
let store = nix_store_open(ctx, ptr::null(), ptr::null_mut());
|
||||
assert!(!store.is_null());
|
||||
let builder = nix_eval_state_builder_new(ctx, store);
|
||||
assert!(!builder.is_null());
|
||||
assert_eq!(nix_eval_state_builder_load(ctx, builder), nix_err_NIX_OK);
|
||||
assert_eq!(nix_eval_state_builder_load(ctx, builder), NixErr::Ok);
|
||||
let state = nix_eval_state_build(ctx, builder);
|
||||
assert!(!state.is_null());
|
||||
|
||||
|
|
@ -220,15 +219,15 @@ fn list_and_attrset_manipulation() {
|
|||
nix_list_builder_insert(ctx, list_builder, 2, v3);
|
||||
|
||||
let list_val = nix_alloc_value(ctx, state);
|
||||
assert_eq!(nix_make_list(ctx, list_builder, list_val), nix_err_NIX_OK);
|
||||
assert_eq!(nix_get_type(ctx, list_val), ValueType_NIX_TYPE_LIST);
|
||||
assert_eq!(nix_make_list(ctx, list_builder, list_val), NixErr::Ok);
|
||||
assert_eq!(nix_get_type(ctx, list_val), ValueType::List);
|
||||
assert_eq!(nix_get_list_size(ctx, list_val), 3);
|
||||
|
||||
// Get elements by index
|
||||
for i in 0..3 {
|
||||
let elem = nix_get_list_byidx(ctx, list_val, state, i);
|
||||
assert!(!elem.is_null());
|
||||
assert_eq!(nix_get_type(ctx, elem), ValueType_NIX_TYPE_INT);
|
||||
assert_eq!(nix_get_type(ctx, elem), ValueType::Int);
|
||||
assert_eq!(nix_get_int(ctx, elem), i64::from(i + 1));
|
||||
}
|
||||
|
||||
|
|
@ -248,19 +247,19 @@ fn list_and_attrset_manipulation() {
|
|||
nix_bindings_builder_insert(ctx, attr_builder, bar.as_ptr(), bar_val);
|
||||
|
||||
let attr_val = nix_alloc_value(ctx, state);
|
||||
assert_eq!(nix_make_attrs(ctx, attr_val, attr_builder), nix_err_NIX_OK);
|
||||
assert_eq!(nix_get_type(ctx, attr_val), ValueType_NIX_TYPE_ATTRS);
|
||||
assert_eq!(nix_make_attrs(ctx, attr_val, attr_builder), NixErr::Ok);
|
||||
assert_eq!(nix_get_type(ctx, attr_val), ValueType::Attrs);
|
||||
assert_eq!(nix_get_attrs_size(ctx, attr_val), 2);
|
||||
|
||||
// Get by name
|
||||
let foo_got = nix_get_attr_byname(ctx, attr_val, state, foo.as_ptr());
|
||||
assert!(!foo_got.is_null());
|
||||
assert_eq!(nix_get_type(ctx, foo_got), ValueType_NIX_TYPE_INT);
|
||||
assert_eq!(nix_get_type(ctx, foo_got), ValueType::Int);
|
||||
assert_eq!(nix_get_int(ctx, foo_got), 42);
|
||||
|
||||
let bar_got = nix_get_attr_byname(ctx, attr_val, state, bar.as_ptr());
|
||||
assert!(!bar_got.is_null());
|
||||
assert_eq!(nix_get_type(ctx, bar_got), ValueType_NIX_TYPE_STRING);
|
||||
assert_eq!(nix_get_type(ctx, bar_got), ValueType::String);
|
||||
|
||||
// Has attr
|
||||
assert!(nix_has_attr_byname(ctx, attr_val, state, foo.as_ptr()));
|
||||
|
|
@ -282,17 +281,17 @@ fn function_application_and_force() {
|
|||
let ctx = nix_c_context_create();
|
||||
assert!(!ctx.is_null());
|
||||
let err = nix_libutil_init(ctx);
|
||||
assert_eq!(err, nix_err_NIX_OK);
|
||||
assert_eq!(err, NixErr::Ok);
|
||||
let err = nix_libstore_init(ctx);
|
||||
assert_eq!(err, nix_err_NIX_OK);
|
||||
assert_eq!(err, NixErr::Ok);
|
||||
let err = nix_libexpr_init(ctx);
|
||||
assert_eq!(err, nix_err_NIX_OK);
|
||||
assert_eq!(err, NixErr::Ok);
|
||||
|
||||
let store = nix_store_open(ctx, ptr::null(), ptr::null_mut());
|
||||
assert!(!store.is_null());
|
||||
let builder = nix_eval_state_builder_new(ctx, store);
|
||||
assert!(!builder.is_null());
|
||||
assert_eq!(nix_eval_state_builder_load(ctx, builder), nix_err_NIX_OK);
|
||||
assert_eq!(nix_eval_state_builder_load(ctx, builder), NixErr::Ok);
|
||||
let state = nix_eval_state_build(ctx, builder);
|
||||
assert!(!state.is_null());
|
||||
|
||||
|
|
@ -303,7 +302,7 @@ fn function_application_and_force() {
|
|||
assert!(!fn_val.is_null());
|
||||
assert_eq!(
|
||||
nix_expr_eval_from_string(ctx, state, expr.as_ptr(), path.as_ptr(), fn_val),
|
||||
nix_err_NIX_OK
|
||||
NixErr::Ok
|
||||
);
|
||||
|
||||
// Argument: 41
|
||||
|
|
@ -315,16 +314,16 @@ fn function_application_and_force() {
|
|||
assert!(!result_val.is_null());
|
||||
assert_eq!(
|
||||
nix_value_call(ctx, state, fn_val, arg_val, result_val),
|
||||
nix_err_NIX_OK
|
||||
NixErr::Ok
|
||||
);
|
||||
|
||||
// Force result
|
||||
assert_eq!(nix_value_force(ctx, state, result_val), nix_err_NIX_OK);
|
||||
assert_eq!(nix_get_type(ctx, result_val), ValueType_NIX_TYPE_INT);
|
||||
assert_eq!(nix_value_force(ctx, state, result_val), NixErr::Ok);
|
||||
assert_eq!(nix_get_type(ctx, result_val), ValueType::Int);
|
||||
assert_eq!(nix_get_int(ctx, result_val), 42);
|
||||
|
||||
// Deep force (should be a no-op for int)
|
||||
assert_eq!(nix_value_force_deep(ctx, state, result_val), nix_err_NIX_OK);
|
||||
assert_eq!(nix_value_force_deep(ctx, state, result_val), NixErr::Ok);
|
||||
|
||||
nix_state_free(state);
|
||||
nix_eval_state_builder_free(builder);
|
||||
|
|
@ -340,17 +339,17 @@ fn error_handling_invalid_expression() {
|
|||
let ctx = nix_c_context_create();
|
||||
assert!(!ctx.is_null());
|
||||
let err = nix_libutil_init(ctx);
|
||||
assert_eq!(err, nix_err_NIX_OK);
|
||||
assert_eq!(err, NixErr::Ok);
|
||||
let err = nix_libstore_init(ctx);
|
||||
assert_eq!(err, nix_err_NIX_OK);
|
||||
assert_eq!(err, NixErr::Ok);
|
||||
let err = nix_libexpr_init(ctx);
|
||||
assert_eq!(err, nix_err_NIX_OK);
|
||||
assert_eq!(err, NixErr::Ok);
|
||||
|
||||
let store = nix_store_open(ctx, ptr::null(), ptr::null_mut());
|
||||
assert!(!store.is_null());
|
||||
let builder = nix_eval_state_builder_new(ctx, store);
|
||||
assert!(!builder.is_null());
|
||||
assert_eq!(nix_eval_state_builder_load(ctx, builder), nix_err_NIX_OK);
|
||||
assert_eq!(nix_eval_state_builder_load(ctx, builder), NixErr::Ok);
|
||||
let state = nix_eval_state_build(ctx, builder);
|
||||
assert!(!state.is_null());
|
||||
|
||||
|
|
@ -360,7 +359,7 @@ fn error_handling_invalid_expression() {
|
|||
let value = nix_alloc_value(ctx, state);
|
||||
assert!(!value.is_null());
|
||||
let eval_err = nix_expr_eval_from_string(ctx, state, expr.as_ptr(), path.as_ptr(), value);
|
||||
assert_ne!(eval_err, nix_err_NIX_OK);
|
||||
assert_ne!(eval_err, NixErr::Ok);
|
||||
|
||||
nix_state_free(state);
|
||||
nix_eval_state_builder_free(builder);
|
||||
|
|
@ -376,24 +375,24 @@ fn realised_string_and_gc() {
|
|||
let ctx = nix_c_context_create();
|
||||
assert!(!ctx.is_null());
|
||||
let err = nix_libutil_init(ctx);
|
||||
assert_eq!(err, nix_err_NIX_OK);
|
||||
assert_eq!(err, NixErr::Ok);
|
||||
let err = nix_libstore_init(ctx);
|
||||
assert_eq!(err, nix_err_NIX_OK);
|
||||
assert_eq!(err, NixErr::Ok);
|
||||
let err = nix_libexpr_init(ctx);
|
||||
assert_eq!(err, nix_err_NIX_OK);
|
||||
assert_eq!(err, NixErr::Ok);
|
||||
|
||||
let store = nix_store_open(ctx, ptr::null(), ptr::null_mut());
|
||||
assert!(!store.is_null());
|
||||
let builder = nix_eval_state_builder_new(ctx, store);
|
||||
assert!(!builder.is_null());
|
||||
assert_eq!(nix_eval_state_builder_load(ctx, builder), nix_err_NIX_OK);
|
||||
assert_eq!(nix_eval_state_builder_load(ctx, builder), NixErr::Ok);
|
||||
let state = nix_eval_state_build(ctx, builder);
|
||||
assert!(!state.is_null());
|
||||
|
||||
// String value
|
||||
let string_val = nix_alloc_value(ctx, state);
|
||||
let s = CString::new("hello world").unwrap();
|
||||
assert_eq!(nix_init_string(ctx, string_val, s.as_ptr()), nix_err_NIX_OK);
|
||||
assert_eq!(nix_init_string(ctx, string_val, s.as_ptr()), NixErr::Ok);
|
||||
|
||||
// Realise string
|
||||
let realised = nix_string_realise(ctx, state, string_val, false);
|
||||
|
|
@ -422,18 +421,18 @@ fn big_thunk_evaluation() {
|
|||
assert!(!ctx.is_null());
|
||||
|
||||
let err = nix_libutil_init(ctx);
|
||||
assert_eq!(err, nix_err_NIX_OK);
|
||||
assert_eq!(err, NixErr::Ok);
|
||||
let err = nix_libstore_init(ctx);
|
||||
assert_eq!(err, nix_err_NIX_OK);
|
||||
assert_eq!(err, NixErr::Ok);
|
||||
let err = nix_libexpr_init(ctx);
|
||||
assert_eq!(err, nix_err_NIX_OK);
|
||||
assert_eq!(err, NixErr::Ok);
|
||||
|
||||
let store = nix_store_open(ctx, ptr::null(), ptr::null_mut());
|
||||
assert!(!store.is_null());
|
||||
|
||||
let builder = nix_eval_state_builder_new(ctx, store);
|
||||
assert!(!builder.is_null());
|
||||
assert_eq!(nix_eval_state_builder_load(ctx, builder), nix_err_NIX_OK);
|
||||
assert_eq!(nix_eval_state_builder_load(ctx, builder), NixErr::Ok);
|
||||
|
||||
let state = nix_eval_state_build(ctx, builder);
|
||||
assert!(!state.is_null());
|
||||
|
|
@ -446,10 +445,10 @@ fn big_thunk_evaluation() {
|
|||
assert!(!value.is_null());
|
||||
|
||||
let eval_err = nix_expr_eval_from_string(ctx, state, expr.as_ptr(), path.as_ptr(), value);
|
||||
assert_eq!(eval_err, nix_err_NIX_OK);
|
||||
assert_eq!(eval_err, NixErr::Ok);
|
||||
|
||||
// The top-level should be an attrset
|
||||
assert_eq!(nix_get_type(ctx, value), ValueType_NIX_TYPE_ATTRS);
|
||||
assert_eq!(nix_get_type(ctx, value), ValueType::Attrs);
|
||||
|
||||
// Get "result" attribute (ts should be a thunk initially)
|
||||
let result_name = CString::new("result").unwrap();
|
||||
|
|
@ -458,9 +457,9 @@ fn big_thunk_evaluation() {
|
|||
|
||||
// Force the result
|
||||
let force_err = nix_value_force(ctx, state, result_val);
|
||||
assert_eq!(force_err, nix_err_NIX_OK);
|
||||
assert_eq!(force_err, NixErr::Ok);
|
||||
|
||||
assert_eq!(nix_get_type(ctx, result_val), ValueType_NIX_TYPE_INT);
|
||||
assert_eq!(nix_get_type(ctx, result_val), ValueType::Int);
|
||||
assert_eq!(nix_get_int(ctx, result_val), 13); // ((1+2)*3)+4 = 13
|
||||
|
||||
// Get "other" attribute
|
||||
|
|
@ -469,9 +468,9 @@ fn big_thunk_evaluation() {
|
|||
assert!(!other_val.is_null());
|
||||
|
||||
let force_err2 = nix_value_force(ctx, state, other_val);
|
||||
assert_eq!(force_err2, nix_err_NIX_OK);
|
||||
assert_eq!(force_err2, NixErr::Ok);
|
||||
|
||||
assert_eq!(nix_get_type(ctx, other_val), ValueType_NIX_TYPE_INT);
|
||||
assert_eq!(nix_get_type(ctx, other_val), ValueType::Int);
|
||||
assert_eq!(nix_get_int(ctx, other_val), 3); // 1+2 = 3
|
||||
|
||||
nix_state_free(state);
|
||||
|
|
@ -489,13 +488,13 @@ fn multi_argument_function_calls() {
|
|||
assert!(!ctx.is_null());
|
||||
|
||||
let err = nix_libutil_init(ctx);
|
||||
assert_eq!(err, nix_err_NIX_OK);
|
||||
assert_eq!(err, NixErr::Ok);
|
||||
|
||||
let err = nix_libstore_init(ctx);
|
||||
assert_eq!(err, nix_err_NIX_OK);
|
||||
assert_eq!(err, NixErr::Ok);
|
||||
|
||||
let err = nix_libexpr_init(ctx);
|
||||
assert_eq!(err, nix_err_NIX_OK);
|
||||
assert_eq!(err, NixErr::Ok);
|
||||
|
||||
let store = nix_store_open(ctx, std::ptr::null(), std::ptr::null_mut());
|
||||
assert!(!store.is_null());
|
||||
|
|
@ -504,7 +503,7 @@ fn multi_argument_function_calls() {
|
|||
assert!(!builder.is_null());
|
||||
|
||||
let load_err = nix_eval_state_builder_load(ctx, builder);
|
||||
assert_eq!(load_err, nix_err_NIX_OK);
|
||||
assert_eq!(load_err, NixErr::Ok);
|
||||
|
||||
let state = nix_eval_state_build(ctx, builder);
|
||||
assert!(!state.is_null());
|
||||
|
|
@ -518,15 +517,15 @@ fn multi_argument_function_calls() {
|
|||
|
||||
let eval_err =
|
||||
nix_expr_eval_from_string(ctx, state, expr.as_ptr(), path.as_ptr(), func_value);
|
||||
assert_eq!(eval_err, nix_err_NIX_OK);
|
||||
assert_eq!(eval_err, NixErr::Ok);
|
||||
|
||||
// Force evaluation of the function
|
||||
let force_err = nix_value_force(ctx, state, func_value);
|
||||
assert_eq!(force_err, nix_err_NIX_OK);
|
||||
assert_eq!(force_err, NixErr::Ok);
|
||||
|
||||
// Verify it's a function
|
||||
let func_type = nix_get_type(ctx, func_value);
|
||||
assert_eq!(func_type, ValueType_NIX_TYPE_FUNCTION);
|
||||
assert_eq!(func_type, ValueType::Function);
|
||||
|
||||
// Create arguments
|
||||
let arg1 = nix_alloc_value(ctx, state);
|
||||
|
|
@ -535,8 +534,8 @@ fn multi_argument_function_calls() {
|
|||
|
||||
let init_arg1_err = nix_init_int(ctx, arg1, 10);
|
||||
let init_arg2_err = nix_init_int(ctx, arg2, 20);
|
||||
assert_eq!(init_arg1_err, nix_err_NIX_OK);
|
||||
assert_eq!(init_arg2_err, nix_err_NIX_OK);
|
||||
assert_eq!(init_arg1_err, NixErr::Ok);
|
||||
assert_eq!(init_arg2_err, NixErr::Ok);
|
||||
|
||||
// Test multi-argument call using nix_value_call_multi
|
||||
let mut args = [arg1, arg2];
|
||||
|
|
@ -544,15 +543,15 @@ fn multi_argument_function_calls() {
|
|||
assert!(!result.is_null());
|
||||
|
||||
let call_err = nix_value_call_multi(ctx, state, func_value, 2, args.as_mut_ptr(), result);
|
||||
assert_eq!(call_err, nix_err_NIX_OK);
|
||||
assert_eq!(call_err, NixErr::Ok);
|
||||
|
||||
// Force the result
|
||||
let force_result_err = nix_value_force(ctx, state, result);
|
||||
assert_eq!(force_result_err, nix_err_NIX_OK);
|
||||
assert_eq!(force_result_err, NixErr::Ok);
|
||||
|
||||
// Check result type and value
|
||||
let result_type = nix_get_type(ctx, result);
|
||||
assert_eq!(result_type, ValueType_NIX_TYPE_INT);
|
||||
assert_eq!(result_type, ValueType::Int);
|
||||
|
||||
let result_value = nix_get_int(ctx, result);
|
||||
assert_eq!(result_value, 30); // 10 + 20
|
||||
|
|
@ -577,13 +576,13 @@ fn curried_function_evaluation() {
|
|||
assert!(!ctx.is_null());
|
||||
|
||||
let err = nix_libutil_init(ctx);
|
||||
assert_eq!(err, nix_err_NIX_OK);
|
||||
assert_eq!(err, NixErr::Ok);
|
||||
|
||||
let err = nix_libstore_init(ctx);
|
||||
assert_eq!(err, nix_err_NIX_OK);
|
||||
assert_eq!(err, NixErr::Ok);
|
||||
|
||||
let err = nix_libexpr_init(ctx);
|
||||
assert_eq!(err, nix_err_NIX_OK);
|
||||
assert_eq!(err, NixErr::Ok);
|
||||
|
||||
let store = nix_store_open(ctx, std::ptr::null(), std::ptr::null_mut());
|
||||
assert!(!store.is_null());
|
||||
|
|
@ -592,7 +591,7 @@ fn curried_function_evaluation() {
|
|||
assert!(!builder.is_null());
|
||||
|
||||
let load_err = nix_eval_state_builder_load(ctx, builder);
|
||||
assert_eq!(load_err, nix_err_NIX_OK);
|
||||
assert_eq!(load_err, NixErr::Ok);
|
||||
|
||||
let state = nix_eval_state_build(ctx, builder);
|
||||
assert!(!state.is_null());
|
||||
|
|
@ -606,7 +605,7 @@ fn curried_function_evaluation() {
|
|||
|
||||
let eval_err =
|
||||
nix_expr_eval_from_string(ctx, state, expr.as_ptr(), path.as_ptr(), func_value);
|
||||
assert_eq!(eval_err, nix_err_NIX_OK);
|
||||
assert_eq!(eval_err, NixErr::Ok);
|
||||
|
||||
// Create three arguments
|
||||
let arg1 = nix_alloc_value(ctx, state);
|
||||
|
|
@ -624,15 +623,15 @@ fn curried_function_evaluation() {
|
|||
assert!(!result.is_null());
|
||||
|
||||
let call_err = nix_value_call_multi(ctx, state, func_value, 3, args.as_mut_ptr(), result);
|
||||
assert_eq!(call_err, nix_err_NIX_OK);
|
||||
assert_eq!(call_err, NixErr::Ok);
|
||||
|
||||
// Force the result
|
||||
let force_result_err = nix_value_force(ctx, state, result);
|
||||
assert_eq!(force_result_err, nix_err_NIX_OK);
|
||||
assert_eq!(force_result_err, NixErr::Ok);
|
||||
|
||||
// Check result
|
||||
let result_type = nix_get_type(ctx, result);
|
||||
assert_eq!(result_type, ValueType_NIX_TYPE_INT);
|
||||
assert_eq!(result_type, ValueType::Int);
|
||||
|
||||
let result_value = nix_get_int(ctx, result);
|
||||
assert_eq!(result_value, 30); // 5 + 10 + 15
|
||||
|
|
@ -642,42 +641,42 @@ fn curried_function_evaluation() {
|
|||
assert!(!partial1.is_null());
|
||||
|
||||
let partial_call1_err = nix_value_call(ctx, state, func_value, arg1, partial1);
|
||||
assert_eq!(partial_call1_err, nix_err_NIX_OK);
|
||||
assert_eq!(partial_call1_err, NixErr::Ok);
|
||||
|
||||
// partial1 should still be a function
|
||||
let force_partial1_err = nix_value_force(ctx, state, partial1);
|
||||
assert_eq!(force_partial1_err, nix_err_NIX_OK);
|
||||
assert_eq!(force_partial1_err, NixErr::Ok);
|
||||
|
||||
let partial1_type = nix_get_type(ctx, partial1);
|
||||
assert_eq!(partial1_type, ValueType_NIX_TYPE_FUNCTION);
|
||||
assert_eq!(partial1_type, ValueType::Function);
|
||||
|
||||
// Apply second argument
|
||||
let partial2 = nix_alloc_value(ctx, state);
|
||||
assert!(!partial2.is_null());
|
||||
|
||||
let partial_call2_err = nix_value_call(ctx, state, partial1, arg2, partial2);
|
||||
assert_eq!(partial_call2_err, nix_err_NIX_OK);
|
||||
assert_eq!(partial_call2_err, NixErr::Ok);
|
||||
|
||||
// partial2 should still be a function
|
||||
let force_partial2_err = nix_value_force(ctx, state, partial2);
|
||||
assert_eq!(force_partial2_err, nix_err_NIX_OK);
|
||||
assert_eq!(force_partial2_err, NixErr::Ok);
|
||||
|
||||
let partial2_type = nix_get_type(ctx, partial2);
|
||||
assert_eq!(partial2_type, ValueType_NIX_TYPE_FUNCTION);
|
||||
assert_eq!(partial2_type, ValueType::Function);
|
||||
|
||||
// Apply final argument
|
||||
let final_result = nix_alloc_value(ctx, state);
|
||||
assert!(!final_result.is_null());
|
||||
|
||||
let final_call_err = nix_value_call(ctx, state, partial2, arg3, final_result);
|
||||
assert_eq!(final_call_err, nix_err_NIX_OK);
|
||||
assert_eq!(final_call_err, NixErr::Ok);
|
||||
|
||||
// Force and check final result
|
||||
let force_final_err = nix_value_force(ctx, state, final_result);
|
||||
assert_eq!(force_final_err, nix_err_NIX_OK);
|
||||
assert_eq!(force_final_err, NixErr::Ok);
|
||||
|
||||
let final_type = nix_get_type(ctx, final_result);
|
||||
assert_eq!(final_type, ValueType_NIX_TYPE_INT);
|
||||
assert_eq!(final_type, ValueType::Int);
|
||||
|
||||
let final_value = nix_get_int(ctx, final_result);
|
||||
assert_eq!(final_value, 30); // same result as multi-arg call
|
||||
|
|
@ -706,13 +705,13 @@ fn thunk_creation_with_init_apply() {
|
|||
assert!(!ctx.is_null());
|
||||
|
||||
let err = nix_libutil_init(ctx);
|
||||
assert_eq!(err, nix_err_NIX_OK);
|
||||
assert_eq!(err, NixErr::Ok);
|
||||
|
||||
let err = nix_libstore_init(ctx);
|
||||
assert_eq!(err, nix_err_NIX_OK);
|
||||
assert_eq!(err, NixErr::Ok);
|
||||
|
||||
let err = nix_libexpr_init(ctx);
|
||||
assert_eq!(err, nix_err_NIX_OK);
|
||||
assert_eq!(err, NixErr::Ok);
|
||||
|
||||
let store = nix_store_open(ctx, std::ptr::null(), std::ptr::null_mut());
|
||||
assert!(!store.is_null());
|
||||
|
|
@ -721,7 +720,7 @@ fn thunk_creation_with_init_apply() {
|
|||
assert!(!builder.is_null());
|
||||
|
||||
let load_err = nix_eval_state_builder_load(ctx, builder);
|
||||
assert_eq!(load_err, nix_err_NIX_OK);
|
||||
assert_eq!(load_err, NixErr::Ok);
|
||||
|
||||
let state = nix_eval_state_build(ctx, builder);
|
||||
assert!(!state.is_null());
|
||||
|
|
@ -735,33 +734,33 @@ fn thunk_creation_with_init_apply() {
|
|||
|
||||
let eval_err =
|
||||
nix_expr_eval_from_string(ctx, state, func_expr.as_ptr(), path.as_ptr(), func_value);
|
||||
assert_eq!(eval_err, nix_err_NIX_OK);
|
||||
assert_eq!(eval_err, NixErr::Ok);
|
||||
|
||||
// Create an argument
|
||||
let arg = nix_alloc_value(ctx, state);
|
||||
assert!(!arg.is_null());
|
||||
|
||||
let init_arg_err = nix_init_int(ctx, arg, 21);
|
||||
assert_eq!(init_arg_err, nix_err_NIX_OK);
|
||||
assert_eq!(init_arg_err, NixErr::Ok);
|
||||
|
||||
// Create a thunk using nix_init_apply (lazy evaluation)
|
||||
let thunk = nix_alloc_value(ctx, state);
|
||||
assert!(!thunk.is_null());
|
||||
|
||||
let apply_err = nix_init_apply(ctx, thunk, func_value, arg);
|
||||
assert_eq!(apply_err, nix_err_NIX_OK);
|
||||
assert_eq!(apply_err, NixErr::Ok);
|
||||
|
||||
// Initially, the thunk should be of type THUNK
|
||||
let thunk_type = nix_get_type(ctx, thunk);
|
||||
assert_eq!(thunk_type, ValueType_NIX_TYPE_THUNK);
|
||||
assert_eq!(thunk_type, ValueType::Thunk);
|
||||
|
||||
// Force evaluation of the thunk
|
||||
let force_err = nix_value_force(ctx, state, thunk);
|
||||
assert_eq!(force_err, nix_err_NIX_OK);
|
||||
assert_eq!(force_err, NixErr::Ok);
|
||||
|
||||
// After forcing, it should be an integer
|
||||
let forced_type = nix_get_type(ctx, thunk);
|
||||
assert_eq!(forced_type, ValueType_NIX_TYPE_INT);
|
||||
assert_eq!(forced_type, ValueType::Int);
|
||||
|
||||
let result_value = nix_get_int(ctx, thunk);
|
||||
assert_eq!(result_value, 42); // 21 * 2
|
||||
|
|
@ -785,13 +784,13 @@ fn lookup_path_configuration() {
|
|||
assert!(!ctx.is_null());
|
||||
|
||||
let err = nix_libutil_init(ctx);
|
||||
assert_eq!(err, nix_err_NIX_OK);
|
||||
assert_eq!(err, NixErr::Ok);
|
||||
|
||||
let err = nix_libstore_init(ctx);
|
||||
assert_eq!(err, nix_err_NIX_OK);
|
||||
assert_eq!(err, NixErr::Ok);
|
||||
|
||||
let err = nix_libexpr_init(ctx);
|
||||
assert_eq!(err, nix_err_NIX_OK);
|
||||
assert_eq!(err, NixErr::Ok);
|
||||
|
||||
let store = nix_store_open(ctx, std::ptr::null(), std::ptr::null_mut());
|
||||
assert!(!store.is_null());
|
||||
|
|
@ -814,10 +813,10 @@ fn lookup_path_configuration() {
|
|||
builder,
|
||||
lookup_path_ptrs_null_terminated.as_mut_ptr(),
|
||||
);
|
||||
assert_eq!(set_lookup_err, nix_err_NIX_OK);
|
||||
assert_eq!(set_lookup_err, NixErr::Ok);
|
||||
|
||||
let load_err = nix_eval_state_builder_load(ctx, builder);
|
||||
assert_eq!(load_err, nix_err_NIX_OK);
|
||||
assert_eq!(load_err, NixErr::Ok);
|
||||
|
||||
let state = nix_eval_state_build(ctx, builder);
|
||||
assert!(!state.is_null());
|
||||
|
|
@ -836,12 +835,12 @@ fn lookup_path_configuration() {
|
|||
// The evaluation might succeed or fail depending on Nix version and
|
||||
// configuration The important thing is that setting the lookup path
|
||||
// didn't crash
|
||||
if eval_err == nix_err_NIX_OK {
|
||||
if eval_err == NixErr::Ok {
|
||||
let force_err = nix_value_force(ctx, state, result);
|
||||
if force_err == nix_err_NIX_OK {
|
||||
if force_err == NixErr::Ok {
|
||||
let result_type = nix_get_type(ctx, result);
|
||||
// nixPath should be a list
|
||||
assert_eq!(result_type, ValueType_NIX_TYPE_LIST);
|
||||
assert_eq!(result_type, ValueType::List);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -862,13 +861,13 @@ fn complex_nested_evaluation() {
|
|||
assert!(!ctx.is_null());
|
||||
|
||||
let err = nix_libutil_init(ctx);
|
||||
assert_eq!(err, nix_err_NIX_OK);
|
||||
assert_eq!(err, NixErr::Ok);
|
||||
|
||||
let err = nix_libstore_init(ctx);
|
||||
assert_eq!(err, nix_err_NIX_OK);
|
||||
assert_eq!(err, NixErr::Ok);
|
||||
|
||||
let err = nix_libexpr_init(ctx);
|
||||
assert_eq!(err, nix_err_NIX_OK);
|
||||
assert_eq!(err, NixErr::Ok);
|
||||
|
||||
let store = nix_store_open(ctx, std::ptr::null(), std::ptr::null_mut());
|
||||
assert!(!store.is_null());
|
||||
|
|
@ -877,7 +876,7 @@ fn complex_nested_evaluation() {
|
|||
assert!(!builder.is_null());
|
||||
|
||||
let load_err = nix_eval_state_builder_load(ctx, builder);
|
||||
assert_eq!(load_err, nix_err_NIX_OK);
|
||||
assert_eq!(load_err, NixErr::Ok);
|
||||
|
||||
let state = nix_eval_state_build(ctx, builder);
|
||||
assert!(!state.is_null());
|
||||
|
|
@ -907,7 +906,7 @@ fn complex_nested_evaluation() {
|
|||
|
||||
// Complex expressions may fail sometimes, check for both success
|
||||
// and error
|
||||
if eval_err != nix_err_NIX_OK {
|
||||
if eval_err != NixErr::Ok {
|
||||
// If evaluation fails, skip the rest of the test
|
||||
nix_value_decref(ctx, result);
|
||||
nix_state_free(state);
|
||||
|
|
@ -919,7 +918,7 @@ fn complex_nested_evaluation() {
|
|||
|
||||
// Force deep evaluation
|
||||
let force_err = nix_value_force_deep(ctx, state, result);
|
||||
if force_err != nix_err_NIX_OK {
|
||||
if force_err != NixErr::Ok {
|
||||
// If forcing fails, skip the rest of the test
|
||||
nix_value_decref(ctx, result);
|
||||
nix_state_free(state);
|
||||
|
|
@ -931,7 +930,7 @@ fn complex_nested_evaluation() {
|
|||
|
||||
// Verify result structure
|
||||
let result_type = nix_get_type(ctx, result);
|
||||
assert_eq!(result_type, ValueType_NIX_TYPE_ATTRS);
|
||||
assert_eq!(result_type, ValueType::Attrs);
|
||||
|
||||
let attrs_size = nix_get_attrs_size(ctx, result);
|
||||
assert_eq!(attrs_size, 2); // original, sum
|
||||
|
|
@ -942,7 +941,7 @@ fn complex_nested_evaluation() {
|
|||
assert!(!sum_value.is_null());
|
||||
|
||||
let sum_type = nix_get_type(ctx, sum_value);
|
||||
assert_eq!(sum_type, ValueType_NIX_TYPE_INT);
|
||||
assert_eq!(sum_type, ValueType::Int);
|
||||
|
||||
let sum_result = nix_get_int(ctx, sum_value);
|
||||
assert_eq!(sum_result, 15); // 1 + 2 + 3 + 4 + 5
|
||||
|
|
@ -952,7 +951,7 @@ fn complex_nested_evaluation() {
|
|||
let original_value = nix_get_attr_byname(ctx, result, state, original_key.as_ptr());
|
||||
if !original_value.is_null() {
|
||||
let original_type = nix_get_type(ctx, original_value);
|
||||
assert_eq!(original_type, ValueType_NIX_TYPE_LIST);
|
||||
assert_eq!(original_type, ValueType::List);
|
||||
|
||||
let original_size = nix_get_list_size(ctx, original_value);
|
||||
assert_eq!(original_size, 5);
|
||||
|
|
@ -961,7 +960,7 @@ fn complex_nested_evaluation() {
|
|||
let first_elem = nix_get_list_byidx(ctx, original_value, state, 0);
|
||||
if !first_elem.is_null() {
|
||||
let first_elem_type = nix_get_type(ctx, first_elem);
|
||||
assert_eq!(first_elem_type, ValueType_NIX_TYPE_INT);
|
||||
assert_eq!(first_elem_type, ValueType::Int);
|
||||
|
||||
let first_elem_value = nix_get_int(ctx, first_elem);
|
||||
assert_eq!(first_elem_value, 1);
|
||||
|
|
@ -985,13 +984,13 @@ fn evaluation_error_handling() {
|
|||
assert!(!ctx.is_null());
|
||||
|
||||
let err = nix_libutil_init(ctx);
|
||||
assert_eq!(err, nix_err_NIX_OK);
|
||||
assert_eq!(err, NixErr::Ok);
|
||||
|
||||
let err = nix_libstore_init(ctx);
|
||||
assert_eq!(err, nix_err_NIX_OK);
|
||||
assert_eq!(err, NixErr::Ok);
|
||||
|
||||
let err = nix_libexpr_init(ctx);
|
||||
assert_eq!(err, nix_err_NIX_OK);
|
||||
assert_eq!(err, NixErr::Ok);
|
||||
|
||||
let store = nix_store_open(ctx, std::ptr::null(), std::ptr::null_mut());
|
||||
assert!(!store.is_null());
|
||||
|
|
@ -1000,7 +999,7 @@ fn evaluation_error_handling() {
|
|||
assert!(!builder.is_null());
|
||||
|
||||
let load_err = nix_eval_state_builder_load(ctx, builder);
|
||||
assert_eq!(load_err, nix_err_NIX_OK);
|
||||
assert_eq!(load_err, NixErr::Ok);
|
||||
|
||||
let state = nix_eval_state_build(ctx, builder);
|
||||
assert!(!state.is_null());
|
||||
|
|
@ -1014,7 +1013,7 @@ fn evaluation_error_handling() {
|
|||
|
||||
let eval_err =
|
||||
nix_expr_eval_from_string(ctx, state, invalid_expr.as_ptr(), path.as_ptr(), result);
|
||||
assert_ne!(eval_err, nix_err_NIX_OK); // should fail
|
||||
assert_ne!(eval_err, NixErr::Ok); // should fail
|
||||
|
||||
// Clear error for next test
|
||||
nix_clear_err(ctx);
|
||||
|
|
@ -1034,14 +1033,14 @@ fn evaluation_error_handling() {
|
|||
);
|
||||
|
||||
// May succeed at parse time but fail during evaluation
|
||||
if eval_err2 == nix_err_NIX_OK {
|
||||
if eval_err2 == NixErr::Ok {
|
||||
let force_err = nix_value_force(ctx, state, result2);
|
||||
assert_ne!(force_err, nix_err_NIX_OK); // should fail during forcing
|
||||
assert_ne!(force_err, NixErr::Ok); // should fail during forcing
|
||||
}
|
||||
|
||||
// Test error information retrieval
|
||||
let error_code = nix_err_code(ctx);
|
||||
assert_ne!(error_code, nix_err_NIX_OK);
|
||||
assert_ne!(error_code, NixErr::Ok);
|
||||
|
||||
// Try to get error message
|
||||
let mut error_len: std::os::raw::c_uint = 0;
|
||||
|
|
@ -1065,7 +1064,7 @@ fn evaluation_error_handling() {
|
|||
|
||||
let eval_func_err =
|
||||
nix_expr_eval_from_string(ctx, state, func_expr.as_ptr(), path.as_ptr(), func_value);
|
||||
assert_eq!(eval_func_err, nix_err_NIX_OK);
|
||||
assert_eq!(eval_func_err, NixErr::Ok);
|
||||
|
||||
// Try to call with wrong number of arguments.
|
||||
// The function expects 2, but we give 1
|
||||
|
|
@ -1087,12 +1086,12 @@ fn evaluation_error_handling() {
|
|||
);
|
||||
|
||||
// This should succeed but result should be a partially applied function
|
||||
if call_err == nix_err_NIX_OK {
|
||||
if call_err == NixErr::Ok {
|
||||
let force_err = nix_value_force(ctx, state, result3);
|
||||
assert_eq!(force_err, nix_err_NIX_OK);
|
||||
assert_eq!(force_err, NixErr::Ok);
|
||||
|
||||
let result_type = nix_get_type(ctx, result3);
|
||||
assert_eq!(result_type, ValueType_NIX_TYPE_FUNCTION); // partially applied
|
||||
assert_eq!(result_type, ValueType::Function); // partially applied
|
||||
}
|
||||
|
||||
// Clean up
|
||||
|
|
@ -1116,13 +1115,13 @@ fn builtin_function_calls() {
|
|||
assert!(!ctx.is_null());
|
||||
|
||||
let err = nix_libutil_init(ctx);
|
||||
assert_eq!(err, nix_err_NIX_OK);
|
||||
assert_eq!(err, NixErr::Ok);
|
||||
|
||||
let err = nix_libstore_init(ctx);
|
||||
assert_eq!(err, nix_err_NIX_OK);
|
||||
assert_eq!(err, NixErr::Ok);
|
||||
|
||||
let err = nix_libexpr_init(ctx);
|
||||
assert_eq!(err, nix_err_NIX_OK);
|
||||
assert_eq!(err, NixErr::Ok);
|
||||
|
||||
let store = nix_store_open(ctx, std::ptr::null(), std::ptr::null_mut());
|
||||
assert!(!store.is_null());
|
||||
|
|
@ -1131,7 +1130,7 @@ fn builtin_function_calls() {
|
|||
assert!(!builder.is_null());
|
||||
|
||||
let load_err = nix_eval_state_builder_load(ctx, builder);
|
||||
assert_eq!(load_err, nix_err_NIX_OK);
|
||||
assert_eq!(load_err, NixErr::Ok);
|
||||
|
||||
let state = nix_eval_state_build(ctx, builder);
|
||||
assert!(!state.is_null());
|
||||
|
|
@ -1145,7 +1144,7 @@ fn builtin_function_calls() {
|
|||
|
||||
let eval_length_err =
|
||||
nix_expr_eval_from_string(ctx, state, length_expr.as_ptr(), path.as_ptr(), length_func);
|
||||
assert_eq!(eval_length_err, nix_err_NIX_OK);
|
||||
assert_eq!(eval_length_err, NixErr::Ok);
|
||||
|
||||
// Create a list to test with
|
||||
let list_expr = CString::new("[1 2 3 4 5]").unwrap();
|
||||
|
|
@ -1154,20 +1153,20 @@ fn builtin_function_calls() {
|
|||
|
||||
let eval_list_err =
|
||||
nix_expr_eval_from_string(ctx, state, list_expr.as_ptr(), path.as_ptr(), test_list);
|
||||
assert_eq!(eval_list_err, nix_err_NIX_OK);
|
||||
assert_eq!(eval_list_err, NixErr::Ok);
|
||||
|
||||
// Call length function with the list
|
||||
let length_result = nix_alloc_value(ctx, state);
|
||||
assert!(!length_result.is_null());
|
||||
|
||||
let call_length_err = nix_value_call(ctx, state, length_func, test_list, length_result);
|
||||
assert_eq!(call_length_err, nix_err_NIX_OK);
|
||||
assert_eq!(call_length_err, NixErr::Ok);
|
||||
|
||||
let force_length_err = nix_value_force(ctx, state, length_result);
|
||||
assert_eq!(force_length_err, nix_err_NIX_OK);
|
||||
assert_eq!(force_length_err, NixErr::Ok);
|
||||
|
||||
let length_type = nix_get_type(ctx, length_result);
|
||||
assert_eq!(length_type, ValueType_NIX_TYPE_INT);
|
||||
assert_eq!(length_type, ValueType::Int);
|
||||
|
||||
let length_value = nix_get_int(ctx, length_result);
|
||||
assert_eq!(length_value, 5);
|
||||
|
|
@ -1179,7 +1178,7 @@ fn builtin_function_calls() {
|
|||
|
||||
let eval_map_err =
|
||||
nix_expr_eval_from_string(ctx, state, map_expr.as_ptr(), path.as_ptr(), map_func);
|
||||
assert_eq!(eval_map_err, nix_err_NIX_OK);
|
||||
assert_eq!(eval_map_err, NixErr::Ok);
|
||||
|
||||
// Create a simple function to map: (x: x * 2)
|
||||
let double_expr = CString::new("(x: x * 2)").unwrap();
|
||||
|
|
@ -1188,7 +1187,7 @@ fn builtin_function_calls() {
|
|||
|
||||
let eval_double_err =
|
||||
nix_expr_eval_from_string(ctx, state, double_expr.as_ptr(), path.as_ptr(), double_func);
|
||||
assert_eq!(eval_double_err, nix_err_NIX_OK);
|
||||
assert_eq!(eval_double_err, NixErr::Ok);
|
||||
|
||||
// Call map with the function and list
|
||||
let mut args = [double_func, test_list];
|
||||
|
|
@ -1197,13 +1196,13 @@ fn builtin_function_calls() {
|
|||
|
||||
let call_map_err =
|
||||
nix_value_call_multi(ctx, state, map_func, 2, args.as_mut_ptr(), map_result);
|
||||
assert_eq!(call_map_err, nix_err_NIX_OK);
|
||||
assert_eq!(call_map_err, NixErr::Ok);
|
||||
|
||||
let force_map_err = nix_value_force(ctx, state, map_result);
|
||||
assert_eq!(force_map_err, nix_err_NIX_OK);
|
||||
assert_eq!(force_map_err, NixErr::Ok);
|
||||
|
||||
let map_result_type = nix_get_type(ctx, map_result);
|
||||
assert_eq!(map_result_type, ValueType_NIX_TYPE_LIST);
|
||||
assert_eq!(map_result_type, ValueType::List);
|
||||
|
||||
let map_result_size = nix_get_list_size(ctx, map_result);
|
||||
assert_eq!(map_result_size, 5);
|
||||
|
|
@ -1213,10 +1212,10 @@ fn builtin_function_calls() {
|
|||
assert!(!first_mapped.is_null());
|
||||
|
||||
let force_first_err = nix_value_force(ctx, state, first_mapped);
|
||||
assert_eq!(force_first_err, nix_err_NIX_OK);
|
||||
assert_eq!(force_first_err, NixErr::Ok);
|
||||
|
||||
let first_mapped_type = nix_get_type(ctx, first_mapped);
|
||||
assert_eq!(first_mapped_type, ValueType_NIX_TYPE_INT);
|
||||
assert_eq!(first_mapped_type, ValueType::Int);
|
||||
|
||||
let first_mapped_value = nix_get_int(ctx, first_mapped);
|
||||
assert_eq!(first_mapped_value, 2); // 1 * 2
|
||||
|
|
|
|||
|
|
@ -3,9 +3,10 @@
|
|||
|
||||
use std::ptr;
|
||||
|
||||
use nixide_sys::*;
|
||||
use serial_test::serial;
|
||||
|
||||
use nixide_sys::*;
|
||||
|
||||
#[test]
|
||||
#[serial]
|
||||
fn flake_settings_new_and_free() {
|
||||
|
|
@ -32,13 +33,13 @@ fn flake_settings_add_to_eval_state_builder() {
|
|||
assert!(!ctx.is_null());
|
||||
|
||||
let err = nix_libutil_init(ctx);
|
||||
assert_eq!(err, nix_err_NIX_OK);
|
||||
assert_eq!(err, NixErr::Ok);
|
||||
|
||||
let err = nix_libstore_init(ctx);
|
||||
assert_eq!(err, nix_err_NIX_OK);
|
||||
assert_eq!(err, NixErr::Ok);
|
||||
|
||||
let err = nix_libexpr_init(ctx);
|
||||
assert_eq!(err, nix_err_NIX_OK);
|
||||
assert_eq!(err, NixErr::Ok);
|
||||
|
||||
let store = nix_store_open(ctx, ptr::null(), ptr::null_mut());
|
||||
assert!(!store.is_null());
|
||||
|
|
@ -53,9 +54,8 @@ fn flake_settings_add_to_eval_state_builder() {
|
|||
let err = nix_flake_settings_add_to_eval_state_builder(ctx, settings, builder);
|
||||
// Accept OK or ERR_UNKNOWN (depends on Nix build/config)
|
||||
assert!(
|
||||
err == nix_err_NIX_OK || err == nix_err_NIX_ERR_UNKNOWN,
|
||||
"nix_flake_settings_add_to_eval_state_builder returned unexpected error \
|
||||
code: {err}"
|
||||
err == NixErr::Ok || err == NixErr::Unknown,
|
||||
"nix_flake_settings_add_to_eval_state_builder returned unexpected error code: {err}"
|
||||
);
|
||||
|
||||
nix_flake_settings_free(settings);
|
||||
|
|
|
|||
|
|
@ -3,9 +3,10 @@
|
|||
|
||||
use std::ffi::CString;
|
||||
|
||||
use nixide_sys::*;
|
||||
use serial_test::serial;
|
||||
|
||||
use nixide_sys::*;
|
||||
|
||||
#[test]
|
||||
#[serial]
|
||||
fn value_reference_counting() {
|
||||
|
|
@ -14,13 +15,13 @@ fn value_reference_counting() {
|
|||
assert!(!ctx.is_null());
|
||||
|
||||
let err = nix_libutil_init(ctx);
|
||||
assert_eq!(err, nix_err_NIX_OK);
|
||||
assert_eq!(err, NixErr::Ok);
|
||||
|
||||
let err = nix_libstore_init(ctx);
|
||||
assert_eq!(err, nix_err_NIX_OK);
|
||||
assert_eq!(err, NixErr::Ok);
|
||||
|
||||
let err = nix_libexpr_init(ctx);
|
||||
assert_eq!(err, nix_err_NIX_OK);
|
||||
assert_eq!(err, NixErr::Ok);
|
||||
|
||||
let store = nix_store_open(ctx, std::ptr::null(), std::ptr::null_mut());
|
||||
assert!(!store.is_null());
|
||||
|
|
@ -29,7 +30,7 @@ fn value_reference_counting() {
|
|||
assert!(!builder.is_null());
|
||||
|
||||
let load_err = nix_eval_state_builder_load(ctx, builder);
|
||||
assert_eq!(load_err, nix_err_NIX_OK);
|
||||
assert_eq!(load_err, NixErr::Ok);
|
||||
|
||||
let state = nix_eval_state_build(ctx, builder);
|
||||
assert!(!state.is_null());
|
||||
|
|
@ -40,11 +41,11 @@ fn value_reference_counting() {
|
|||
|
||||
// Initialize with an integer
|
||||
let init_err = nix_init_int(ctx, value, 42);
|
||||
assert_eq!(init_err, nix_err_NIX_OK);
|
||||
assert_eq!(init_err, NixErr::Ok);
|
||||
|
||||
// Test value-specific reference counting
|
||||
let incref_err = nix_value_incref(ctx, value);
|
||||
assert_eq!(incref_err, nix_err_NIX_OK);
|
||||
assert_eq!(incref_err, NixErr::Ok);
|
||||
|
||||
// Value should still be valid after increment
|
||||
let int_val = nix_get_int(ctx, value);
|
||||
|
|
@ -52,7 +53,7 @@ fn value_reference_counting() {
|
|||
|
||||
// Test decrement
|
||||
let decref_err = nix_value_decref(ctx, value);
|
||||
assert_eq!(decref_err, nix_err_NIX_OK);
|
||||
assert_eq!(decref_err, NixErr::Ok);
|
||||
|
||||
// Value should still be valid (original reference still exists)
|
||||
let int_val2 = nix_get_int(ctx, value);
|
||||
|
|
@ -60,7 +61,7 @@ fn value_reference_counting() {
|
|||
|
||||
// Final decrement (should not crash)
|
||||
let final_decref_err = nix_value_decref(ctx, value);
|
||||
assert_eq!(final_decref_err, nix_err_NIX_OK);
|
||||
assert_eq!(final_decref_err, NixErr::Ok);
|
||||
|
||||
// Clean up
|
||||
nix_state_free(state);
|
||||
|
|
@ -78,13 +79,13 @@ fn general_gc_reference_counting() {
|
|||
assert!(!ctx.is_null());
|
||||
|
||||
let err = nix_libutil_init(ctx);
|
||||
assert_eq!(err, nix_err_NIX_OK);
|
||||
assert_eq!(err, NixErr::Ok);
|
||||
|
||||
let err = nix_libstore_init(ctx);
|
||||
assert_eq!(err, nix_err_NIX_OK);
|
||||
assert_eq!(err, NixErr::Ok);
|
||||
|
||||
let err = nix_libexpr_init(ctx);
|
||||
assert_eq!(err, nix_err_NIX_OK);
|
||||
assert_eq!(err, NixErr::Ok);
|
||||
|
||||
let store = nix_store_open(ctx, std::ptr::null(), std::ptr::null_mut());
|
||||
assert!(!store.is_null());
|
||||
|
|
@ -93,7 +94,7 @@ fn general_gc_reference_counting() {
|
|||
assert!(!builder.is_null());
|
||||
|
||||
let load_err = nix_eval_state_builder_load(ctx, builder);
|
||||
assert_eq!(load_err, nix_err_NIX_OK);
|
||||
assert_eq!(load_err, NixErr::Ok);
|
||||
|
||||
let state = nix_eval_state_build(ctx, builder);
|
||||
assert!(!state.is_null());
|
||||
|
|
@ -107,19 +108,19 @@ fn general_gc_reference_counting() {
|
|||
value,
|
||||
CString::new("test string for GC").unwrap().as_ptr(),
|
||||
);
|
||||
assert_eq!(init_err, nix_err_NIX_OK);
|
||||
assert_eq!(init_err, NixErr::Ok);
|
||||
|
||||
// Test general GC reference counting
|
||||
let gc_incref_err = nix_gc_incref(ctx, value as *const ::std::os::raw::c_void);
|
||||
assert_eq!(gc_incref_err, nix_err_NIX_OK);
|
||||
assert_eq!(gc_incref_err, NixErr::Ok);
|
||||
|
||||
// Value should still be accessible
|
||||
let value_type = nix_get_type(ctx, value);
|
||||
assert_eq!(value_type, ValueType_NIX_TYPE_STRING);
|
||||
assert_eq!(value_type, ValueType::String);
|
||||
|
||||
// Test GC decrement
|
||||
let gc_decref_err = nix_gc_decref(ctx, value as *const ::std::os::raw::c_void);
|
||||
assert_eq!(gc_decref_err, nix_err_NIX_OK);
|
||||
assert_eq!(gc_decref_err, NixErr::Ok);
|
||||
|
||||
// Final cleanup
|
||||
nix_value_decref(ctx, value);
|
||||
|
|
@ -138,13 +139,13 @@ fn manual_garbage_collection() {
|
|||
assert!(!ctx.is_null());
|
||||
|
||||
let err = nix_libutil_init(ctx);
|
||||
assert_eq!(err, nix_err_NIX_OK);
|
||||
assert_eq!(err, NixErr::Ok);
|
||||
|
||||
let err = nix_libstore_init(ctx);
|
||||
assert_eq!(err, nix_err_NIX_OK);
|
||||
assert_eq!(err, NixErr::Ok);
|
||||
|
||||
let err = nix_libexpr_init(ctx);
|
||||
assert_eq!(err, nix_err_NIX_OK);
|
||||
assert_eq!(err, NixErr::Ok);
|
||||
|
||||
let store = nix_store_open(ctx, std::ptr::null(), std::ptr::null_mut());
|
||||
assert!(!store.is_null());
|
||||
|
|
@ -153,7 +154,7 @@ fn manual_garbage_collection() {
|
|||
assert!(!builder.is_null());
|
||||
|
||||
let load_err = nix_eval_state_builder_load(ctx, builder);
|
||||
assert_eq!(load_err, nix_err_NIX_OK);
|
||||
assert_eq!(load_err, NixErr::Ok);
|
||||
|
||||
let state = nix_eval_state_build(ctx, builder);
|
||||
assert!(!state.is_null());
|
||||
|
|
@ -164,7 +165,7 @@ fn manual_garbage_collection() {
|
|||
let value = nix_alloc_value(ctx, state);
|
||||
if !value.is_null() {
|
||||
let init_err = nix_init_int(ctx, value, i);
|
||||
if init_err == nix_err_NIX_OK {
|
||||
if init_err == NixErr::Ok {
|
||||
values.push(value);
|
||||
}
|
||||
}
|
||||
|
|
@ -196,13 +197,13 @@ fn value_copying_and_memory_management() {
|
|||
assert!(!ctx.is_null());
|
||||
|
||||
let err = nix_libutil_init(ctx);
|
||||
assert_eq!(err, nix_err_NIX_OK);
|
||||
assert_eq!(err, NixErr::Ok);
|
||||
|
||||
let err = nix_libstore_init(ctx);
|
||||
assert_eq!(err, nix_err_NIX_OK);
|
||||
assert_eq!(err, NixErr::Ok);
|
||||
|
||||
let err = nix_libexpr_init(ctx);
|
||||
assert_eq!(err, nix_err_NIX_OK);
|
||||
assert_eq!(err, NixErr::Ok);
|
||||
|
||||
let store = nix_store_open(ctx, std::ptr::null(), std::ptr::null_mut());
|
||||
assert!(!store.is_null());
|
||||
|
|
@ -211,7 +212,7 @@ fn value_copying_and_memory_management() {
|
|||
assert!(!builder.is_null());
|
||||
|
||||
let load_err = nix_eval_state_builder_load(ctx, builder);
|
||||
assert_eq!(load_err, nix_err_NIX_OK);
|
||||
assert_eq!(load_err, NixErr::Ok);
|
||||
|
||||
let state = nix_eval_state_build(ctx, builder);
|
||||
assert!(!state.is_null());
|
||||
|
|
@ -222,20 +223,20 @@ fn value_copying_and_memory_management() {
|
|||
|
||||
let test_string = CString::new("test string for copying").unwrap();
|
||||
let init_err = nix_init_string(ctx, original, test_string.as_ptr());
|
||||
assert_eq!(init_err, nix_err_NIX_OK);
|
||||
assert_eq!(init_err, NixErr::Ok);
|
||||
|
||||
// Create copy
|
||||
let copy = nix_alloc_value(ctx, state);
|
||||
assert!(!copy.is_null());
|
||||
|
||||
let copy_err = nix_copy_value(ctx, copy, original);
|
||||
assert_eq!(copy_err, nix_err_NIX_OK);
|
||||
assert_eq!(copy_err, NixErr::Ok);
|
||||
|
||||
// Verify copy has same type and can be accessed
|
||||
let original_type = nix_get_type(ctx, original);
|
||||
let copy_type = nix_get_type(ctx, copy);
|
||||
assert_eq!(original_type, copy_type);
|
||||
assert_eq!(copy_type, ValueType_NIX_TYPE_STRING);
|
||||
assert_eq!(copy_type, ValueType::String);
|
||||
|
||||
// Test string contents using callback
|
||||
unsafe extern "C" fn string_callback(
|
||||
|
|
@ -268,20 +269,22 @@ fn value_copying_and_memory_management() {
|
|||
|
||||
// Both should have the same string content
|
||||
assert_eq!(original_string, copy_string);
|
||||
assert!(original_string
|
||||
assert!(
|
||||
original_string
|
||||
.as_deref()
|
||||
.unwrap_or("")
|
||||
.contains("test string"));
|
||||
.contains("test string")
|
||||
);
|
||||
|
||||
// Test reference counting on both values
|
||||
let incref_orig = nix_value_incref(ctx, original);
|
||||
let incref_copy = nix_value_incref(ctx, copy);
|
||||
assert_eq!(incref_orig, nix_err_NIX_OK);
|
||||
assert_eq!(incref_copy, nix_err_NIX_OK);
|
||||
assert_eq!(incref_orig, NixErr::Ok);
|
||||
assert_eq!(incref_copy, NixErr::Ok);
|
||||
|
||||
// Values should still be accessible after increment
|
||||
assert_eq!(nix_get_type(ctx, original), ValueType_NIX_TYPE_STRING);
|
||||
assert_eq!(nix_get_type(ctx, copy), ValueType_NIX_TYPE_STRING);
|
||||
assert_eq!(nix_get_type(ctx, original), ValueType::String);
|
||||
assert_eq!(nix_get_type(ctx, copy), ValueType::String);
|
||||
|
||||
// Clean up with decrements
|
||||
nix_value_decref(ctx, original);
|
||||
|
|
@ -304,13 +307,13 @@ fn complex_value_memory_management() {
|
|||
assert!(!ctx.is_null());
|
||||
|
||||
let err = nix_libutil_init(ctx);
|
||||
assert_eq!(err, nix_err_NIX_OK);
|
||||
assert_eq!(err, NixErr::Ok);
|
||||
|
||||
let err = nix_libstore_init(ctx);
|
||||
assert_eq!(err, nix_err_NIX_OK);
|
||||
assert_eq!(err, NixErr::Ok);
|
||||
|
||||
let err = nix_libexpr_init(ctx);
|
||||
assert_eq!(err, nix_err_NIX_OK);
|
||||
assert_eq!(err, NixErr::Ok);
|
||||
|
||||
let store = nix_store_open(ctx, std::ptr::null(), std::ptr::null_mut());
|
||||
assert!(!store.is_null());
|
||||
|
|
@ -319,7 +322,7 @@ fn complex_value_memory_management() {
|
|||
assert!(!builder.is_null());
|
||||
|
||||
let load_err = nix_eval_state_builder_load(ctx, builder);
|
||||
assert_eq!(load_err, nix_err_NIX_OK);
|
||||
assert_eq!(load_err, NixErr::Ok);
|
||||
|
||||
let state = nix_eval_state_build(ctx, builder);
|
||||
assert!(!state.is_null());
|
||||
|
|
@ -343,7 +346,7 @@ fn complex_value_memory_management() {
|
|||
let _ = nix_init_string(ctx, val1, name_str.as_ptr());
|
||||
|
||||
let insert_err1 = nix_bindings_builder_insert(ctx, bindings_builder1, key1.as_ptr(), val1);
|
||||
assert_eq!(insert_err1, nix_err_NIX_OK);
|
||||
assert_eq!(insert_err1, NixErr::Ok);
|
||||
|
||||
let key2 = CString::new("value").unwrap();
|
||||
let val2 = nix_alloc_value(ctx, state);
|
||||
|
|
@ -351,14 +354,14 @@ fn complex_value_memory_management() {
|
|||
let _ = nix_init_int(ctx, val2, 42);
|
||||
|
||||
let insert_err2 = nix_bindings_builder_insert(ctx, bindings_builder1, key2.as_ptr(), val2);
|
||||
assert_eq!(insert_err2, nix_err_NIX_OK);
|
||||
assert_eq!(insert_err2, NixErr::Ok);
|
||||
|
||||
let make_attrs_err1 = nix_make_attrs(ctx, attrs1, bindings_builder1);
|
||||
assert_eq!(make_attrs_err1, nix_err_NIX_OK);
|
||||
assert_eq!(make_attrs_err1, NixErr::Ok);
|
||||
|
||||
// Insert first attrs into list
|
||||
let list_insert_err1 = nix_list_builder_insert(ctx, list_builder, 0, attrs1);
|
||||
assert_eq!(list_insert_err1, nix_err_NIX_OK);
|
||||
assert_eq!(list_insert_err1, NixErr::Ok);
|
||||
|
||||
// Create second element
|
||||
let attrs2 = nix_alloc_value(ctx, state);
|
||||
|
|
@ -374,23 +377,23 @@ fn complex_value_memory_management() {
|
|||
let _ = nix_init_string(ctx, val3, data_str.as_ptr());
|
||||
|
||||
let insert_err3 = nix_bindings_builder_insert(ctx, bindings_builder2, key3.as_ptr(), val3);
|
||||
assert_eq!(insert_err3, nix_err_NIX_OK);
|
||||
assert_eq!(insert_err3, NixErr::Ok);
|
||||
|
||||
let make_attrs_err2 = nix_make_attrs(ctx, attrs2, bindings_builder2);
|
||||
assert_eq!(make_attrs_err2, nix_err_NIX_OK);
|
||||
assert_eq!(make_attrs_err2, NixErr::Ok);
|
||||
|
||||
let list_insert_err2 = nix_list_builder_insert(ctx, list_builder, 1, attrs2);
|
||||
assert_eq!(list_insert_err2, nix_err_NIX_OK);
|
||||
assert_eq!(list_insert_err2, NixErr::Ok);
|
||||
|
||||
// Create final list
|
||||
let final_list = nix_alloc_value(ctx, state);
|
||||
assert!(!final_list.is_null());
|
||||
|
||||
let make_list_err = nix_make_list(ctx, list_builder, final_list);
|
||||
assert_eq!(make_list_err, nix_err_NIX_OK);
|
||||
assert_eq!(make_list_err, NixErr::Ok);
|
||||
|
||||
// Test the complex structure
|
||||
assert_eq!(nix_get_type(ctx, final_list), ValueType_NIX_TYPE_LIST);
|
||||
assert_eq!(nix_get_type(ctx, final_list), ValueType::List);
|
||||
assert_eq!(nix_get_list_size(ctx, final_list), 2);
|
||||
|
||||
// Access nested elements
|
||||
|
|
@ -398,19 +401,19 @@ fn complex_value_memory_management() {
|
|||
let elem1 = nix_get_list_byidx(ctx, final_list, state, 1);
|
||||
assert!(!elem0.is_null() && !elem1.is_null());
|
||||
|
||||
assert_eq!(nix_get_type(ctx, elem0), ValueType_NIX_TYPE_ATTRS);
|
||||
assert_eq!(nix_get_type(ctx, elem1), ValueType_NIX_TYPE_ATTRS);
|
||||
assert_eq!(nix_get_type(ctx, elem0), ValueType::Attrs);
|
||||
assert_eq!(nix_get_type(ctx, elem1), ValueType::Attrs);
|
||||
|
||||
// Test memory management with deep copying
|
||||
let copied_list = nix_alloc_value(ctx, state);
|
||||
assert!(!copied_list.is_null());
|
||||
|
||||
let copy_err = nix_copy_value(ctx, copied_list, final_list);
|
||||
assert_eq!(copy_err, nix_err_NIX_OK);
|
||||
assert_eq!(copy_err, NixErr::Ok);
|
||||
|
||||
// Force deep evaluation on copy
|
||||
let deep_force_err = nix_value_force_deep(ctx, state, copied_list);
|
||||
assert_eq!(deep_force_err, nix_err_NIX_OK);
|
||||
assert_eq!(deep_force_err, NixErr::Ok);
|
||||
|
||||
// Both should still be accessible
|
||||
assert_eq!(nix_get_list_size(ctx, final_list), 2);
|
||||
|
|
@ -443,34 +446,28 @@ fn memory_management_error_conditions() {
|
|||
|
||||
// XXX: May succeed or fail depending on implementation. We can't really
|
||||
// know, so assert both.
|
||||
assert!(null_incref_err == nix_err_NIX_OK || null_incref_err == nix_err_NIX_ERR_UNKNOWN);
|
||||
assert!(null_incref_err == NixErr::Ok || null_incref_err == NixErr::Unknown);
|
||||
|
||||
let null_decref_err = nix_gc_decref(ctx, std::ptr::null() as *const ::std::os::raw::c_void);
|
||||
assert!(null_decref_err == nix_err_NIX_OK || null_decref_err == nix_err_NIX_ERR_UNKNOWN);
|
||||
assert!(null_decref_err == NixErr::Ok || null_decref_err == NixErr::Unknown);
|
||||
|
||||
let null_value_incref_err = nix_value_incref(ctx, std::ptr::null_mut());
|
||||
// Some Nix APIs gracefully handle null pointers and return OK
|
||||
assert!(
|
||||
null_value_incref_err == nix_err_NIX_OK
|
||||
|| null_value_incref_err == nix_err_NIX_ERR_UNKNOWN
|
||||
);
|
||||
assert!(null_value_incref_err == NixErr::Ok || null_value_incref_err == NixErr::Unknown);
|
||||
|
||||
let null_value_decref_err = nix_value_decref(ctx, std::ptr::null_mut());
|
||||
// Some Nix APIs gracefully handle null pointers and return OK
|
||||
assert!(
|
||||
null_value_decref_err == nix_err_NIX_OK
|
||||
|| null_value_decref_err == nix_err_NIX_ERR_UNKNOWN
|
||||
);
|
||||
assert!(null_value_decref_err == NixErr::Ok || null_value_decref_err == NixErr::Unknown);
|
||||
|
||||
// Test copy with NULL values
|
||||
let err = nix_libutil_init(ctx);
|
||||
assert_eq!(err, nix_err_NIX_OK);
|
||||
assert_eq!(err, NixErr::Ok);
|
||||
|
||||
let err = nix_libstore_init(ctx);
|
||||
assert_eq!(err, nix_err_NIX_OK);
|
||||
assert_eq!(err, NixErr::Ok);
|
||||
|
||||
let err = nix_libexpr_init(ctx);
|
||||
assert_eq!(err, nix_err_NIX_OK);
|
||||
assert_eq!(err, NixErr::Ok);
|
||||
|
||||
let store = nix_store_open(ctx, std::ptr::null(), std::ptr::null_mut());
|
||||
assert!(!store.is_null());
|
||||
|
|
@ -479,7 +476,7 @@ fn memory_management_error_conditions() {
|
|||
assert!(!builder.is_null());
|
||||
|
||||
let load_err = nix_eval_state_builder_load(ctx, builder);
|
||||
assert_eq!(load_err, nix_err_NIX_OK);
|
||||
assert_eq!(load_err, NixErr::Ok);
|
||||
|
||||
let state = nix_eval_state_build(ctx, builder);
|
||||
assert!(!state.is_null());
|
||||
|
|
@ -489,10 +486,10 @@ fn memory_management_error_conditions() {
|
|||
|
||||
// Test copying to/from NULL
|
||||
let copy_from_null_err = nix_copy_value(ctx, valid_value, std::ptr::null_mut());
|
||||
assert_ne!(copy_from_null_err, nix_err_NIX_OK);
|
||||
assert_ne!(copy_from_null_err, NixErr::Ok);
|
||||
|
||||
let copy_to_null_err = nix_copy_value(ctx, std::ptr::null_mut(), valid_value);
|
||||
assert_ne!(copy_to_null_err, nix_err_NIX_OK);
|
||||
assert_ne!(copy_to_null_err, NixErr::Ok);
|
||||
|
||||
// Clean up
|
||||
nix_value_decref(ctx, valid_value);
|
||||
|
|
|
|||
|
|
@ -1,13 +1,12 @@
|
|||
#![cfg(feature = "nix-expr-c")]
|
||||
#![cfg(test)]
|
||||
|
||||
use std::{
|
||||
ffi::CString,
|
||||
sync::atomic::{AtomicU32, Ordering},
|
||||
};
|
||||
use std::ffi::CString;
|
||||
use std::sync::atomic::{AtomicU32, Ordering};
|
||||
|
||||
use serial_test::serial;
|
||||
|
||||
use nixide_sys::*;
|
||||
use serial_test::serial;
|
||||
|
||||
#[derive(Debug)]
|
||||
struct TestPrimOpData {
|
||||
|
|
@ -18,10 +17,10 @@ struct TestPrimOpData {
|
|||
// Simple PrimOp that adds 1 to an integer argument
|
||||
unsafe extern "C" fn add_one_primop(
|
||||
user_data: *mut ::std::os::raw::c_void,
|
||||
context: *mut nix_c_context,
|
||||
context: *mut NixCContext,
|
||||
state: *mut EvalState,
|
||||
args: *mut *mut nix_value,
|
||||
ret: *mut nix_value,
|
||||
args: *mut *mut NixValue,
|
||||
ret: *mut NixValue,
|
||||
) {
|
||||
if user_data.is_null()
|
||||
|| context.is_null()
|
||||
|
|
@ -32,7 +31,7 @@ unsafe extern "C" fn add_one_primop(
|
|||
let _ = unsafe {
|
||||
nix_set_err_msg(
|
||||
context,
|
||||
nix_err_NIX_ERR_UNKNOWN,
|
||||
NixErr::Unknown,
|
||||
b"Null pointer in add_one_primop\0".as_ptr() as *const _,
|
||||
)
|
||||
};
|
||||
|
|
@ -48,7 +47,7 @@ unsafe extern "C" fn add_one_primop(
|
|||
let _ = unsafe {
|
||||
nix_set_err_msg(
|
||||
context,
|
||||
nix_err_NIX_ERR_UNKNOWN,
|
||||
NixErr::Unknown,
|
||||
b"Missing argument in add_one_primop\0".as_ptr() as *const _,
|
||||
)
|
||||
};
|
||||
|
|
@ -56,16 +55,16 @@ unsafe extern "C" fn add_one_primop(
|
|||
}
|
||||
|
||||
// Force evaluation of argument
|
||||
if unsafe { nix_value_force(context, state, arg) } != nix_err_NIX_OK {
|
||||
if unsafe { nix_value_force(context, state, arg) } != NixErr::Ok {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if argument is integer
|
||||
if unsafe { nix_get_type(context, arg) } != ValueType_NIX_TYPE_INT {
|
||||
if unsafe { nix_get_type(context, arg) } != ValueType::Int {
|
||||
let _ = unsafe {
|
||||
nix_set_err_msg(
|
||||
context,
|
||||
nix_err_NIX_ERR_UNKNOWN,
|
||||
NixErr::Unknown,
|
||||
b"Expected integer argument in add_one_primop\0".as_ptr() as *const _,
|
||||
)
|
||||
};
|
||||
|
|
@ -83,10 +82,10 @@ unsafe extern "C" fn add_one_primop(
|
|||
// PrimOp that returns a constant string
|
||||
unsafe extern "C" fn hello_world_primop(
|
||||
_user_data: *mut ::std::os::raw::c_void,
|
||||
context: *mut nix_c_context,
|
||||
context: *mut NixCContext,
|
||||
_state: *mut EvalState,
|
||||
_args: *mut *mut nix_value,
|
||||
ret: *mut nix_value,
|
||||
_args: *mut *mut NixValue,
|
||||
ret: *mut NixValue,
|
||||
) {
|
||||
let hello = CString::new("Hello from Rust PrimOp!").unwrap();
|
||||
let _ = unsafe { nix_init_string(context, ret, hello.as_ptr()) };
|
||||
|
|
@ -95,10 +94,10 @@ unsafe extern "C" fn hello_world_primop(
|
|||
// PrimOp that takes multiple arguments and concatenates them
|
||||
unsafe extern "C" fn concat_strings_primop(
|
||||
_user_data: *mut ::std::os::raw::c_void,
|
||||
context: *mut nix_c_context,
|
||||
context: *mut NixCContext,
|
||||
state: *mut EvalState,
|
||||
args: *mut *mut nix_value,
|
||||
ret: *mut nix_value,
|
||||
args: *mut *mut NixValue,
|
||||
ret: *mut NixValue,
|
||||
) {
|
||||
if context.is_null() || state.is_null() || args.is_null() || ret.is_null() {
|
||||
return;
|
||||
|
|
@ -113,7 +112,7 @@ unsafe extern "C" fn concat_strings_primop(
|
|||
let _ = unsafe {
|
||||
nix_set_err_msg(
|
||||
context,
|
||||
nix_err_NIX_ERR_UNKNOWN,
|
||||
NixErr::Unknown,
|
||||
b"Missing argument in concat_strings_primop\0".as_ptr() as *const _,
|
||||
)
|
||||
};
|
||||
|
|
@ -121,15 +120,15 @@ unsafe extern "C" fn concat_strings_primop(
|
|||
}
|
||||
|
||||
// Force evaluation
|
||||
if unsafe { nix_value_force(context, state, arg) } != nix_err_NIX_OK {
|
||||
if unsafe { nix_value_force(context, state, arg) } != NixErr::Ok {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if it's a string
|
||||
if unsafe { nix_get_type(context, arg) } != ValueType_NIX_TYPE_STRING {
|
||||
if unsafe { nix_get_type(context, arg) } != ValueType::String {
|
||||
let _ = unsafe {
|
||||
static ITEMS: &[u8] = b"Expected string argument in concat_strings_primop\0";
|
||||
nix_set_err_msg(context, nix_err_NIX_ERR_UNKNOWN, ITEMS.as_ptr() as *const _)
|
||||
nix_set_err_msg(context, NixErr::Unknown, ITEMS.as_ptr() as *const _)
|
||||
};
|
||||
return;
|
||||
}
|
||||
|
|
@ -168,13 +167,13 @@ fn primop_allocation_and_registration() {
|
|||
assert!(!ctx.is_null());
|
||||
|
||||
let err = nix_libutil_init(ctx);
|
||||
assert_eq!(err, nix_err_NIX_OK);
|
||||
assert_eq!(err, NixErr::Ok);
|
||||
|
||||
let err = nix_libstore_init(ctx);
|
||||
assert_eq!(err, nix_err_NIX_OK);
|
||||
assert_eq!(err, NixErr::Ok);
|
||||
|
||||
let err = nix_libexpr_init(ctx);
|
||||
assert_eq!(err, nix_err_NIX_OK);
|
||||
assert_eq!(err, NixErr::Ok);
|
||||
|
||||
let store = nix_store_open(ctx, std::ptr::null(), std::ptr::null_mut());
|
||||
assert!(!store.is_null());
|
||||
|
|
@ -183,7 +182,7 @@ fn primop_allocation_and_registration() {
|
|||
assert!(!builder.is_null());
|
||||
|
||||
let load_err = nix_eval_state_builder_load(ctx, builder);
|
||||
assert_eq!(load_err, nix_err_NIX_OK);
|
||||
assert_eq!(load_err, NixErr::Ok);
|
||||
|
||||
let state = nix_eval_state_build(ctx, builder);
|
||||
assert!(!state.is_null());
|
||||
|
|
@ -220,7 +219,7 @@ fn primop_allocation_and_registration() {
|
|||
let register_err = nix_register_primop(ctx, primop);
|
||||
// Registration may fail in some environments, but allocation should work
|
||||
assert!(
|
||||
register_err == nix_err_NIX_OK || register_err == nix_err_NIX_ERR_UNKNOWN,
|
||||
register_err == NixErr::Ok || register_err == NixErr::Unknown,
|
||||
"Unexpected error code: {register_err}"
|
||||
);
|
||||
|
||||
|
|
@ -229,7 +228,7 @@ fn primop_allocation_and_registration() {
|
|||
assert!(!primop_value.is_null());
|
||||
|
||||
let init_err = nix_init_primop(ctx, primop_value, primop);
|
||||
assert_eq!(init_err, nix_err_NIX_OK);
|
||||
assert_eq!(init_err, NixErr::Ok);
|
||||
|
||||
// Clean up value
|
||||
nix_value_decref(ctx, primop_value);
|
||||
|
|
@ -252,13 +251,13 @@ fn primop_function_call() {
|
|||
assert!(!ctx.is_null());
|
||||
|
||||
let err = nix_libutil_init(ctx);
|
||||
assert_eq!(err, nix_err_NIX_OK);
|
||||
assert_eq!(err, NixErr::Ok);
|
||||
|
||||
let err = nix_libstore_init(ctx);
|
||||
assert_eq!(err, nix_err_NIX_OK);
|
||||
assert_eq!(err, NixErr::Ok);
|
||||
|
||||
let err = nix_libexpr_init(ctx);
|
||||
assert_eq!(err, nix_err_NIX_OK);
|
||||
assert_eq!(err, NixErr::Ok);
|
||||
|
||||
let store = nix_store_open(ctx, std::ptr::null(), std::ptr::null_mut());
|
||||
assert!(!store.is_null());
|
||||
|
|
@ -267,7 +266,7 @@ fn primop_function_call() {
|
|||
assert!(!builder.is_null());
|
||||
|
||||
let load_err = nix_eval_state_builder_load(ctx, builder);
|
||||
assert_eq!(load_err, nix_err_NIX_OK);
|
||||
assert_eq!(load_err, NixErr::Ok);
|
||||
|
||||
let state = nix_eval_state_build(ctx, builder);
|
||||
assert!(!state.is_null());
|
||||
|
|
@ -300,21 +299,21 @@ fn primop_function_call() {
|
|||
assert!(!primop_value.is_null());
|
||||
|
||||
let init_err = nix_init_primop(ctx, primop_value, hello_primop);
|
||||
assert_eq!(init_err, nix_err_NIX_OK);
|
||||
assert_eq!(init_err, NixErr::Ok);
|
||||
|
||||
// Call the PrimOp (no arguments)
|
||||
let result = nix_alloc_value(ctx, state);
|
||||
assert!(!result.is_null());
|
||||
|
||||
let call_err = nix_value_call(ctx, state, primop_value, std::ptr::null_mut(), result);
|
||||
if call_err == nix_err_NIX_OK {
|
||||
if call_err == NixErr::Ok {
|
||||
// Force the result
|
||||
let force_err = nix_value_force(ctx, state, result);
|
||||
assert_eq!(force_err, nix_err_NIX_OK);
|
||||
assert_eq!(force_err, NixErr::Ok);
|
||||
|
||||
// Check if result is a string
|
||||
let result_type = nix_get_type(ctx, result);
|
||||
if result_type == ValueType_NIX_TYPE_STRING {
|
||||
if result_type == ValueType::String {
|
||||
// Get string value
|
||||
unsafe extern "C" fn string_callback(
|
||||
start: *const ::std::os::raw::c_char,
|
||||
|
|
@ -337,10 +336,12 @@ fn primop_function_call() {
|
|||
);
|
||||
|
||||
// Verify we got the expected string
|
||||
assert!(string_result
|
||||
assert!(
|
||||
string_result
|
||||
.as_deref()
|
||||
.unwrap_or("")
|
||||
.contains("Hello from Rust"));
|
||||
.contains("Hello from Rust")
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -365,13 +366,13 @@ fn primop_with_arguments() {
|
|||
assert!(!ctx.is_null());
|
||||
|
||||
let err = nix_libutil_init(ctx);
|
||||
assert_eq!(err, nix_err_NIX_OK);
|
||||
assert_eq!(err, NixErr::Ok);
|
||||
|
||||
let err = nix_libstore_init(ctx);
|
||||
assert_eq!(err, nix_err_NIX_OK);
|
||||
assert_eq!(err, NixErr::Ok);
|
||||
|
||||
let err = nix_libexpr_init(ctx);
|
||||
assert_eq!(err, nix_err_NIX_OK);
|
||||
assert_eq!(err, NixErr::Ok);
|
||||
|
||||
let store = nix_store_open(ctx, std::ptr::null(), std::ptr::null_mut());
|
||||
assert!(!store.is_null());
|
||||
|
|
@ -380,7 +381,7 @@ fn primop_with_arguments() {
|
|||
assert!(!builder.is_null());
|
||||
|
||||
let load_err = nix_eval_state_builder_load(ctx, builder);
|
||||
assert_eq!(load_err, nix_err_NIX_OK);
|
||||
assert_eq!(load_err, NixErr::Ok);
|
||||
|
||||
let state = nix_eval_state_build(ctx, builder);
|
||||
assert!(!state.is_null());
|
||||
|
|
@ -417,28 +418,28 @@ fn primop_with_arguments() {
|
|||
assert!(!primop_value.is_null());
|
||||
|
||||
let init_err = nix_init_primop(ctx, primop_value, add_primop);
|
||||
assert_eq!(init_err, nix_err_NIX_OK);
|
||||
assert_eq!(init_err, NixErr::Ok);
|
||||
|
||||
// Create an integer argument
|
||||
let arg_value = nix_alloc_value(ctx, state);
|
||||
assert!(!arg_value.is_null());
|
||||
|
||||
let init_arg_err = nix_init_int(ctx, arg_value, 42);
|
||||
assert_eq!(init_arg_err, nix_err_NIX_OK);
|
||||
assert_eq!(init_arg_err, NixErr::Ok);
|
||||
|
||||
// Call the PrimOp with the argument
|
||||
let result = nix_alloc_value(ctx, state);
|
||||
assert!(!result.is_null());
|
||||
|
||||
let call_err = nix_value_call(ctx, state, primop_value, arg_value, result);
|
||||
if call_err == nix_err_NIX_OK {
|
||||
if call_err == NixErr::Ok {
|
||||
// Force the result
|
||||
let force_err = nix_value_force(ctx, state, result);
|
||||
assert_eq!(force_err, nix_err_NIX_OK);
|
||||
assert_eq!(force_err, NixErr::Ok);
|
||||
|
||||
// Check if result is an integer
|
||||
let result_type = nix_get_type(ctx, result);
|
||||
if result_type == ValueType_NIX_TYPE_INT {
|
||||
if result_type == ValueType::Int {
|
||||
let result_value = nix_get_int(ctx, result);
|
||||
assert_eq!(result_value, 43); // 42 + 1
|
||||
|
||||
|
|
@ -471,13 +472,13 @@ fn primop_multi_argument() {
|
|||
assert!(!ctx.is_null());
|
||||
|
||||
let err = nix_libutil_init(ctx);
|
||||
assert_eq!(err, nix_err_NIX_OK);
|
||||
assert_eq!(err, NixErr::Ok);
|
||||
|
||||
let err = nix_libstore_init(ctx);
|
||||
assert_eq!(err, nix_err_NIX_OK);
|
||||
assert_eq!(err, NixErr::Ok);
|
||||
|
||||
let err = nix_libexpr_init(ctx);
|
||||
assert_eq!(err, nix_err_NIX_OK);
|
||||
assert_eq!(err, NixErr::Ok);
|
||||
|
||||
let store = nix_store_open(ctx, std::ptr::null(), std::ptr::null_mut());
|
||||
assert!(!store.is_null());
|
||||
|
|
@ -486,7 +487,7 @@ fn primop_multi_argument() {
|
|||
assert!(!builder.is_null());
|
||||
|
||||
let load_err = nix_eval_state_builder_load(ctx, builder);
|
||||
assert_eq!(load_err, nix_err_NIX_OK);
|
||||
assert_eq!(load_err, NixErr::Ok);
|
||||
|
||||
let state = nix_eval_state_build(ctx, builder);
|
||||
assert!(!state.is_null());
|
||||
|
|
@ -516,7 +517,7 @@ fn primop_multi_argument() {
|
|||
assert!(!primop_value.is_null());
|
||||
|
||||
let init_err = nix_init_primop(ctx, primop_value, concat_primop);
|
||||
assert_eq!(init_err, nix_err_NIX_OK);
|
||||
assert_eq!(init_err, NixErr::Ok);
|
||||
|
||||
// Create string arguments
|
||||
let arg1 = nix_alloc_value(ctx, state);
|
||||
|
|
@ -528,8 +529,8 @@ fn primop_multi_argument() {
|
|||
|
||||
let init_arg1_err = nix_init_string(ctx, arg1, hello_cstr.as_ptr());
|
||||
let init_arg2_err = nix_init_string(ctx, arg2, world_cstr.as_ptr());
|
||||
assert_eq!(init_arg1_err, nix_err_NIX_OK);
|
||||
assert_eq!(init_arg2_err, nix_err_NIX_OK);
|
||||
assert_eq!(init_arg1_err, NixErr::Ok);
|
||||
assert_eq!(init_arg2_err, NixErr::Ok);
|
||||
|
||||
// Test multi-argument call using nix_value_call_multi
|
||||
let mut args = [arg1, arg2];
|
||||
|
|
@ -538,14 +539,14 @@ fn primop_multi_argument() {
|
|||
|
||||
let call_err =
|
||||
nix_value_call_multi(ctx, state, primop_value, 2, args.as_mut_ptr(), result);
|
||||
if call_err == nix_err_NIX_OK {
|
||||
if call_err == NixErr::Ok {
|
||||
// Force the result
|
||||
let force_err = nix_value_force(ctx, state, result);
|
||||
assert_eq!(force_err, nix_err_NIX_OK);
|
||||
assert_eq!(force_err, NixErr::Ok);
|
||||
|
||||
// Check if result is a string
|
||||
let result_type = nix_get_type(ctx, result);
|
||||
if result_type == ValueType_NIX_TYPE_STRING {
|
||||
if result_type == ValueType::String {
|
||||
unsafe extern "C" fn string_callback(
|
||||
start: *const ::std::os::raw::c_char,
|
||||
n: ::std::os::raw::c_uint,
|
||||
|
|
@ -592,13 +593,13 @@ fn primop_error_handling() {
|
|||
assert!(!ctx.is_null());
|
||||
|
||||
let err = nix_libutil_init(ctx);
|
||||
assert_eq!(err, nix_err_NIX_OK);
|
||||
assert_eq!(err, NixErr::Ok);
|
||||
|
||||
let err = nix_libstore_init(ctx);
|
||||
assert_eq!(err, nix_err_NIX_OK);
|
||||
assert_eq!(err, NixErr::Ok);
|
||||
|
||||
let err = nix_libexpr_init(ctx);
|
||||
assert_eq!(err, nix_err_NIX_OK);
|
||||
assert_eq!(err, NixErr::Ok);
|
||||
|
||||
let store = nix_store_open(ctx, std::ptr::null(), std::ptr::null_mut());
|
||||
assert!(!store.is_null());
|
||||
|
|
@ -607,7 +608,7 @@ fn primop_error_handling() {
|
|||
assert!(!builder.is_null());
|
||||
|
||||
let load_err = nix_eval_state_builder_load(ctx, builder);
|
||||
assert_eq!(load_err, nix_err_NIX_OK);
|
||||
assert_eq!(load_err, NixErr::Ok);
|
||||
|
||||
let state = nix_eval_state_build(ctx, builder);
|
||||
assert!(!state.is_null());
|
||||
|
|
|
|||
|
|
@ -1,10 +1,12 @@
|
|||
#![cfg(feature = "nix-store-c")]
|
||||
#![cfg(test)]
|
||||
|
||||
use std::{ffi::CString, ptr};
|
||||
use std::ffi::CString;
|
||||
use std::ptr;
|
||||
|
||||
use serial_test::serial;
|
||||
|
||||
use nixide_sys::*;
|
||||
use serial_test::serial;
|
||||
|
||||
#[test]
|
||||
#[serial]
|
||||
|
|
@ -13,7 +15,7 @@ fn libstore_init_and_open_free() {
|
|||
let ctx = nix_c_context_create();
|
||||
assert!(!ctx.is_null());
|
||||
let err = nix_libstore_init(ctx);
|
||||
assert_eq!(err, nix_err_NIX_OK);
|
||||
assert_eq!(err, NixErr::Ok);
|
||||
|
||||
// Open the default store (NULL URI, NULL params)
|
||||
let store = nix_store_open(ctx, ptr::null(), ptr::null_mut());
|
||||
|
|
@ -32,7 +34,7 @@ fn parse_and_clone_free_store_path() {
|
|||
let ctx = nix_c_context_create();
|
||||
assert!(!ctx.is_null());
|
||||
let err = nix_libstore_init(ctx);
|
||||
assert_eq!(err, nix_err_NIX_OK);
|
||||
assert_eq!(err, NixErr::Ok);
|
||||
|
||||
let store = nix_store_open(ctx, ptr::null(), ptr::null_mut());
|
||||
assert!(!store.is_null());
|
||||
|
|
@ -74,14 +76,14 @@ fn store_get_uri_and_storedir() {
|
|||
let ctx = nix_c_context_create();
|
||||
assert!(!ctx.is_null());
|
||||
let err = nix_libstore_init(ctx);
|
||||
assert_eq!(err, nix_err_NIX_OK);
|
||||
assert_eq!(err, NixErr::Ok);
|
||||
|
||||
let store = nix_store_open(ctx, ptr::null(), ptr::null_mut());
|
||||
assert!(!store.is_null());
|
||||
|
||||
let mut uri: Option<String> = None;
|
||||
let res = nix_store_get_uri(ctx, store, Some(string_callback), (&raw mut uri).cast());
|
||||
assert_eq!(res, nix_err_NIX_OK);
|
||||
assert_eq!(res, NixErr::Ok);
|
||||
assert!(uri.is_some());
|
||||
|
||||
let mut storedir: Option<String> = None;
|
||||
|
|
@ -91,7 +93,7 @@ fn store_get_uri_and_storedir() {
|
|||
Some(string_callback),
|
||||
(&raw mut storedir).cast(),
|
||||
);
|
||||
assert_eq!(res, nix_err_NIX_OK);
|
||||
assert_eq!(res, NixErr::Ok);
|
||||
assert!(storedir.is_some());
|
||||
|
||||
nix_store_free(store);
|
||||
|
|
@ -106,7 +108,7 @@ fn libstore_init_no_load_config() {
|
|||
let ctx = nix_c_context_create();
|
||||
assert!(!ctx.is_null());
|
||||
let err = nix_libstore_init_no_load_config(ctx);
|
||||
assert_eq!(err, nix_err_NIX_OK);
|
||||
assert_eq!(err, NixErr::Ok);
|
||||
nix_c_context_free(ctx);
|
||||
}
|
||||
}
|
||||
|
|
@ -129,7 +131,7 @@ fn store_is_valid_path_and_real_path() {
|
|||
let ctx = nix_c_context_create();
|
||||
assert!(!ctx.is_null());
|
||||
let err = nix_libstore_init(ctx);
|
||||
assert_eq!(err, nix_err_NIX_OK);
|
||||
assert_eq!(err, NixErr::Ok);
|
||||
|
||||
let store = nix_store_open(ctx, std::ptr::null(), std::ptr::null_mut());
|
||||
assert!(!store.is_null());
|
||||
|
|
@ -150,7 +152,7 @@ fn store_is_valid_path_and_real_path() {
|
|||
(&raw mut real_path).cast(),
|
||||
);
|
||||
// May fail, but should not crash
|
||||
assert!(res == nix_err_NIX_OK || res == nix_err_NIX_ERR_UNKNOWN);
|
||||
assert!(res == NixErr::Ok || res == NixErr::Unknown);
|
||||
nix_store_path_free(store_path);
|
||||
}
|
||||
|
||||
|
|
@ -177,7 +179,7 @@ fn store_path_name() {
|
|||
let ctx = nix_c_context_create();
|
||||
assert!(!ctx.is_null());
|
||||
let err = nix_libstore_init(ctx);
|
||||
assert_eq!(err, nix_err_NIX_OK);
|
||||
assert_eq!(err, NixErr::Ok);
|
||||
|
||||
let store = nix_store_open(ctx, std::ptr::null(), std::ptr::null_mut());
|
||||
assert!(!store.is_null());
|
||||
|
|
@ -215,7 +217,7 @@ fn store_get_version() {
|
|||
let ctx = nix_c_context_create();
|
||||
assert!(!ctx.is_null());
|
||||
let err = nix_libstore_init(ctx);
|
||||
assert_eq!(err, nix_err_NIX_OK);
|
||||
assert_eq!(err, NixErr::Ok);
|
||||
|
||||
let store = nix_store_open(ctx, std::ptr::null(), std::ptr::null_mut());
|
||||
assert!(!store.is_null());
|
||||
|
|
@ -223,7 +225,7 @@ fn store_get_version() {
|
|||
let mut version: Option<String> = None;
|
||||
let res =
|
||||
nix_store_get_version(ctx, store, Some(string_callback), (&raw mut version).cast());
|
||||
assert_eq!(res, nix_err_NIX_OK);
|
||||
assert_eq!(res, NixErr::Ok);
|
||||
// Version may be empty for dummy stores, but should not crash
|
||||
assert!(version.is_some());
|
||||
|
||||
|
|
@ -249,7 +251,7 @@ fn store_realise_and_copy_closure() {
|
|||
let ctx = nix_c_context_create();
|
||||
assert!(!ctx.is_null());
|
||||
let err = nix_libstore_init(ctx);
|
||||
assert_eq!(err, nix_err_NIX_OK);
|
||||
assert_eq!(err, NixErr::Ok);
|
||||
|
||||
let store = nix_store_open(ctx, std::ptr::null(), std::ptr::null_mut());
|
||||
assert!(!store.is_null());
|
||||
|
|
|
|||
|
|
@ -1,10 +1,12 @@
|
|||
#![cfg(feature = "nix-util-c")]
|
||||
#![cfg(test)]
|
||||
|
||||
use std::ffi::{CStr, CString};
|
||||
|
||||
use nixide_sys::*;
|
||||
use serial_test::serial;
|
||||
|
||||
use nixide_sys::*;
|
||||
|
||||
#[test]
|
||||
#[serial]
|
||||
fn context_create_and_free() {
|
||||
|
|
@ -22,7 +24,7 @@ fn libutil_init() {
|
|||
let ctx = nix_c_context_create();
|
||||
assert!(!ctx.is_null());
|
||||
let err = nix_libutil_init(ctx);
|
||||
assert_eq!(err, nix_err_NIX_OK);
|
||||
assert_eq!(err, NixErr::Ok);
|
||||
nix_c_context_free(ctx);
|
||||
}
|
||||
}
|
||||
|
|
@ -60,7 +62,7 @@ fn setting_set_and_get() {
|
|||
let ctx = nix_c_context_create();
|
||||
assert!(!ctx.is_null());
|
||||
let err = nix_libutil_init(ctx);
|
||||
assert_eq!(err, nix_err_NIX_OK);
|
||||
assert_eq!(err, NixErr::Ok);
|
||||
|
||||
// Set a setting (use a dummy/extra setting to avoid breaking global config)
|
||||
let key = CString::new("extra-test-setting").unwrap();
|
||||
|
|
@ -68,7 +70,7 @@ fn setting_set_and_get() {
|
|||
let set_err = nix_setting_set(ctx, key.as_ptr(), value.as_ptr());
|
||||
// Setting may not exist, but should not crash
|
||||
assert!(
|
||||
set_err == nix_err_NIX_OK || set_err == nix_err_NIX_ERR_KEY,
|
||||
set_err == NixErr::Ok || set_err == NixErr::Key,
|
||||
"Unexpected error code: {set_err}"
|
||||
);
|
||||
|
||||
|
|
@ -81,11 +83,11 @@ fn setting_set_and_get() {
|
|||
(&raw mut got).cast(),
|
||||
);
|
||||
assert!(
|
||||
get_err == nix_err_NIX_OK || get_err == nix_err_NIX_ERR_KEY,
|
||||
get_err == NixErr::Ok || get_err == NixErr::Key,
|
||||
"Unexpected error code: {get_err}"
|
||||
);
|
||||
// If OK, we should have gotten a value
|
||||
if get_err == nix_err_NIX_OK {
|
||||
if get_err == NixErr::Ok {
|
||||
assert_eq!(got.as_deref(), Some("test-value"));
|
||||
}
|
||||
|
||||
|
|
@ -111,16 +113,16 @@ fn error_handling_apis() {
|
|||
let ctx = nix_c_context_create();
|
||||
assert!(!ctx.is_null());
|
||||
let err = nix_libutil_init(ctx);
|
||||
assert_eq!(err, nix_err_NIX_OK);
|
||||
assert_eq!(err, NixErr::Ok);
|
||||
|
||||
// Set an error message
|
||||
let msg = CString::new("custom error message").unwrap();
|
||||
let set_err = nix_set_err_msg(ctx, nix_err_NIX_ERR_UNKNOWN, msg.as_ptr());
|
||||
assert_eq!(set_err, nix_err_NIX_ERR_UNKNOWN);
|
||||
let set_err = nix_set_err_msg(ctx, NixErr::Unknown, msg.as_ptr());
|
||||
assert_eq!(set_err, NixErr::Unknown);
|
||||
|
||||
// Get error code
|
||||
let code = nix_err_code(ctx);
|
||||
assert_eq!(code, nix_err_NIX_ERR_UNKNOWN);
|
||||
assert_eq!(code, NixErr::Unknown);
|
||||
|
||||
// Get error message
|
||||
let mut len: std::os::raw::c_uint = 0;
|
||||
|
|
@ -145,7 +147,7 @@ fn error_handling_apis() {
|
|||
// Clear error
|
||||
nix_clear_err(ctx);
|
||||
let code_after_clear = nix_err_code(ctx);
|
||||
assert_eq!(code_after_clear, nix_err_NIX_OK);
|
||||
assert_eq!(code_after_clear, NixErr::Ok);
|
||||
|
||||
nix_c_context_free(ctx);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -57,42 +57,29 @@ use crate::util::wrappers::AsInnerPtr;
|
|||
/// };
|
||||
/// ```
|
||||
///
|
||||
/// The [sys::nix_c_context] struct is laid out so that it can also be
|
||||
/// cast to a [sys::nix_err] to inspect directly:
|
||||
/// The [NixCContext] struct is laid out so that it can also be
|
||||
/// cast to a [sys::NixErr] to inspect directly:
|
||||
/// ```c
|
||||
/// assert(*(nix_err*)ctx == NIX_OK);
|
||||
/// ```
|
||||
///
|
||||
pub(crate) struct ErrorContext {
|
||||
inner: NonNull<sys::nix_c_context>,
|
||||
inner: NonNull<sys::NixCContext>,
|
||||
}
|
||||
|
||||
// impl Clone for ErrorContext {
|
||||
// fn clone(&self) -> Self {
|
||||
// let inner = self.inner.clone();
|
||||
//
|
||||
// wrap::nix_fn!(|ctx: &ErrorContext| unsafe {
|
||||
// sys::nix_gc_incref(ctx.as_ptr(), self.as_ptr() as *mut c_void);
|
||||
// })
|
||||
// .unwrap();
|
||||
//
|
||||
// Self { inner }
|
||||
// }
|
||||
// }
|
||||
|
||||
impl AsInnerPtr<sys::nix_c_context> for ErrorContext {
|
||||
impl AsInnerPtr<sys::NixCContext> for ErrorContext {
|
||||
#[inline]
|
||||
unsafe fn as_ptr(&self) -> *mut sys::nix_c_context {
|
||||
unsafe fn as_ptr(&self) -> *mut sys::NixCContext {
|
||||
self.inner.as_ptr()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
unsafe fn as_ref(&self) -> &sys::nix_c_context {
|
||||
unsafe fn as_ref(&self) -> &sys::NixCContext {
|
||||
unsafe { self.inner.as_ref() }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
unsafe fn as_mut(&mut self) -> &mut sys::nix_c_context {
|
||||
unsafe fn as_mut(&mut self) -> &mut sys::NixCContext {
|
||||
unsafe { self.inner.as_mut() }
|
||||
}
|
||||
}
|
||||
|
|
@ -100,11 +87,11 @@ impl AsInnerPtr<sys::nix_c_context> for ErrorContext {
|
|||
impl Into<NixideResult<()>> for &ErrorContext {
|
||||
/// # Panics
|
||||
///
|
||||
/// This function will panic in the event that `context.get_err() == Some(err) && err == sys::nix_err_NIX_OK`
|
||||
/// since `nixide::ErrorContext::get_err` is expected to return `None` to indicate `sys::nix_err_NIX_OK`.
|
||||
/// This function will panic in the event that `context.get_err() == Some(err) && err == sys::NixErr::NIX_OK`
|
||||
/// since `nixide::ErrorContext::get_err` is expected to return `None` to indicate `sys::NixErr::NIX_OK`.
|
||||
///
|
||||
/// This function will panic in the event that `value != sys::nix_err_NIX_OK`
|
||||
/// but that `context.get_code() == sys::nix_err_NIX_OK`
|
||||
/// This function will panic in the event that `value != sys::NixErr::NIX_OK`
|
||||
/// but that `context.get_code() == sys::NixErr::NIX_OK`
|
||||
///
|
||||
fn into(self) -> NixideResult<()> {
|
||||
let inner = match self.get_err() {
|
||||
|
|
@ -117,11 +104,11 @@ impl Into<NixideResult<()>> for &ErrorContext {
|
|||
};
|
||||
|
||||
let err = match inner {
|
||||
sys::nix_err_NIX_OK => unreachable!(),
|
||||
sys::NixErr::Ok => unreachable!(),
|
||||
|
||||
sys::nix_err_NIX_ERR_OVERFLOW => NixError::Overflow,
|
||||
sys::nix_err_NIX_ERR_KEY => NixError::KeyNotFound(None),
|
||||
sys::nix_err_NIX_ERR_NIX_ERROR => NixError::ExprEval {
|
||||
sys::NixErr::Overflow => NixError::Overflow,
|
||||
sys::NixErr::Key => NixError::KeyNotFound(None),
|
||||
sys::NixErr::NixError => NixError::ExprEval {
|
||||
name: self
|
||||
.get_nix_err_name()
|
||||
.unwrap_or_else(|| panic_issue_call_failed!()),
|
||||
|
|
@ -131,7 +118,7 @@ impl Into<NixideResult<()>> for &ErrorContext {
|
|||
.unwrap_or_else(|| panic_issue_call_failed!()),
|
||||
},
|
||||
|
||||
sys::nix_err_NIX_ERR_UNKNOWN => NixError::Unknown,
|
||||
sys::NixErr::Unknown => NixError::Unknown,
|
||||
err => NixError::Undocumented(err),
|
||||
};
|
||||
|
||||
|
|
@ -145,13 +132,13 @@ impl ErrorContext {
|
|||
/// # Errors
|
||||
///
|
||||
/// Returns an error if no memory can be allocated for
|
||||
/// the underlying [sys::nix_c_context] struct.
|
||||
/// the underlying [NixCContext] struct.
|
||||
///
|
||||
pub fn new() -> Self {
|
||||
match NonNull::new(unsafe { sys::nix_c_context_create() }) {
|
||||
Some(inner) => ErrorContext { inner },
|
||||
None => panic!(
|
||||
"[nixide] CRITICAL FAILURE: Out-Of-Memory condition reached - `sys::nix_c_context_create` allocation failed!"
|
||||
"[nixide] CRITICAL FAILURE: Out-Of-Memory condition reached - `NixCContext_create` allocation failed!"
|
||||
),
|
||||
}
|
||||
}
|
||||
|
|
@ -216,12 +203,12 @@ impl ErrorContext {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
/// Returns [None] if [self.code] is [sys::nix_err_NIX_OK], and [Some] otherwise.
|
||||
/// Returns [None] if [self.code] is [sys::NixErr::NIX_OK], and [Some] otherwise.
|
||||
///
|
||||
/// # Nix C++ API Internals
|
||||
///
|
||||
/// ```cpp
|
||||
/// nix_err nix_err_code(const nix_c_context * read_context)
|
||||
/// nix_err nix_err::code(const nix_c_context * read_context)
|
||||
/// {
|
||||
/// return read_context->last_err_code;
|
||||
/// }
|
||||
|
|
@ -229,19 +216,19 @@ impl ErrorContext {
|
|||
///
|
||||
/// This function **never fails**.
|
||||
///
|
||||
fn get_err(&self) -> Option<sys::nix_err> {
|
||||
fn get_err(&self) -> Option<sys::NixErr> {
|
||||
match unsafe { sys::nix_err_code(self.as_ptr()) } {
|
||||
sys::nix_err_NIX_OK => None,
|
||||
sys::NixErr::Ok => None,
|
||||
err => Some(err),
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns [None] if [self.code] is [sys::nix_err_NIX_OK], and [Some] otherwise.
|
||||
/// Returns [None] if [self.code] is [sys::NixErr::NIX_OK], and [Some] otherwise.
|
||||
///
|
||||
/// # Nix C++ API Internals
|
||||
///
|
||||
/// ```cpp
|
||||
/// const char * nix_err_msg(nix_c_context * context, const nix_c_context * read_context, unsigned int * n)
|
||||
/// const char * nix_err::msg(nix_c_context * context, const nix_c_context * read_context, unsigned int * n)
|
||||
/// {
|
||||
/// if (context)
|
||||
/// context->last_err_code = NIX_OK;
|
||||
|
|
@ -250,21 +237,21 @@ impl ErrorContext {
|
|||
/// *n = read_context->last_err->size();
|
||||
/// return read_context->last_err->c_str();
|
||||
/// }
|
||||
/// nix_set_err_msg(context, NIX_ERR_UNKNOWN, "No error message");
|
||||
/// nix_set_err_msg(context, NIX_ERR::UNKNOWN, "No error message");
|
||||
/// return nullptr;
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// # Note
|
||||
///
|
||||
/// On failure [sys::nix_err_name] does the following if the error
|
||||
/// has the error code [sys::nix_err_NIX_OK]:
|
||||
/// On failure [sys::NixErr::name] does the following if the error
|
||||
/// has the error code [sys::NixErr::NIX_OK]:
|
||||
/// ```cpp
|
||||
/// nix_set_err_msg(context, NIX_ERR_UNKNOWN, "No error message");
|
||||
/// nix_set_err_msg(context, NIX_ERR::UNKNOWN, "No error message");
|
||||
/// return nullptr;
|
||||
/// ```
|
||||
/// Hence we can just test whether the returned pointer is a `NULL` pointer,
|
||||
/// and avoid passing in a [sys::nix_c_context] struct.
|
||||
/// and avoid passing in a [NixCContext] struct.
|
||||
///
|
||||
fn get_msg(&self) -> Option<String> {
|
||||
// NOTE: an Err here only occurs when `self.get_code() == Ok(())`
|
||||
|
|
@ -281,13 +268,13 @@ impl ErrorContext {
|
|||
}
|
||||
}
|
||||
|
||||
/// Returns [None] if [self.code] is [sys::nix_err_NIX_OK], and [Some] otherwise.
|
||||
/// Returns [None] if [self.code] is [sys::NixErr::NIX_OK], and [Some] otherwise.
|
||||
///
|
||||
/// # Nix C++ API Internals
|
||||
///
|
||||
/// ```cpp
|
||||
/// // NOTE(nixide): the implementation of `nix_err_info_msg` is identical to `nix_err_name`
|
||||
/// nix_err nix_err_info_msg(
|
||||
/// // NOTE(nixide): the implementation of `nix_err::info_msg` is identical to `nix_err::name`
|
||||
/// nix_err nix_err::info_msg(
|
||||
/// nix_c_context * context,
|
||||
/// const nix_c_context * read_context,
|
||||
/// nix_get_string_callback callback,
|
||||
|
|
@ -295,16 +282,16 @@ impl ErrorContext {
|
|||
/// {
|
||||
/// if (context)
|
||||
/// context->last_err_code = NIX_OK;
|
||||
/// if (read_context->last_err_code != NIX_ERR_NIX_ERROR) {
|
||||
/// if (read_context->last_err_code != NIX_ERR::NIX_ERROR) {
|
||||
/// // NOTE(nixide): `nix_set_err_msg` throws a `nix::Error` exception if `context == nullptr`
|
||||
/// return nix_set_err_msg(context, NIX_ERR_UNKNOWN, "Last error was not a nix error");
|
||||
/// return nix_set_err_msg(context, NIX_ERR::UNKNOWN, "Last error was not a nix error");
|
||||
/// }
|
||||
/// // NOTE(nixide): `call_nix_get_string_callback` always returns `NIX_OK`
|
||||
/// return call_nix_get_string_callback(read_context->info->msg.str(), callback, user_data);
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// `nix_err_info_msg` accepts two `nix_c_context*`:
|
||||
/// `nix_err::info_msg` accepts two `nix_c_context*`:
|
||||
/// * `nix_c_context* context` - errors from the function call are logged here
|
||||
/// * `const nix_c_context* read_context` - the context to read `info_msg` from
|
||||
///
|
||||
|
|
@ -333,13 +320,13 @@ impl ErrorContext {
|
|||
.ok()
|
||||
}
|
||||
|
||||
/// Returns [None] if [self.code] is [sys::nix_err_NIX_OK], and [Some] otherwise.
|
||||
/// Returns [None] if [self.code] is [sys::NixErr::NIX_OK], and [Some] otherwise.
|
||||
///
|
||||
/// # Nix C++ API Internals
|
||||
///
|
||||
/// ```cpp
|
||||
/// // NOTE(nixide): the implementation of `nix_err_info_msg` is identical to `nix_err_name`
|
||||
/// nix_err nix_err_info_msg(
|
||||
/// // NOTE(nixide): the implementation of `nix_err::info_msg` is identical to `nix_err::name`
|
||||
/// nix_err nix_err::info_msg(
|
||||
/// nix_c_context * context,
|
||||
/// const nix_c_context * read_context,
|
||||
/// nix_get_string_callback callback,
|
||||
|
|
@ -347,16 +334,16 @@ impl ErrorContext {
|
|||
/// {
|
||||
/// if (context)
|
||||
/// context->last_err_code = NIX_OK;
|
||||
/// if (read_context->last_err_code != NIX_ERR_NIX_ERROR) {
|
||||
/// if (read_context->last_err_code != NIX_ERR::NIX_ERROR) {
|
||||
/// // NOTE(nixide): `nix_set_err_msg` throws a `nix::Error` exception if `context == nullptr`
|
||||
/// return nix_set_err_msg(context, NIX_ERR_UNKNOWN, "Last error was not a nix error");
|
||||
/// return nix_set_err_msg(context, NIX_ERR::UNKNOWN, "Last error was not a nix error");
|
||||
/// }
|
||||
/// // NOTE(nixide): `call_nix_get_string_callback` always returns `NIX_OK`
|
||||
/// return call_nix_get_string_callback(read_context->info->msg.str(), callback, user_data);
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// `nix_err_info_msg` accepts two `nix_c_context*`:
|
||||
/// `nix_err::info_msg` accepts two `nix_c_context*`:
|
||||
/// * `nix_c_context* context` - errors from the function call are logged here
|
||||
/// * `const nix_c_context* read_context` - the context to read `info_msg` from
|
||||
///
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ pub enum NixideError {
|
|||
/// that is instead mapped to [NixError::ExprEval]
|
||||
NixError {
|
||||
trace: String,
|
||||
inner: sys::nix_err,
|
||||
inner: sys::NixErr,
|
||||
err: NixError,
|
||||
msg: String,
|
||||
},
|
||||
|
|
@ -84,9 +84,7 @@ pub(crate) use new_nixide_error;
|
|||
|
||||
#[allow(unused_macros)]
|
||||
macro_rules! retrace_nixide_error {
|
||||
($x:expr) => {{
|
||||
crate::errors::new_nixide_error!($x.err)
|
||||
}};
|
||||
($x:expr) => {{ crate::errors::new_nixide_error!($x.err) }};
|
||||
}
|
||||
pub(crate) use retrace_nixide_error;
|
||||
|
||||
|
|
@ -102,15 +100,15 @@ impl Display for NixideError {
|
|||
msg,
|
||||
} => {
|
||||
write!(f, "[nixide ~ {trace}]{err} (nix_err={inner}): {msg}")
|
||||
}
|
||||
},
|
||||
|
||||
NixideError::StringNulByte { trace } => {
|
||||
write!(f, "[nixide ~ {trace}] Got premature `\\0` (NUL) byte")
|
||||
}
|
||||
},
|
||||
|
||||
NixideError::StringNotUtf8 { trace } => {
|
||||
write!(f, "[nixide ~ {trace}] Expected UTF-8 encoded string")
|
||||
}
|
||||
},
|
||||
|
||||
NixideError::NullPtr { trace } => write!(f, "[nixide ~ {trace}] Got null pointer"),
|
||||
|
||||
|
|
@ -123,7 +121,7 @@ impl Display for NixideError {
|
|||
f,
|
||||
"[nixide ~ {trace}] Invalid argument `{name}`: reason \"{reason}\""
|
||||
)
|
||||
}
|
||||
},
|
||||
|
||||
NixideError::InvalidType {
|
||||
trace,
|
||||
|
|
|
|||
|
|
@ -93,15 +93,18 @@ pub enum NixError {
|
|||
///
|
||||
/// [NixError::Undocumented] has no equivalent in the `libnix` api.
|
||||
/// This is solely a language difference between C++ and Rust, since
|
||||
/// [sys::nix_err] is defined over the *"continuous" (not realy)*
|
||||
/// [sys::NixErr] is defined over the *"continuous" (not realy)*
|
||||
/// type [std::os::raw::c_int].
|
||||
Undocumented(sys::nix_err),
|
||||
Undocumented(sys::NixErr),
|
||||
}
|
||||
|
||||
impl Display for NixError {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
|
||||
match self {
|
||||
NixError::ExprEval { name, info_msg } => write!(f, "[libnix] NixExpr evaluation failed [name=\"{name}\", info_msg=\"{info_msg}\"]"),
|
||||
NixError::ExprEval { name, info_msg } => write!(
|
||||
f,
|
||||
"[libnix] NixExpr evaluation failed [name=\"{name}\", info_msg=\"{info_msg}\"]"
|
||||
),
|
||||
NixError::KeyNotFound(Some(key)) => write!(f, "[libnix] Key not found \"{key}\""),
|
||||
NixError::KeyNotFound(None) => write!(f, "[libnix] Key not found"),
|
||||
NixError::Overflow => write!(f, "[libnix] Overflow error"),
|
||||
|
|
@ -115,15 +118,15 @@ impl Display for NixError {
|
|||
}
|
||||
|
||||
impl NixError {
|
||||
pub fn err_code(&self) -> sys::nix_err {
|
||||
pub fn err_code(&self) -> sys::NixErr {
|
||||
match self {
|
||||
NixError::Overflow => sys::nix_err_NIX_ERR_OVERFLOW,
|
||||
NixError::KeyNotFound(_) => sys::nix_err_NIX_ERR_NIX_ERROR,
|
||||
NixError::Overflow => sys::NixErr::Overflow,
|
||||
NixError::KeyNotFound(_) => sys::NixErr::Key,
|
||||
NixError::ExprEval {
|
||||
name: _,
|
||||
info_msg: _,
|
||||
} => sys::nix_err_NIX_ERR_NIX_ERROR,
|
||||
NixError::Unknown => sys::nix_err_NIX_ERR_UNKNOWN,
|
||||
} => sys::NixErr::NixError,
|
||||
NixError::Unknown => sys::NixErr::NixError,
|
||||
NixError::Undocumented(err) => err.clone(),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,23 +18,23 @@ use crate::util::{panic_issue_call_failed, wrap};
|
|||
/// the evaluation state.
|
||||
///
|
||||
pub struct EvalStateBuilder {
|
||||
inner: Rc<RefCell<NonNull<sys::nix_eval_state_builder>>>,
|
||||
inner: Rc<RefCell<NonNull<sys::NixEvalStateBuilder>>>,
|
||||
store: Rc<RefCell<Store>>,
|
||||
}
|
||||
|
||||
impl AsInnerPtr<sys::nix_eval_state_builder> for EvalStateBuilder {
|
||||
impl AsInnerPtr<sys::NixEvalStateBuilder> for EvalStateBuilder {
|
||||
#[inline]
|
||||
unsafe fn as_ptr(&self) -> *mut sys::nix_eval_state_builder {
|
||||
unsafe fn as_ptr(&self) -> *mut sys::NixEvalStateBuilder {
|
||||
self.inner.borrow().as_ptr()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
unsafe fn as_ref(&self) -> &sys::nix_eval_state_builder {
|
||||
unsafe fn as_ref(&self) -> &sys::NixEvalStateBuilder {
|
||||
unsafe { self.inner.borrow().as_ref() }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
unsafe fn as_mut(&mut self) -> &mut sys::nix_eval_state_builder {
|
||||
unsafe fn as_mut(&mut self) -> &mut sys::NixEvalStateBuilder {
|
||||
unsafe { self.inner.borrow_mut().as_mut() }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,24 +12,24 @@ use crate::{EvalState, NixideResult, StorePath};
|
|||
use crate::{Store, sys};
|
||||
|
||||
pub struct RealisedString<'a> {
|
||||
inner: RefCell<NonNull<sys::nix_realised_string>>,
|
||||
inner: RefCell<NonNull<sys::NixRealisedString>>,
|
||||
pub path: StorePath,
|
||||
pub children: LazyArray<StorePath, Box<dyn Fn(usize) -> StorePath + 'a>>,
|
||||
}
|
||||
|
||||
impl<'a> AsInnerPtr<sys::nix_realised_string> for RealisedString<'a> {
|
||||
impl<'a> AsInnerPtr<sys::NixRealisedString> for RealisedString<'a> {
|
||||
#[inline]
|
||||
unsafe fn as_ptr(&self) -> *mut sys::nix_realised_string {
|
||||
unsafe fn as_ptr(&self) -> *mut sys::NixRealisedString {
|
||||
self.inner.borrow().as_ptr()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
unsafe fn as_ref(&self) -> &sys::nix_realised_string {
|
||||
unsafe fn as_ref(&self) -> &sys::NixRealisedString {
|
||||
unsafe { self.inner.borrow().as_ref() }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
unsafe fn as_mut(&mut self) -> &mut sys::nix_realised_string {
|
||||
unsafe fn as_mut(&mut self) -> &mut sys::NixRealisedString {
|
||||
unsafe { self.inner.borrow_mut().as_mut() }
|
||||
}
|
||||
}
|
||||
|
|
@ -82,7 +82,7 @@ impl<'a> RealisedString<'a> {
|
|||
})
|
||||
}
|
||||
|
||||
fn parse_path(realised_string: *mut sys::nix_realised_string, store: &Store) -> StorePath {
|
||||
fn parse_path(realised_string: *mut sys::NixRealisedString, store: &Store) -> StorePath {
|
||||
let buffer_ptr = unsafe { sys::nix_realised_string_get_buffer_start(realised_string) };
|
||||
let buffer_size = unsafe { sys::nix_realised_string_get_buffer_size(realised_string) };
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ use crate::util::wrappers::AsInnerPtr;
|
|||
use crate::util::{panic_issue_call_failed, wrap};
|
||||
|
||||
pub struct NixAttrs {
|
||||
inner: NonNull<sys::nix_value>,
|
||||
inner: NonNull<sys::NixValue>,
|
||||
state: Rc<RefCell<NonNull<sys::EvalState>>>,
|
||||
len: u32,
|
||||
}
|
||||
|
|
@ -55,19 +55,19 @@ impl Debug for NixAttrs {
|
|||
}
|
||||
}
|
||||
|
||||
impl AsInnerPtr<sys::nix_value> for NixAttrs {
|
||||
impl AsInnerPtr<sys::NixValue> for NixAttrs {
|
||||
#[inline]
|
||||
unsafe fn as_ptr(&self) -> *mut sys::nix_value {
|
||||
unsafe fn as_ptr(&self) -> *mut sys::NixValue {
|
||||
self.inner.as_ptr()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
unsafe fn as_ref(&self) -> &sys::nix_value {
|
||||
unsafe fn as_ref(&self) -> &sys::NixValue {
|
||||
unsafe { self.inner.as_ref() }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
unsafe fn as_mut(&mut self) -> &mut sys::nix_value {
|
||||
unsafe fn as_mut(&mut self) -> &mut sys::NixValue {
|
||||
unsafe { self.inner.as_mut() }
|
||||
}
|
||||
}
|
||||
|
|
@ -75,10 +75,10 @@ impl AsInnerPtr<sys::nix_value> for NixAttrs {
|
|||
impl NixValue for NixAttrs {
|
||||
#[inline]
|
||||
fn type_id(&self) -> sys::ValueType {
|
||||
sys::ValueType_NIX_TYPE_ATTRS
|
||||
sys::ValueType::Attrs
|
||||
}
|
||||
|
||||
fn from(inner: NonNull<sys::nix_value>, state: Rc<RefCell<NonNull<sys::EvalState>>>) -> Self {
|
||||
fn from(inner: NonNull<sys::NixValue>, state: Rc<RefCell<NonNull<sys::EvalState>>>) -> Self {
|
||||
let len = wrap::nix_fn!(|ctx: &ErrorContext| unsafe {
|
||||
sys::nix_get_attrs_size(ctx.as_ptr(), inner.as_ptr())
|
||||
})
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ use crate::util::wrap;
|
|||
use crate::util::wrappers::AsInnerPtr;
|
||||
|
||||
pub struct NixBool {
|
||||
inner: NonNull<sys::nix_value>,
|
||||
inner: NonNull<sys::NixValue>,
|
||||
state: Rc<RefCell<NonNull<sys::EvalState>>>,
|
||||
value: bool,
|
||||
}
|
||||
|
|
@ -54,19 +54,19 @@ impl Debug for NixBool {
|
|||
}
|
||||
}
|
||||
|
||||
impl AsInnerPtr<sys::nix_value> for NixBool {
|
||||
impl AsInnerPtr<sys::NixValue> for NixBool {
|
||||
#[inline]
|
||||
unsafe fn as_ptr(&self) -> *mut sys::nix_value {
|
||||
unsafe fn as_ptr(&self) -> *mut sys::NixValue {
|
||||
self.inner.as_ptr()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
unsafe fn as_ref(&self) -> &sys::nix_value {
|
||||
unsafe fn as_ref(&self) -> &sys::NixValue {
|
||||
unsafe { self.inner.as_ref() }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
unsafe fn as_mut(&mut self) -> &mut sys::nix_value {
|
||||
unsafe fn as_mut(&mut self) -> &mut sys::NixValue {
|
||||
unsafe { self.inner.as_mut() }
|
||||
}
|
||||
}
|
||||
|
|
@ -74,10 +74,10 @@ impl AsInnerPtr<sys::nix_value> for NixBool {
|
|||
impl NixValue for NixBool {
|
||||
#[inline]
|
||||
fn type_id(&self) -> sys::ValueType {
|
||||
sys::ValueType_NIX_TYPE_BOOL
|
||||
sys::ValueType::Bool
|
||||
}
|
||||
|
||||
fn from(inner: NonNull<sys::nix_value>, state: Rc<RefCell<NonNull<sys::EvalState>>>) -> Self {
|
||||
fn from(inner: NonNull<sys::NixValue>, state: Rc<RefCell<NonNull<sys::EvalState>>>) -> Self {
|
||||
let value = wrap::nix_fn!(|ctx: &ErrorContext| unsafe {
|
||||
sys::nix_get_bool(ctx.as_ptr(), inner.as_ptr())
|
||||
})
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ use crate::util::wrappers::AsInnerPtr;
|
|||
use crate::util::{panic_issue_call_failed, wrap};
|
||||
|
||||
pub struct NixFloat {
|
||||
inner: NonNull<sys::nix_value>,
|
||||
inner: NonNull<sys::NixValue>,
|
||||
state: Rc<RefCell<NonNull<sys::EvalState>>>,
|
||||
value: f64,
|
||||
}
|
||||
|
|
@ -53,19 +53,19 @@ impl Debug for NixFloat {
|
|||
}
|
||||
}
|
||||
|
||||
impl AsInnerPtr<sys::nix_value> for NixFloat {
|
||||
impl AsInnerPtr<sys::NixValue> for NixFloat {
|
||||
#[inline]
|
||||
unsafe fn as_ptr(&self) -> *mut sys::nix_value {
|
||||
unsafe fn as_ptr(&self) -> *mut sys::NixValue {
|
||||
self.inner.as_ptr()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
unsafe fn as_ref(&self) -> &sys::nix_value {
|
||||
unsafe fn as_ref(&self) -> &sys::NixValue {
|
||||
unsafe { self.inner.as_ref() }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
unsafe fn as_mut(&mut self) -> &mut sys::nix_value {
|
||||
unsafe fn as_mut(&mut self) -> &mut sys::NixValue {
|
||||
unsafe { self.inner.as_mut() }
|
||||
}
|
||||
}
|
||||
|
|
@ -73,10 +73,10 @@ impl AsInnerPtr<sys::nix_value> for NixFloat {
|
|||
impl NixValue for NixFloat {
|
||||
#[inline]
|
||||
fn type_id(&self) -> sys::ValueType {
|
||||
sys::ValueType_NIX_TYPE_FLOAT
|
||||
sys::ValueType::Float
|
||||
}
|
||||
|
||||
fn from(inner: NonNull<sys::nix_value>, state: Rc<RefCell<NonNull<sys::EvalState>>>) -> Self {
|
||||
fn from(inner: NonNull<sys::NixValue>, state: Rc<RefCell<NonNull<sys::EvalState>>>) -> Self {
|
||||
let value = wrap::nix_fn!(|ctx: &ErrorContext| unsafe {
|
||||
sys::nix_get_float(ctx.as_ptr(), inner.as_ptr())
|
||||
})
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ use crate::util::wrappers::AsInnerPtr;
|
|||
use crate::util::{panic_issue_call_failed, wrap};
|
||||
|
||||
pub struct NixFunction {
|
||||
inner: NonNull<sys::nix_value>,
|
||||
inner: NonNull<sys::NixValue>,
|
||||
state: Rc<RefCell<NonNull<sys::EvalState>>>,
|
||||
}
|
||||
|
||||
|
|
@ -52,19 +52,19 @@ impl Debug for NixFunction {
|
|||
}
|
||||
}
|
||||
|
||||
impl AsInnerPtr<sys::nix_value> for NixFunction {
|
||||
impl AsInnerPtr<sys::NixValue> for NixFunction {
|
||||
#[inline]
|
||||
unsafe fn as_ptr(&self) -> *mut sys::nix_value {
|
||||
unsafe fn as_ptr(&self) -> *mut sys::NixValue {
|
||||
self.inner.as_ptr()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
unsafe fn as_ref(&self) -> &sys::nix_value {
|
||||
unsafe fn as_ref(&self) -> &sys::NixValue {
|
||||
unsafe { self.inner.as_ref() }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
unsafe fn as_mut(&mut self) -> &mut sys::nix_value {
|
||||
unsafe fn as_mut(&mut self) -> &mut sys::NixValue {
|
||||
unsafe { self.inner.as_mut() }
|
||||
}
|
||||
}
|
||||
|
|
@ -72,10 +72,10 @@ impl AsInnerPtr<sys::nix_value> for NixFunction {
|
|||
impl NixValue for NixFunction {
|
||||
#[inline]
|
||||
fn type_id(&self) -> sys::ValueType {
|
||||
sys::ValueType_NIX_TYPE_FUNCTION
|
||||
sys::ValueType::Function
|
||||
}
|
||||
|
||||
fn from(inner: NonNull<sys::nix_value>, state: Rc<RefCell<NonNull<sys::EvalState>>>) -> Self {
|
||||
fn from(inner: NonNull<sys::NixValue>, state: Rc<RefCell<NonNull<sys::EvalState>>>) -> Self {
|
||||
Self { inner, state }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ use crate::util::wrappers::AsInnerPtr;
|
|||
use crate::util::{panic_issue_call_failed, wrap};
|
||||
|
||||
pub struct NixInt {
|
||||
inner: NonNull<sys::nix_value>,
|
||||
inner: NonNull<sys::NixValue>,
|
||||
state: Rc<RefCell<NonNull<sys::EvalState>>>,
|
||||
value: i64,
|
||||
}
|
||||
|
|
@ -53,19 +53,19 @@ impl Debug for NixInt {
|
|||
}
|
||||
}
|
||||
|
||||
impl AsInnerPtr<sys::nix_value> for NixInt {
|
||||
impl AsInnerPtr<sys::NixValue> for NixInt {
|
||||
#[inline]
|
||||
unsafe fn as_ptr(&self) -> *mut sys::nix_value {
|
||||
unsafe fn as_ptr(&self) -> *mut sys::NixValue {
|
||||
self.inner.as_ptr()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
unsafe fn as_ref(&self) -> &sys::nix_value {
|
||||
unsafe fn as_ref(&self) -> &sys::NixValue {
|
||||
unsafe { self.inner.as_ref() }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
unsafe fn as_mut(&mut self) -> &mut sys::nix_value {
|
||||
unsafe fn as_mut(&mut self) -> &mut sys::NixValue {
|
||||
unsafe { self.inner.as_mut() }
|
||||
}
|
||||
}
|
||||
|
|
@ -73,10 +73,10 @@ impl AsInnerPtr<sys::nix_value> for NixInt {
|
|||
impl NixValue for NixInt {
|
||||
#[inline]
|
||||
fn type_id(&self) -> sys::ValueType {
|
||||
sys::ValueType_NIX_TYPE_INT
|
||||
sys::ValueType::Int
|
||||
}
|
||||
|
||||
fn from(inner: NonNull<sys::nix_value>, state: Rc<RefCell<NonNull<sys::EvalState>>>) -> Self {
|
||||
fn from(inner: NonNull<sys::NixValue>, state: Rc<RefCell<NonNull<sys::EvalState>>>) -> Self {
|
||||
let value = wrap::nix_fn!(|ctx: &ErrorContext| unsafe {
|
||||
sys::nix_get_int(ctx.as_ptr(), inner.as_ptr())
|
||||
})
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ use crate::util::wrappers::AsInnerPtr;
|
|||
use crate::util::{panic_issue_call_failed, wrap};
|
||||
|
||||
pub struct NixList {
|
||||
inner: NonNull<sys::nix_value>,
|
||||
inner: NonNull<sys::NixValue>,
|
||||
state: Rc<RefCell<NonNull<sys::EvalState>>>,
|
||||
}
|
||||
|
||||
|
|
@ -51,19 +51,19 @@ impl Debug for NixList {
|
|||
}
|
||||
}
|
||||
|
||||
impl AsInnerPtr<sys::nix_value> for NixList {
|
||||
impl AsInnerPtr<sys::NixValue> for NixList {
|
||||
#[inline]
|
||||
unsafe fn as_ptr(&self) -> *mut sys::nix_value {
|
||||
unsafe fn as_ptr(&self) -> *mut sys::NixValue {
|
||||
self.inner.as_ptr()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
unsafe fn as_ref(&self) -> &sys::nix_value {
|
||||
unsafe fn as_ref(&self) -> &sys::NixValue {
|
||||
unsafe { self.inner.as_ref() }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
unsafe fn as_mut(&mut self) -> &mut sys::nix_value {
|
||||
unsafe fn as_mut(&mut self) -> &mut sys::NixValue {
|
||||
unsafe { self.inner.as_mut() }
|
||||
}
|
||||
}
|
||||
|
|
@ -71,10 +71,10 @@ impl AsInnerPtr<sys::nix_value> for NixList {
|
|||
impl NixValue for NixList {
|
||||
#[inline]
|
||||
fn type_id(&self) -> sys::ValueType {
|
||||
sys::ValueType_NIX_TYPE_LIST
|
||||
sys::ValueType::List
|
||||
}
|
||||
|
||||
fn from(inner: NonNull<sys::nix_value>, state: Rc<RefCell<NonNull<sys::EvalState>>>) -> Self {
|
||||
fn from(inner: NonNull<sys::NixValue>, state: Rc<RefCell<NonNull<sys::EvalState>>>) -> Self {
|
||||
Self { inner, state }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,21 +30,16 @@ use std::rc::Rc;
|
|||
|
||||
use crate::errors::ErrorContext;
|
||||
use crate::sys;
|
||||
use crate::sys::{
|
||||
ValueType_NIX_TYPE_ATTRS, ValueType_NIX_TYPE_BOOL, ValueType_NIX_TYPE_EXTERNAL,
|
||||
ValueType_NIX_TYPE_FLOAT, ValueType_NIX_TYPE_FUNCTION, ValueType_NIX_TYPE_INT,
|
||||
ValueType_NIX_TYPE_LIST, ValueType_NIX_TYPE_NULL, ValueType_NIX_TYPE_PATH,
|
||||
ValueType_NIX_TYPE_STRING, ValueType_NIX_TYPE_THUNK,
|
||||
};
|
||||
use crate::sys::ValueType;
|
||||
use crate::util::wrappers::AsInnerPtr;
|
||||
use crate::util::{panic_issue_call_failed, wrap};
|
||||
|
||||
pub trait NixValue: Clone + Drop + Display + Debug + AsInnerPtr<sys::nix_value> {
|
||||
pub trait NixValue: Clone + Drop + Display + Debug + AsInnerPtr<sys::NixValue> {
|
||||
/// TODO
|
||||
fn type_id(&self) -> sys::ValueType;
|
||||
|
||||
/// TODO
|
||||
fn from(inner: NonNull<sys::nix_value>, state: Rc<RefCell<NonNull<sys::EvalState>>>) -> Self;
|
||||
fn from(inner: NonNull<sys::NixValue>, state: Rc<RefCell<NonNull<sys::EvalState>>>) -> Self;
|
||||
}
|
||||
|
||||
/// A Nix value
|
||||
|
|
@ -110,18 +105,8 @@ pub enum Value {
|
|||
// Failed(NixFailed),
|
||||
}
|
||||
|
||||
impl
|
||||
From<(
|
||||
NonNull<sys::nix_value>,
|
||||
Rc<RefCell<NonNull<sys::EvalState>>>,
|
||||
)> for Value
|
||||
{
|
||||
fn from(
|
||||
value: (
|
||||
NonNull<sys::nix_value>,
|
||||
Rc<RefCell<NonNull<sys::EvalState>>>,
|
||||
),
|
||||
) -> Self {
|
||||
impl From<(NonNull<sys::NixValue>, Rc<RefCell<NonNull<sys::EvalState>>>)> for Value {
|
||||
fn from(value: (NonNull<sys::NixValue>, Rc<RefCell<NonNull<sys::EvalState>>>)) -> Self {
|
||||
let (inner, state) = value;
|
||||
|
||||
wrap::nix_fn!(|ctx: &ErrorContext| unsafe {
|
||||
|
|
@ -136,22 +121,20 @@ impl
|
|||
|
||||
#[allow(non_upper_case_globals)]
|
||||
match type_id {
|
||||
ValueType_NIX_TYPE_THUNK => Value::Thunk(<NixThunk as NixValue>::from(inner, state)),
|
||||
ValueType_NIX_TYPE_INT => Value::Int(<NixInt as NixValue>::from(inner, state)),
|
||||
ValueType_NIX_TYPE_FLOAT => Value::Float(<NixFloat as NixValue>::from(inner, state)),
|
||||
ValueType_NIX_TYPE_BOOL => Value::Bool(<NixBool as NixValue>::from(inner, state)),
|
||||
ValueType_NIX_TYPE_STRING => Value::String(<NixString as NixValue>::from(inner, state)),
|
||||
ValueType_NIX_TYPE_PATH => Value::Path(<NixPath as NixValue>::from(inner, state)),
|
||||
ValueType_NIX_TYPE_NULL => Value::Null(<NixNull as NixValue>::from(inner, state)),
|
||||
ValueType_NIX_TYPE_ATTRS => Value::Attrs(<NixAttrs as NixValue>::from(inner, state)),
|
||||
ValueType_NIX_TYPE_LIST => Value::List(<NixList as NixValue>::from(inner, state)),
|
||||
ValueType_NIX_TYPE_FUNCTION => {
|
||||
Value::Function(<NixFunction as NixValue>::from(inner, state))
|
||||
},
|
||||
// ValueType_NIX_TYPE_EXTERNAL => {
|
||||
ValueType::Thunk => Value::Thunk(<NixThunk as NixValue>::from(inner, state)),
|
||||
ValueType::Int => Value::Int(<NixInt as NixValue>::from(inner, state)),
|
||||
ValueType::Float => Value::Float(<NixFloat as NixValue>::from(inner, state)),
|
||||
ValueType::Bool => Value::Bool(<NixBool as NixValue>::from(inner, state)),
|
||||
ValueType::String => Value::String(<NixString as NixValue>::from(inner, state)),
|
||||
ValueType::Path => Value::Path(<NixPath as NixValue>::from(inner, state)),
|
||||
ValueType::Null => Value::Null(<NixNull as NixValue>::from(inner, state)),
|
||||
ValueType::Attrs => Value::Attrs(<NixAttrs as NixValue>::from(inner, state)),
|
||||
ValueType::List => Value::List(<NixList as NixValue>::from(inner, state)),
|
||||
ValueType::Function => Value::Function(<NixFunction as NixValue>::from(inner, state)),
|
||||
// ValueType::External => {
|
||||
// Value::External(<NixExternal as NixValue>::from(inner, state))
|
||||
// },
|
||||
// ValueType_NIX_TYPE_FAILED => {
|
||||
// ValueType::Failed => {
|
||||
// Value::Failed(<NixFailed as NixValue>::from(inner, state))
|
||||
// },
|
||||
_ => unreachable!(),
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ use crate::util::wrap;
|
|||
use crate::util::wrappers::AsInnerPtr;
|
||||
|
||||
pub struct NixNull {
|
||||
inner: NonNull<sys::nix_value>,
|
||||
inner: NonNull<sys::NixValue>,
|
||||
state: Rc<RefCell<NonNull<sys::EvalState>>>,
|
||||
}
|
||||
|
||||
|
|
@ -51,19 +51,19 @@ impl Debug for NixNull {
|
|||
}
|
||||
}
|
||||
|
||||
impl AsInnerPtr<sys::nix_value> for NixNull {
|
||||
impl AsInnerPtr<sys::NixValue> for NixNull {
|
||||
#[inline]
|
||||
unsafe fn as_ptr(&self) -> *mut sys::nix_value {
|
||||
unsafe fn as_ptr(&self) -> *mut sys::NixValue {
|
||||
self.inner.as_ptr()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
unsafe fn as_ref(&self) -> &sys::nix_value {
|
||||
unsafe fn as_ref(&self) -> &sys::NixValue {
|
||||
unsafe { self.inner.as_ref() }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
unsafe fn as_mut(&mut self) -> &mut sys::nix_value {
|
||||
unsafe fn as_mut(&mut self) -> &mut sys::NixValue {
|
||||
unsafe { self.inner.as_mut() }
|
||||
}
|
||||
}
|
||||
|
|
@ -71,10 +71,10 @@ impl AsInnerPtr<sys::nix_value> for NixNull {
|
|||
impl NixValue for NixNull {
|
||||
#[inline]
|
||||
fn type_id(&self) -> sys::ValueType {
|
||||
sys::ValueType_NIX_TYPE_NULL
|
||||
sys::ValueType::Null
|
||||
}
|
||||
|
||||
fn from(inner: NonNull<sys::nix_value>, state: Rc<RefCell<NonNull<sys::EvalState>>>) -> Self {
|
||||
fn from(inner: NonNull<sys::NixValue>, state: Rc<RefCell<NonNull<sys::EvalState>>>) -> Self {
|
||||
Self { inner, state }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ use crate::util::wrap;
|
|||
use crate::util::wrappers::AsInnerPtr;
|
||||
|
||||
pub struct NixPath {
|
||||
inner: NonNull<sys::nix_value>,
|
||||
inner: NonNull<sys::NixValue>,
|
||||
state: Rc<RefCell<NonNull<sys::EvalState>>>,
|
||||
value: PathBuf,
|
||||
}
|
||||
|
|
@ -56,19 +56,19 @@ impl Debug for NixPath {
|
|||
}
|
||||
}
|
||||
|
||||
impl AsInnerPtr<sys::nix_value> for NixPath {
|
||||
impl AsInnerPtr<sys::NixValue> for NixPath {
|
||||
#[inline]
|
||||
unsafe fn as_ptr(&self) -> *mut sys::nix_value {
|
||||
unsafe fn as_ptr(&self) -> *mut sys::NixValue {
|
||||
self.inner.as_ptr()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
unsafe fn as_ref(&self) -> &sys::nix_value {
|
||||
unsafe fn as_ref(&self) -> &sys::NixValue {
|
||||
unsafe { self.inner.as_ref() }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
unsafe fn as_mut(&mut self) -> &mut sys::nix_value {
|
||||
unsafe fn as_mut(&mut self) -> &mut sys::NixValue {
|
||||
unsafe { self.inner.as_mut() }
|
||||
}
|
||||
}
|
||||
|
|
@ -76,10 +76,10 @@ impl AsInnerPtr<sys::nix_value> for NixPath {
|
|||
impl NixValue for NixPath {
|
||||
#[inline]
|
||||
fn type_id(&self) -> sys::ValueType {
|
||||
sys::ValueType_NIX_TYPE_PATH
|
||||
sys::ValueType::Path
|
||||
}
|
||||
|
||||
fn from(inner: NonNull<sys::nix_value>, state: Rc<RefCell<NonNull<sys::EvalState>>>) -> Self {
|
||||
fn from(inner: NonNull<sys::NixValue>, state: Rc<RefCell<NonNull<sys::EvalState>>>) -> Self {
|
||||
let value = wrap::nix_fn!(|ctx: &ErrorContext| unsafe {
|
||||
sys::nix_get_path_string(ctx.as_ptr(), inner.as_ptr())
|
||||
})
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ use crate::util::wrap;
|
|||
use crate::util::wrappers::AsInnerPtr;
|
||||
|
||||
pub struct NixString {
|
||||
inner: NonNull<sys::nix_value>,
|
||||
inner: NonNull<sys::NixValue>,
|
||||
state: Rc<RefCell<NonNull<sys::EvalState>>>,
|
||||
value: String,
|
||||
}
|
||||
|
|
@ -55,19 +55,19 @@ impl Debug for NixString {
|
|||
}
|
||||
}
|
||||
|
||||
impl AsInnerPtr<sys::nix_value> for NixString {
|
||||
impl AsInnerPtr<sys::NixValue> for NixString {
|
||||
#[inline]
|
||||
unsafe fn as_ptr(&self) -> *mut sys::nix_value {
|
||||
unsafe fn as_ptr(&self) -> *mut sys::NixValue {
|
||||
self.inner.as_ptr()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
unsafe fn as_ref(&self) -> &sys::nix_value {
|
||||
unsafe fn as_ref(&self) -> &sys::NixValue {
|
||||
unsafe { self.inner.as_ref() }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
unsafe fn as_mut(&mut self) -> &mut sys::nix_value {
|
||||
unsafe fn as_mut(&mut self) -> &mut sys::NixValue {
|
||||
unsafe { self.inner.as_mut() }
|
||||
}
|
||||
}
|
||||
|
|
@ -75,10 +75,10 @@ impl AsInnerPtr<sys::nix_value> for NixString {
|
|||
impl NixValue for NixString {
|
||||
#[inline]
|
||||
fn type_id(&self) -> sys::ValueType {
|
||||
sys::ValueType_NIX_TYPE_STRING
|
||||
sys::ValueType::String
|
||||
}
|
||||
|
||||
fn from(inner: NonNull<sys::nix_value>, state: Rc<RefCell<NonNull<sys::EvalState>>>) -> Self {
|
||||
fn from(inner: NonNull<sys::NixValue>, state: Rc<RefCell<NonNull<sys::EvalState>>>) -> Self {
|
||||
let value = wrap::nix_string_callback!(
|
||||
|callback, userdata: *mut __UserData, ctx: &ErrorContext| unsafe {
|
||||
sys::nix_get_string(
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ use crate::util::wrappers::AsInnerPtr;
|
|||
use crate::util::{panic_issue_call_failed, wrap};
|
||||
|
||||
pub struct NixThunk {
|
||||
inner: NonNull<sys::nix_value>,
|
||||
inner: NonNull<sys::NixValue>,
|
||||
state: Rc<RefCell<NonNull<sys::EvalState>>>,
|
||||
}
|
||||
|
||||
|
|
@ -51,19 +51,19 @@ impl Debug for NixThunk {
|
|||
}
|
||||
}
|
||||
|
||||
impl AsInnerPtr<sys::nix_value> for NixThunk {
|
||||
impl AsInnerPtr<sys::NixValue> for NixThunk {
|
||||
#[inline]
|
||||
unsafe fn as_ptr(&self) -> *mut sys::nix_value {
|
||||
unsafe fn as_ptr(&self) -> *mut sys::NixValue {
|
||||
self.inner.as_ptr()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
unsafe fn as_ref(&self) -> &sys::nix_value {
|
||||
unsafe fn as_ref(&self) -> &sys::NixValue {
|
||||
unsafe { self.inner.as_ref() }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
unsafe fn as_mut(&mut self) -> &mut sys::nix_value {
|
||||
unsafe fn as_mut(&mut self) -> &mut sys::NixValue {
|
||||
unsafe { self.inner.as_mut() }
|
||||
}
|
||||
}
|
||||
|
|
@ -71,10 +71,10 @@ impl AsInnerPtr<sys::nix_value> for NixThunk {
|
|||
impl NixValue for NixThunk {
|
||||
#[inline]
|
||||
fn type_id(&self) -> sys::ValueType {
|
||||
sys::ValueType_NIX_TYPE_THUNK
|
||||
sys::ValueType::Thunk
|
||||
}
|
||||
|
||||
fn from(inner: NonNull<sys::nix_value>, state: Rc<RefCell<NonNull<sys::EvalState>>>) -> Self {
|
||||
fn from(inner: NonNull<sys::NixValue>, state: Rc<RefCell<NonNull<sys::EvalState>>>) -> Self {
|
||||
Self { inner, state }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ use crate::util::wrap;
|
|||
use crate::util::wrappers::AsInnerPtr;
|
||||
|
||||
pub struct FetchersSettings {
|
||||
inner: NonNull<sys::nix_fetchers_settings>,
|
||||
inner: NonNull<sys::NixFetchersSettings>,
|
||||
}
|
||||
|
||||
impl FetchersSettings {
|
||||
|
|
@ -41,19 +41,19 @@ impl Drop for FetchersSettings {
|
|||
}
|
||||
}
|
||||
|
||||
impl AsInnerPtr<sys::nix_fetchers_settings> for FetchersSettings {
|
||||
impl AsInnerPtr<sys::NixFetchersSettings> for FetchersSettings {
|
||||
#[inline]
|
||||
unsafe fn as_ptr(&self) -> *mut sys::nix_fetchers_settings {
|
||||
unsafe fn as_ptr(&self) -> *mut sys::NixFetchersSettings {
|
||||
self.inner.as_ptr()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
unsafe fn as_ref(&self) -> &sys::nix_fetchers_settings {
|
||||
unsafe fn as_ref(&self) -> &sys::NixFetchersSettings {
|
||||
unsafe { self.inner.as_ref() }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
unsafe fn as_mut(&mut self) -> &mut sys::nix_fetchers_settings {
|
||||
unsafe fn as_mut(&mut self) -> &mut sys::NixFetchersSettings {
|
||||
unsafe { self.inner.as_mut() }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
use std::ffi::c_void;
|
||||
use std::ptr::NonNull;
|
||||
|
||||
use super::{FlakeReference, FlakeSettings};
|
||||
|
|
@ -26,7 +25,7 @@ pub enum FlakeLockMode {
|
|||
|
||||
/// Parameters that affect the locking of a flake.
|
||||
pub struct FlakeLockFlags {
|
||||
pub(crate) inner: NonNull<sys::nix_flake_lock_flags>,
|
||||
pub(crate) inner: NonNull<sys::NixFlakeLockFlags>,
|
||||
}
|
||||
|
||||
// impl Clone for FlakeLockFlags {
|
||||
|
|
@ -50,19 +49,19 @@ impl Drop for FlakeLockFlags {
|
|||
}
|
||||
}
|
||||
|
||||
impl AsInnerPtr<sys::nix_flake_lock_flags> for FlakeLockFlags {
|
||||
impl AsInnerPtr<sys::NixFlakeLockFlags> for FlakeLockFlags {
|
||||
#[inline]
|
||||
unsafe fn as_ptr(&self) -> *mut sys::nix_flake_lock_flags {
|
||||
unsafe fn as_ptr(&self) -> *mut sys::NixFlakeLockFlags {
|
||||
self.inner.as_ptr()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
unsafe fn as_ref(&self) -> &sys::nix_flake_lock_flags {
|
||||
unsafe fn as_ref(&self) -> &sys::NixFlakeLockFlags {
|
||||
unsafe { self.inner.as_ref() }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
unsafe fn as_mut(&mut self) -> &mut sys::nix_flake_lock_flags {
|
||||
unsafe fn as_mut(&mut self) -> &mut sys::NixFlakeLockFlags {
|
||||
unsafe { self.inner.as_mut() }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ use crate::util::wrappers::AsInnerPtr;
|
|||
|
||||
// XXX: TODO: rename FlakeReference -> FlakeRef
|
||||
pub struct FlakeReference {
|
||||
inner: NonNull<sys::nix_flake_reference>,
|
||||
inner: NonNull<sys::NixFlakeReference>,
|
||||
fragment: String,
|
||||
}
|
||||
|
||||
|
|
@ -37,19 +37,19 @@ impl Drop for FlakeReference {
|
|||
}
|
||||
}
|
||||
|
||||
impl AsInnerPtr<sys::nix_flake_reference> for FlakeReference {
|
||||
impl AsInnerPtr<sys::NixFlakeReference> for FlakeReference {
|
||||
#[inline]
|
||||
unsafe fn as_ptr(&self) -> *mut sys::nix_flake_reference {
|
||||
unsafe fn as_ptr(&self) -> *mut sys::NixFlakeReference {
|
||||
self.inner.as_ptr()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
unsafe fn as_ref(&self) -> &sys::nix_flake_reference {
|
||||
unsafe fn as_ref(&self) -> &sys::NixFlakeReference {
|
||||
unsafe { self.inner.as_ref() }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
unsafe fn as_mut(&mut self) -> &mut sys::nix_flake_reference {
|
||||
unsafe fn as_mut(&mut self) -> &mut sys::NixFlakeReference {
|
||||
unsafe { self.inner.as_mut() }
|
||||
}
|
||||
}
|
||||
|
|
@ -65,7 +65,7 @@ impl FlakeReference {
|
|||
flags: &FlakeReferenceParseFlags,
|
||||
reference: &str,
|
||||
) -> Result<FlakeReference, NixideError> {
|
||||
let mut ptr: *mut sys::nix_flake_reference = null_mut();
|
||||
let mut ptr: *mut sys::NixFlakeReference = null_mut();
|
||||
let fragment = wrap::nix_string_callback!(
|
||||
|callback, userdata: *mut __UserData, ctx: &ErrorContext| unsafe {
|
||||
sys::nix_flake_reference_and_fragment_from_string(
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
use std::ffi::c_void;
|
||||
use std::os::raw::c_char;
|
||||
use std::ptr::NonNull;
|
||||
|
||||
|
|
@ -12,7 +11,7 @@ use crate::util::wrappers::AsInnerPtr;
|
|||
/// Parameters for parsing a flake reference.
|
||||
#[derive(Debug)]
|
||||
pub struct FlakeReferenceParseFlags {
|
||||
inner: NonNull<sys::nix_flake_reference_parse_flags>,
|
||||
inner: NonNull<sys::NixFlakeReferenceParseFlags>,
|
||||
}
|
||||
|
||||
// impl Clone for FlakeReferenceParseFlags {
|
||||
|
|
@ -36,19 +35,19 @@ impl Drop for FlakeReferenceParseFlags {
|
|||
}
|
||||
}
|
||||
|
||||
impl AsInnerPtr<sys::nix_flake_reference_parse_flags> for FlakeReferenceParseFlags {
|
||||
impl AsInnerPtr<sys::NixFlakeReferenceParseFlags> for FlakeReferenceParseFlags {
|
||||
#[inline]
|
||||
unsafe fn as_ptr(&self) -> *mut sys::nix_flake_reference_parse_flags {
|
||||
unsafe fn as_ptr(&self) -> *mut sys::NixFlakeReferenceParseFlags {
|
||||
self.inner.as_ptr()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
unsafe fn as_ref(&self) -> &sys::nix_flake_reference_parse_flags {
|
||||
unsafe fn as_ref(&self) -> &sys::NixFlakeReferenceParseFlags {
|
||||
unsafe { self.inner.as_ref() }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
unsafe fn as_mut(&mut self) -> &mut sys::nix_flake_reference_parse_flags {
|
||||
unsafe fn as_mut(&mut self) -> &mut sys::NixFlakeReferenceParseFlags {
|
||||
unsafe { self.inner.as_mut() }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ use crate::util::wrappers::AsInnerPtr;
|
|||
|
||||
/// Store settings for the flakes feature.
|
||||
pub struct FlakeSettings {
|
||||
inner: NonNull<sys::nix_flake_settings>,
|
||||
inner: NonNull<sys::NixFlakeSettings>,
|
||||
}
|
||||
|
||||
impl Drop for FlakeSettings {
|
||||
|
|
@ -19,19 +19,19 @@ impl Drop for FlakeSettings {
|
|||
}
|
||||
}
|
||||
|
||||
impl AsInnerPtr<sys::nix_flake_settings> for FlakeSettings {
|
||||
impl AsInnerPtr<sys::NixFlakeSettings> for FlakeSettings {
|
||||
#[inline]
|
||||
unsafe fn as_ptr(&self) -> *mut sys::nix_flake_settings {
|
||||
unsafe fn as_ptr(&self) -> *mut sys::NixFlakeSettings {
|
||||
self.inner.as_ptr()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
unsafe fn as_ref(&self) -> &sys::nix_flake_settings {
|
||||
unsafe fn as_ref(&self) -> &sys::NixFlakeSettings {
|
||||
unsafe { self.inner.as_ref() }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
unsafe fn as_mut(&mut self) -> &mut sys::nix_flake_settings {
|
||||
unsafe fn as_mut(&mut self) -> &mut sys::NixFlakeSettings {
|
||||
unsafe { self.inner.as_mut() }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ use crate::util::wrappers::AsInnerPtr;
|
|||
use crate::{EvalState, NixideResult, Value};
|
||||
|
||||
pub struct LockedFlake {
|
||||
inner: NonNull<sys::nix_locked_flake>,
|
||||
inner: NonNull<sys::NixLockedFlake>,
|
||||
|
||||
flakeref: FlakeReference,
|
||||
state: EvalState,
|
||||
|
|
@ -45,19 +45,19 @@ impl Drop for LockedFlake {
|
|||
}
|
||||
}
|
||||
|
||||
impl AsInnerPtr<sys::nix_locked_flake> for LockedFlake {
|
||||
impl AsInnerPtr<sys::NixLockedFlake> for LockedFlake {
|
||||
#[inline]
|
||||
unsafe fn as_ptr(&self) -> *mut sys::nix_locked_flake {
|
||||
unsafe fn as_ptr(&self) -> *mut sys::NixLockedFlake {
|
||||
self.inner.as_ptr()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
unsafe fn as_ref(&self) -> &sys::nix_locked_flake {
|
||||
unsafe fn as_ref(&self) -> &sys::NixLockedFlake {
|
||||
unsafe { self.inner.as_ref() }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
unsafe fn as_mut(&mut self) -> &mut sys::nix_locked_flake {
|
||||
unsafe fn as_mut(&mut self) -> &mut sys::NixLockedFlake {
|
||||
unsafe { self.inner.as_mut() }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,14 @@
|
|||
use crate::errors::ErrorContext;
|
||||
use crate::sys;
|
||||
use crate::util::wrappers::AsInnerPtr as _;
|
||||
use crate::util::{panic_issue, panic_issue_call_failed, wrap};
|
||||
use crate::util::{panic_issue_call_failed, wrap};
|
||||
|
||||
/// Verbosity level
|
||||
///
|
||||
/// # NOTE
|
||||
///
|
||||
/// This should be kept in sync with the C++ implementation (nix::Verbosity)
|
||||
///
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub enum NixVerbosity {
|
||||
Error,
|
||||
|
|
@ -20,28 +21,24 @@ pub enum NixVerbosity {
|
|||
Vomit,
|
||||
}
|
||||
|
||||
impl From<sys::nix_verbosity> for NixVerbosity {
|
||||
fn from(level: sys::nix_verbosity) -> NixVerbosity {
|
||||
impl From<sys::NixVerbosity> for NixVerbosity {
|
||||
fn from(level: sys::NixVerbosity) -> NixVerbosity {
|
||||
match level {
|
||||
sys::nix_verbosity_NIX_LVL_ERROR => NixVerbosity::Error,
|
||||
sys::nix_verbosity_NIX_LVL_WARN => NixVerbosity::Warn,
|
||||
sys::nix_verbosity_NIX_LVL_NOTICE => NixVerbosity::Notice,
|
||||
sys::nix_verbosity_NIX_LVL_INFO => NixVerbosity::Info,
|
||||
sys::nix_verbosity_NIX_LVL_TALKATIVE => NixVerbosity::Talkative,
|
||||
sys::nix_verbosity_NIX_LVL_CHATTY => NixVerbosity::Chatty,
|
||||
sys::nix_verbosity_NIX_LVL_DEBUG => NixVerbosity::Debug,
|
||||
sys::nix_verbosity_NIX_LVL_VOMIT => NixVerbosity::Vomit,
|
||||
value => panic_issue!(
|
||||
"nixide encountered unknown `nix_verbosity` value ({})",
|
||||
value
|
||||
),
|
||||
sys::NixVerbosity::Error => NixVerbosity::Error,
|
||||
sys::NixVerbosity::Warn => NixVerbosity::Warn,
|
||||
sys::NixVerbosity::Notice => NixVerbosity::Notice,
|
||||
sys::NixVerbosity::Info => NixVerbosity::Info,
|
||||
sys::NixVerbosity::Talkative => NixVerbosity::Talkative,
|
||||
sys::NixVerbosity::Chatty => NixVerbosity::Chatty,
|
||||
sys::NixVerbosity::Debug => NixVerbosity::Debug,
|
||||
sys::NixVerbosity::Vomit => NixVerbosity::Vomit,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<sys::nix_verbosity> for NixVerbosity {
|
||||
fn into(self) -> sys::nix_verbosity {
|
||||
self as sys::nix_verbosity
|
||||
impl Into<sys::NixVerbosity> for NixVerbosity {
|
||||
fn into(self) -> sys::NixVerbosity {
|
||||
self as sys::NixVerbosity
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue