|
40 | 40 | craneLib = crane.mkLib pkgs; |
41 | 41 | src = craneLib.cleanCargoSource ./.; |
42 | 42 |
|
| 43 | + baseArgs = { |
| 44 | + src = craneLib.cleanCargoSource ./.; |
| 45 | + # src = fileSetForCrate; |
| 46 | + }; |
| 47 | + |
| 48 | + # cargoVendorDir |
| 49 | + |
| 50 | + # isLinderaRepo = p: lib.hasPrefix |
| 51 | + # "git+https://github.com/seanmonstar/num_cpus.git" |
| 52 | + # p.source; |
| 53 | + httplz_port = "34567"; |
| 54 | + cargoVendorDir = craneLib.vendorCargoDeps (baseArgs // { |
| 55 | + # Use this function to override crates coming from git dependencies |
| 56 | + # overrideVendorGitCheckout = ps: drv: |
| 57 | + # # For example, patch a specific repository and tag, in this case num_cpus-1.13.1 |
| 58 | + # # if lib.any (p: (isLinderaRepo p) ) ps then |
| 59 | + # # drv.overrideAttrs (_old: { |
| 60 | + # # }) |
| 61 | + # # else |
| 62 | + # # Nothing to change, leave the derivations as is |
| 63 | + # drv; |
| 64 | + |
| 65 | + |
| 66 | + # Use this function to override crates coming from any registry checkout |
| 67 | + overrideVendorCargoPackage = p: drv: |
| 68 | + # For example, patch a specific crate, in this case byteorder-1.5.0 |
| 69 | + if p.name == "lindera-unidic" then |
| 70 | + builtins.trace "MATCHED LINDERA-UNIDIC" drv.overrideAttrs(_old: { |
| 71 | + CARGO_BUILD_RUSTFLAGS = "--verbose"; |
| 72 | + |
| 73 | + # Specifying an arbitrary patch to apply |
| 74 | + # patches = [ |
| 75 | + # ./0001-patch-num-cpus.patch |
| 76 | + # ]; |
| 77 | + |
| 78 | + # Similarly we can also run additional hooks to make changes |
| 79 | + # lindera = { version = "0.43.1" } |
| 80 | + |
| 81 | + postPatch = '' |
| 82 | + echo "PATCHING" |
| 83 | + ls -l |
| 84 | + cat build.rs |
| 85 | + substituteInPlace build.rs --replace-fail \ |
| 86 | + "https://Lindera.dev/unidic-mecab-2.1.2.tar.gz" \ |
| 87 | + "http://localhost:${httplz_port}/unidic-mecab-2.1.2.tar.gz" |
| 88 | +
|
| 89 | + cat build.rs |
| 90 | +
|
| 91 | + ''; |
| 92 | + }) |
| 93 | + else |
| 94 | + # Nothing to change, leave the derivations as is |
| 95 | + drv; |
| 96 | + }); |
| 97 | + |
43 | 98 | # Common arguments can be set here to avoid repeating them later |
44 | 99 | commonArgs = { |
45 | 100 | inherit src; |
| 101 | + inherit cargoVendorDir; |
46 | 102 | strictDeps = true; |
47 | 103 |
|
48 | 104 | buildInputs = |
|
63 | 119 | # so we can reuse all of that work (e.g. via cachix) when running in CI |
64 | 120 | # It is *highly* recommended to use something like cargo-hakari to avoid |
65 | 121 | # cache misses when building individual top-level-crates |
66 | | - cargoArtifacts = craneLib.buildDepsOnly commonArgs; |
| 122 | + cargoArtifacts = (craneLib.buildDepsOnly commonArgs).overrideAttrs(oa: { |
| 123 | + pname = builtins.trace "pname=${oa.pname}" oa.pname; |
| 124 | + |
| 125 | + nativeBuildInputs = oa.nativeBuildInputs ++ [ pkgs.httplz]; |
| 126 | + doCheck = false; |
| 127 | + preBuild = '' |
| 128 | + echo "PATCHING" |
| 129 | + ls -l |
| 130 | + set -x |
| 131 | + ( |
| 132 | + set -x |
| 133 | + # serve lindera-unidic on localhost vacant port |
| 134 | + httplz_port="${ |
| 135 | + if pkgs.stdenv.buildPlatform.isDarwin then |
| 136 | + ''$(python -c 'import socket; s=socket.socket(); s.bind(("", 0)); print(s.getsockname()[1]); s.close()')'' |
| 137 | + else |
| 138 | + "34567" |
| 139 | + }" |
| 140 | + mkdir .lindera-http-plz |
| 141 | + ln -s ${lindera-unidic-src} .lindera-http-plz/unidic-mecab-2.1.2.tar.gz |
| 142 | + httplz --port "$httplz_port" -- .lindera-http-plz/ & |
| 143 | + echo $! >$TMPDIR/.httplz_pid |
| 144 | +
|
| 145 | + echo "$out" |
| 146 | + echo "Trying to substitute" |
| 147 | + ls -l |
| 148 | +
|
| 149 | + # not needed with useFetchCargoVendor=true, but kept in case it is required again |
| 150 | + #newHash=$(sha256sum build.rs | cut -d " " -f 1) |
| 151 | + #substituteInPlace .cargo-checksum.json --replace-fail $oldHash $newHash |
| 152 | + )''; |
| 153 | + |
| 154 | + }); |
67 | 155 |
|
68 | 156 | individualCrateArgs = commonArgs // { |
69 | 157 | inherit cargoArtifacts; |
|
215 | 303 | nixfmt-tree |
216 | 304 |
|
217 | 305 | # Rust |
218 | | - rustToolchain |
219 | | - taplo |
| 306 | + # rustToolchain |
| 307 | + # taplo |
220 | 308 | cargo-shear |
221 | 309 | pkg-config |
222 | 310 | openssl |
|
0 commit comments