Commit Graph

86 Commits

Author SHA1 Message Date
Ivan Petkov
89eb07f68e
Fix typo 2022-01-17 15:01:58 -08:00
Ivan Petkov
282a3b502a
Add README 2022-01-17 15:01:21 -08:00
Ivan Petkov
67c680b5dc
Move API docs to their own file 2022-01-17 13:56:03 -08:00
Ivan Petkov
405c9cb8cf
Update quick-start template with cargoFmt and cargoTarpaulin 2022-01-17 13:06:11 -08:00
Ivan Petkov
8f6b608ca1
Inline Cargo.{toml,lock} checks in buildDepsOnly 2022-01-16 18:24:13 -08:00
Ivan Petkov
aeb598b174
Add cargoTarpaulin 2022-01-16 18:16:21 -08:00
Ivan Petkov
438154f265
Add cargoFmt 2022-01-16 17:49:39 -08:00
Ivan Petkov
e457182093
Add quick-start template with a clippy check
* Also rename `hello-world` to `quick-start-simple`
2022-01-16 16:56:30 -08:00
Ivan Petkov
725a646c8d
Add CI 2022-01-16 16:15:12 -08:00
Ivan Petkov
e2cc10bb60
Inline template definition in flake.nix 2022-01-16 16:11:11 -08:00
Ivan Petkov
9ef96fbfeb
Add a custom rust toolchain example/template 2022-01-16 15:38:59 -08:00
Ivan Petkov
1ab55bba74
Add hello-world example/template 2022-01-16 14:33:47 -08:00
Ivan Petkov
7f392394e7
Add mkLib function 2022-01-15 20:29:39 -08:00
Ivan Petkov
13c6a4cdce
crateNameFromCargoToml: use 0.0.1 as fallback version 2022-01-15 19:58:31 -08:00
Ivan Petkov
92d185d877
Fix some formatting 2022-01-15 19:56:46 -08:00
Ivan Petkov
8362763342
Add hooks documentation 2022-01-15 17:59:34 -08:00
Ivan Petkov
3967b68793
Add API documentation 2022-01-12 20:11:14 -08:00
Ivan Petkov
72bb21ee86
crateNameFromCargoToml: fix parameter validation
* Previously the check was overzealous and it was impossible to only
  specify `cargoToml` (since both other parameters would be null)
* Instead, we take advantage of Nix's laziness and only throw when
  needed
2022-01-09 15:50:21 -08:00
Ivan Petkov
3f82111135
Merge vendorCargoDepsFromArgs into vendorCargoDeps 2022-01-08 17:52:10 -08:00
Ivan Petkov
bd27ed8f73
cargoClippy: remove unused parameter 2022-01-08 17:24:57 -08:00
Ivan Petkov
49ef407216
Rename doCopyTargetToOutput to doInstallCargoArtifacts
* Similarly rename `installCargoTargetDirHook` to
  `installCargoArtifactsHook`
* The intention is to highlight that "install" implies "copy to output"
  and not anywhere else
* Also avoids the potential confusion of "cargo target dir" (location of
  cargo's artifacts) with "cargo target" (which is the target
  architecture/platform we want cargo to build for)
2022-01-08 17:14:05 -08:00
Ivan Petkov
4099e352b8
cargoClippy: do not force cargo target dir to be installed
* Just having the derivation succeed is evidence enough and copying the
  artifacts isn't strictly necessary
2022-01-08 17:03:06 -08:00
Ivan Petkov
263fe7c78f
Fix operator precedence typo
* In Nix the `or` operator has higher precedence than function
  application, therefore `x or y z` parses as `(x or y) z`
2022-01-08 16:57:45 -08:00
Ivan Petkov
1c9633f4aa
mkDummySrc: allow cargoLock location to be passed in by caller
* This can potentially allow callers to build crates which may not have
  a Cargo.lock in their source but needs to be passed in from
  _elsewhere_
2022-01-07 20:54:07 -08:00
Ivan Petkov
44e9060497
Print cargo version before building
* Just for the benefit of being able to tell at which cargo version is
  used at a glance
2022-01-07 20:48:52 -08:00
Ivan Petkov
abc2c8c418
mkDummySrc: drop dummy lib.rs by default, not main.rs
* There are some edge cases where cargo will allow a lib.rs file to be
  present but not a main.rs (e.g. a binary cannot be called "examples",
  which will happen if the crate is called that and a main.rs file is
  present)
2022-01-07 20:42:24 -08:00
Ivan Petkov
bcec95e215
Add test for rooted workspace 2022-01-07 18:03:12 -08:00
Ivan Petkov
a8c6f256bc
Add tests for a simple workspace 2022-01-07 17:56:12 -08:00
Ivan Petkov
1c8034c0d9
Update mkDummySrc to support cargo workspaces 2022-01-07 17:36:31 -08:00
Ivan Petkov
791f1b2241
Add tests for mkDummySrc
* Also fix a bug with copying over .cargo/config files
2022-01-05 20:46:05 -08:00
Ivan Petkov
daae0bac2b
Rename checks/cleanCargoToml directory for consistency 2022-01-05 20:14:45 -08:00
Ivan Petkov
aa58fce185
Memoize some parameters to avoid recomputing the vendorDir when possible 2022-01-04 18:25:39 -08:00
Ivan Petkov
7ec94f9653
Remove internally used parameters from derivations where possible
* By default we pass everything through to the actual derivation itself,
  but some internal parameters don't show up as environment variables
  directly (or rather do not need to)
