Skip to content

Commit b234ca1

Browse files
committed
chiptool: patch-out broken svd-parser
Fork repository that contains svd-parser as well as a broken submodule that causes a Cargo vendor crash in the newer versions of the Nix rust-platform (since nixpkgs @ 5cd869caa4ea1bf1bde71731ecc96b24e1bdcc2d). Upstream variant contains a patch that fixes this (rust-embedded/svd#294) and additional features that do not break chiptool. Nice plus: new fetchCargoVendor supports git dependencies, we do not have to use importCargoLock and manually populate git dependencies' output hashes to source dependencies!
1 parent df56f2d commit b234ca1

File tree

2 files changed

+63
-462
lines changed

2 files changed

+63
-462
lines changed

packages/chiptool.nix

Lines changed: 63 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ rustPlatform.buildRustPackage rec {
2020
hash = "sha256-l5a184UCqy/IeQ25hR43uWoSUg1cexLX2Dxd7mgOHKQ=";
2121
};
2222

23-
patches = [
23+
cargoHash = "sha256-gMCD0xTyN+KIDM1zrzkyt8qxJhjQNr2fx/Ub+F9fe5k=";
24+
cargoPatches = [
2425
# Patch-in the revision, there is no .git directory in src that the build-script could use
2526
(writeText "chiptool-nix-generated-revision.patch" ''
2627
--- a/src/generate/mod.rs
@@ -30,24 +31,74 @@ rustPlatform.buildRustPackage rec {
3031
3132
let commit_info = {
3233
- let tmp = include_str!(concat!(env!("OUT_DIR"), "/commit-info.txt"));
33-
+ let tmp = " (${rev} from github:kiteshield-ab/nix-utils#chiptool)";
34+
+ let tmp = " (${rev} from github:kiteshield-ab/nix-utils#chiptool (patched to use upstream svd-parser))";
3435
3536
if tmp.is_empty() {
3637
" (untracked)"
3738
3839
'')
40+
# Patch-in the upstream variant of svd-parser, does not seem to meaningfully differ (just more features)
41+
# but it includes our patch (https://github.com/rust-embedded/svd/pull/294) that removes a broken submodule
42+
# that clashes with the Nix's rust-platform behaviour (forced git-submodule pull)
43+
(writeText "use-upstream-svd-rs.patch" ''
44+
--- a/Cargo.toml
45+
+++ b/Cargo.toml
46+
@@ -14,7 +14,7 @@ proc-macro2 = "1.0"
47+
anyhow = "1.0.79"
48+
regex = "1.10.3"
49+
serde = { version = "1.0.196", features = [ "derive" ]}
50+
-svd-parser = { git = "https://github.com/Dirbaio/svd.git", rev = "4d5c96f95b32acf9c9bfbda5a0619a2374475fe7", features = ["derive-from", "expand"] }
51+
+svd-parser = { git = "https://github.com/rust-embedded/svd.git", features = ["derive-from", "expand"] }
52+
#svd-parser = { path = "./svd/svd-parser", features = ["derive-from", "expand"] }
53+
# Development has stopped for `serde_yaml`
54+
serde_yaml = "=0.9.34-deprecated"
55+
--- a/Cargo.lock
56+
+++ b/Cargo.lock
57+
@@ -1,6 +1,6 @@
58+
# This file is automatically @generated by Cargo.
59+
# It is not intended for manual editing.
60+
-version = 3
61+
+version = 4
62+
63+
[[package]]
64+
name = "aho-corasick"
65+
@@ -264,9 +264,9 @@ checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c"
66+
67+
[[package]]
68+
name = "roxmltree"
69+
-version = "0.19.0"
70+
+version = "0.20.0"
71+
source = "registry+https://github.com/rust-lang/crates.io-index"
72+
-checksum = "3cd14fd5e3b777a7422cca79358c57a8f6e3a703d9ac187448d0daf220c2407f"
73+
+checksum = "6c20b6793b5c2fa6553b250154b78d6d0db37e72700ae35fad9387a46f487c97"
74+
75+
[[package]]
76+
name = "ryu"
77+
@@ -315,8 +315,8 @@ checksum = "5ee073c9e4cd00e28217186dbe12796d692868f432bf2e97ee73bed0c56dfa01"
78+
79+
[[package]]
80+
name = "svd-parser"
81+
-version = "0.14.5"
82+
-source = "git+https://github.com/Dirbaio/svd.git?rev=4d5c96f95b32acf9c9bfbda5a0619a2374475fe7#4d5c96f95b32acf9c9bfbda5a0619a2374475fe7"
83+
+version = "0.14.9"
84+
+source = "git+https://github.com/rust-embedded/svd.git#36750c1b8dc3c76760cd5569337192bec0ca6749"
85+
dependencies = [
86+
"anyhow",
87+
"roxmltree",
88+
@@ -326,8 +326,8 @@ dependencies = [
89+
90+
[[package]]
91+
name = "svd-rs"
92+
-version = "0.14.7"
93+
-source = "git+https://github.com/Dirbaio/svd.git?rev=4d5c96f95b32acf9c9bfbda5a0619a2374475fe7#4d5c96f95b32acf9c9bfbda5a0619a2374475fe7"
94+
+version = "0.14.12"
95+
+source = "git+https://github.com/rust-embedded/svd.git#36750c1b8dc3c76760cd5569337192bec0ca6749"
96+
dependencies = [
97+
"once_cell",
98+
"regex",
99+
'')
39100
];
40101

41-
# Nix's Rust platform does not support git dependencies in lock files.
42-
# Replace `cargoHash`, copy the lockfile over and provide hashes for git dependencies.
43-
# https://github.com/NixOS/nixpkgs/blob/a84ebe20c6bc2ecbcfb000a50776219f48d134cc/doc/languages-frameworks/rust.section.md#importing-a-cargolock-file-importing-a-cargolock-file
44-
cargoLock = {
45-
lockFile = ./chiptool/Cargo.lock;
46-
outputHashes = {
47-
"svd-parser-0.14.5" = "sha256-r78UZfulqPBegBc5/fOkgGGtv5AN2FjZFVg7g8ii5Qc=";
48-
};
49-
};
50-
51102
meta = with lib; {
52103
description = "SVD to PAC next-gen code generator (${forkOwner} fork)";
53104
mainProgram = "chiptool";

0 commit comments

Comments
 (0)