|
20 | 20 | files |
21 | 21 | # Classes for which to generate implementations for (default lbf-prelude classes). |
22 | 22 | , classes ? [ ] |
23 | | - , # Dependencies to include in the Cabal's `build-depends` stanza. |
| 23 | + , # Dependencies to include in the Cargo's `dependencies` section. |
24 | 24 | # examples: dependencies = [ "lbf-prelude" ] |
25 | 25 | dependencies ? [ ] |
26 | 26 | , configs ? [ ] |
27 | | - , # Name of the package and also the name of the Cabal package. |
| 27 | + , # Name of the package and also the name of the Cargo crate. |
28 | 28 | # Examples: name = "lbf-myproject" |
29 | 29 | name |
30 | | - , # Version of the package and also the version of the Cabal package. |
| 30 | + , # Version of the package and also the version of the Cargo crate. |
31 | 31 | # Examples: version = "0.1.0.0" |
32 | 32 | version ? "0.1.0" |
33 | 33 | }: { inherit src imports files classes dependencies configs name version; }; |
|
67 | 67 |
|
68 | 68 | cargoTemplate = opts: with (lbfRustOpts opts); |
69 | 69 | pkgs.writeTextFile { |
70 | | - name = "lambda-buffers-cabal-template"; |
| 70 | + name = "lambda-buffers-cargo-template"; |
71 | 71 | text = '' |
72 | 72 | [package] |
73 | 73 | name = "${name}" |
|
78 | 78 | ''; |
79 | 79 | }; |
80 | 80 |
|
81 | | - # |
| 81 | + # This is a lookup table of default crate versions used by lamba-buffers modules |
| 82 | + # Based on the contents of `build.json` a subset of these will be attached to the |
| 83 | + # Cargo.toml file |
82 | 84 | crateVersions = pkgs.writeTextFile { |
83 | 85 | name = "lambda-buffers-crate-versions"; |
84 | 86 | text = '' |
|
108 | 110 | DEPS=$(echo ${builtins.concatStringsSep " " dependencies} $(cat build.json | jq -r ".[]" | sort -u)); |
109 | 111 | echo "Gathered Cargo deps $DEPS"; |
110 | 112 | cat ${cargoTemplate opts} > Cargo.toml; |
| 113 | + # Using the lookup table `crateVersions`, filling in the library version. |
| 114 | + # If no version is found, we default to a local path dependency, pointing to |
| 115 | + # a sibling directory (directory in extra-sources or .extras) |
| 116 | + # e.g.: for `lbr-prelude` we print `lbr-prelude = { path = "../lbr-prelude" } |
111 | 117 | for DEP in $DEPS; do |
112 | 118 | if [ $DEP != "std" ]; then |
113 | 119 | echo "$(cat ${crateVersions} | grep "$DEP" || echo "$DEP = { path = \"../$DEP\" }")" >> Cargo.toml |
|
128 | 134 | chmod -R u+w $out/src |
129 | 135 | pushd $out/src |
130 | 136 |
|
| 137 | + # Collecting modules of the library and attaching a module declaration |
| 138 | + # to parent modules. Any directory in the path must also |
| 139 | + # be considered as a module (e.g. for `foo/bar/baz.rs` we have to create |
| 140 | + # `lib.rs`, `foo.rs`and `foo/bar.rs`) |
131 | 141 | MODS=$(find . -type f -name "*.rs") |
132 | 142 | MODS+=" " |
133 | 143 | MODS+=$(find . -type d) |
|
0 commit comments