* In an effort to keep the build environment as lean as possible, we can
  do some clean up (e.g. to avoid invalidating builds if some parameter
  changes but is completely ignored/overridden elsewhere)
2022-01-04 17:45:31 -08:00
Ivan Petkov
98d59e6a6c
Replace regex dependencies with byteorder
* This should make the tests a bit more lightweight as we only have to
  build one crate instead of several
2022-01-04 14:48:40 -08:00
Ivan Petkov
3da8e2e195
Enable doCheck on derivations by default 2022-01-04 14:40:24 -08:00
Ivan Petkov
ba50659d0d
Rename buildWithCargo to cargoBuild 2022-01-04 14:18:29 -08:00
Ivan Petkov
0f3e3e9a9b
Bring all tests back under nix flake check
* Seems like whatever issue was preventing us from evaluating
  derivations for other architectures (without actually building them)
  has been resolved, and now we can nicely test everything with a single
  invocation of `nix flake check`
2022-01-04 12:55:36 -08:00
Ivan Petkov
66db381bac
Add cargoClippy 2022-01-04 12:07:32 -08:00
Ivan Petkov
ab283fb5f7
Echo all build/check/install commands for easier debugging 2022-01-04 09:49:04 -08:00
Ivan Petkov
359cb53441
Add tests for using cargoExtraArgs
* In this case, we set up a crate with various non-default features and
  ensure that we can correctly influence the cargo build by passing in
  the appropriate `--feature` flag
2022-01-04 09:28:58 -08:00
Ivan Petkov
9b09599c5c
Add tests that cargo features can be set via cargoExtraArgs 2022-01-03 20:19:16 -08:00
Ivan Petkov
3b4e0bffe1
Rename copyCargoTargetToOutputHook to installCargoTargetDirHook
* New name should better reflect that we are _installing to the output_
  rather than copying from some location to another
2022-01-03 19:57:35 -08:00
Ivan Petkov
dc553e3853
Remove installFromCargoArtifactsHook
* This hook was never a great implementation to begin with since it
  would simply search the cargo artifacts directory for binaries and
  libraries to install
* This isn't really great since if we have multiple builds (say one with
  debug artifacts, one with release artifacts) it isn't exactly clear
  which artifacts would get installed (or which will get clobbered).
* Now that we have installFromCargoBuildLogHook we can simplify the
  options a bit and only have one main installation method. The caller
  can always provide their own if they wish
2022-01-03 14:42:59 -08:00
Ivan Petkov
f69c8a4c44
Add buildPackage for building and installing cargo packages 2022-01-03 14:32:51 -08:00
Ivan Petkov
47316bfe5b
Add vendorCargoDepsFromArgs
* This abstracts the path checking and message raised on errors into a
  reusable function
2022-01-03 10:28:56 -08:00
Ivan Petkov
4c1711399d
Split out buildWithCargo into a lower level mkCargoDerivation
* The intention here is to split up different "responsibilities" into
  smaller parts which can be composed as a DAG rather than mutually
  recursive functions. Specifically:
* `mkCargoDerivation` represents a lower-level thin wrapper around
  `stdenv.mkDerivation` which will
  - set up hooks
  - require the caller to define the variables needed by the hooks (like
    vendor dir, or artifacts to inherit)
  - ensure that build/check/install phases can be configured by the
    caller without having them remember to call pre/post hooks
* This allows `buildDepsOnly` to only focus on setting some default
  values (like good default commands to build all artifacts, setting the
  derivation name, etc.) and delegating the rest to `mkCargoDerivation`
* Lastly, the responsibility of `buildWithCargo` ends up ensuring that
  `cargoArtifacts` and `cargoVendorDir` are defined if the caller does
  not pass them in
2022-01-02 14:48:32 -08:00
Ivan Petkov
10a60cc085
Do not copy cargo artifacts into a separate output by default
* Copying the cargo artifacts to their own separate output is a good
  idea *in theory* where each derivation produces bins/libs so that
  other things can depend on them without pulling in the cargo artifacts
  as well
* In practice, it's much more likely that a derivation will produce
  cargo artifacts (to be reused in other build/test steps) XOR produce
  the final binaries
* Therefore _not_ separating the outputs will produce less friction when
  forming dependency trees in the general path (e.g. no more forgetting
  to specify `drv.target`)
* If a caller really wants to install cargo artifacts in a separate
  output, they can easily add the customization themselves
2022-01-01 11:12:13 -08:00
Ivan Petkov
0f94b11615
Update inheritCargoArtifactsHook to be more flexible
* This allows a caller to pass in the path directly to the prepared
  target dir instead of requiring that the input be a path to its
  directory
2022-01-01 11:08:36 -08:00
Ivan Petkov
55ba19ec1c
mkDummySrc: fix handling of bin targets
* First, bin targets go into `src/bin` not `bin`
* Second, the path fallback name needs a `rs` suffix
2021-12-31 19:03:06 -08:00
Ivan Petkov
b4a1445590
cleanCargoToml: retain crate-type
* Some tools may try to inspect crate types (e.g. wasm-pack) so it may
  be useful to retain the attribute
* In general, the crate-type can influence the project's "structure" so
  we should remain faithful to that
2021-12-31 18:40:01 -08:00