Commit Graph

70 Commits

Author SHA1 Message Date
Ivan Petkov
78359792ae
Form paths by concatenating a string suffix not a path
* Seems like Nix can get unhappy if a path fragment is evaluated too
  eagerly, giving errors like
  `error: access to absolute path '/Cargo.toml' is forbidden in pure eval mode (use '--impure' to override)`
* Changing to using string manipulation seems to resolve the issue
2022-02-13 12:50:43 -08:00
Ivan Petkov
a56b6d1c56
cargoTarpaulin: change behavior to install cargo artifacts by default
* This allows potentially chaining `cargoTarpaulin` invocations with other
  derivations
2022-02-13 09:36:31 -08:00
Ivan Petkov
3024283855
cargoClippy: change behavior to install cargo artifacts by default
* This allows potentially chaining `cargoClippy` invocations with other
  derivations
2022-02-13 09:34:26 -08:00
Ivan Petkov
472d7ffc99
Handle case where a git repo contains multiple crates 2022-02-10 20:32:31 -08:00
Ivan Petkov
e2c665091e
Add test that source prefix remapping works 2022-02-09 20:54:56 -08:00
Ivan Petkov
469f4a5fde
Fix git dependency handling of overlapping repos 2022-02-09 20:22:07 -08:00
Ivan Petkov
ca73fc5305
Add support for git dependencies 2022-02-07 20:03:12 -08:00
Ivan Petkov
1ab0cad98c
Split out registry vendoring to vendorCargoRegistries 2022-02-06 17:16:49 -08:00
Ivan Petkov
90d5ad84c4
cargoFmt: change behavior to install cargo artifacts by default
* This allows potentially chaining `cargoFmt` invocations with other
  derivations
2022-02-10 21:02:48 -08:00
Ivan Petkov
d4b5f8abe6
chore: switch to runCommandLocal to reduce network pressure 2022-01-30 16:10:41 -08:00
Ivan Petkov
492076c765 Rename registryFromGitIndex input to indexUrl for consistency 2022-01-30 23:58:56 +00:00
Ivan Petkov
47fbae6dc3 Add support for alternative cargo registries 2022-01-30 23:58:56 +00:00
Ivan Petkov
5e44613211 Make crate downloads aware of alternative registries 2022-01-30 23:58:56 +00:00
Ivan Petkov
5bae4b91c1 Optimize searching for cargo configuration files
* Rather than recursively look up all paths in a given project and then
  filtering for cargo-specific files, we now use our own customized
  traversal method to only capture the results we want.
2022-01-30 23:58:56 +00: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
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
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
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
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
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
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
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
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
Ivan Petkov
e6cdd3df92
cleanCargoToml: strip required-features from target definitions
* Turns out the `required-features` attribute is only used from hiding
  targets from cargo's selection (e.g. do not build unless feature is
  enabled) and does not actually influence what features cargo will
  enable/build for dependencies
2021-12-31 18:34:06 -08:00
Ivan Petkov
64914fbc98
Remove doCompressTarget option
* Reducing the parameter surface area for good measure, zstd compression
  works pretty well and it seems redundant to support multiple ways of
  copying the target directory around
2021-12-30 20:25:33 -08:00
Ivan Petkov
2a14c2d53b
Update crateNameFromCargoToml with better fallback error messages
* If a derivation is created without a name *and* we cannot infer a name
  from a Cargo.toml file, we'll throw a descriptive error message which
  hints towards the remediation
* Otherwise nix can throw a pretty obtuse "derivation has no name" error
  with no error trace
2021-12-30 15:08:45 -08:00
Ivan Petkov
0aadea3b08
Rename buildWithDummySrc to buildDepsOnly 2021-12-30 14:49:52 -08:00
Ivan Petkov
2339d7959f
Add buildWithDummySrc
* This also implements automatically building dependencies in a separate
  derivation if `buildWithCargo` is invoked without `cargoArtifacts`
2021-12-30 14:46:35 -08:00
Ivan Petkov
3223e4860e
Add mkDummySrc 2021-12-30 13:22:05 -08:00