Commit Graph

638 Commits

Author SHA1 Message Date
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
6b9ebe7220
Restructure cleanCargoToml tests 2021-12-31 18:29:43 -08:00
Ivan Petkov
8d6d973261
Make remapSourcePathPrefixHook potentially customizable 2021-12-31 18:18:19 -08:00
Ivan Petkov
32ca849598
Make build hooks potentially customizable
* Hook functions now will accept any relevant arguments and fall back to
  our default variables if they are not provided, potentially allowing
  them to be adapted externally (without needing more configuration
  knobs on our end)
2021-12-31 17:43:56 -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
38006226c1
Add more tests 2021-12-30 20:12:52 -08:00
Ivan Petkov
59b21c0335
Add test cases that the two phase build works 2021-12-30 18:44:19 -08:00
Ivan Petkov
6925af0d0b
Move all tests (except for formatting) out of flake checks
* `nix flake check` insists on evaluating all outputs for all systems,
  which seems to include evaluating build inputs needed for other
  systems (which gives us errors like `a 'aarch64-darwin' with features
  {} is required to build '...', but I am a 'x86_64-linux'`)
* To work around this we'll move all tests to their own directory
  outside of the flake's outputs, and manually invoke a test script to
  build them
2021-12-30 17:18:17 -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
Ivan Petkov
4a515f43ca
cleanCargoToml: do not replace path attributes
* Keep the paths as specified in the Cargo.toml while cleaning, leaving
  it up to the caller to replace them if necessary
2021-12-30 10:04:12 -08:00
Ivan Petkov
234257c239
cleanCargoToml: do not strip edition fields
* The edition entries can affect cargo behavior, not just rustc
  behavior, so we should keep them in for consistency with what the
  project expects
2021-12-30 09:44:50 -08:00
Ivan Petkov
cf1c6eb0e8
Add checks for cleanCargoToml 2021-12-29 19:26:55 -08:00
Ivan Petkov
a286fe1ff5
Add cleanCargoToml 2021-12-29 16:03:39 -08:00
Ivan Petkov
e6a6ad68b1
Change default buildPhase to run cargo build 2021-12-28 18:54:51 -08:00
Ivan Petkov
2730271710
Make copyCargoTargetToOutputHook even more lazy
* Instead of always installing the hook but bailing early based on the
  configuration, we will instead only install the hook if the
  configuration requests it
2021-12-28 18:53:05 -08:00
Ivan Petkov
ade4ea7137
Add some documentation around the buildWithCargo parameters 2021-12-28 18:51:44 -08:00
Ivan Petkov
6cc3ea3199
Add remapSourcePathPrefixHook 2021-12-28 18:51:06 -08:00
Ivan Petkov
bf17616560
Add installFromCargoArtifactsHook 2021-12-28 17:51:51 -08:00
Ivan Petkov
dd3fa0123b
Rename inheritCargoTargetHook to inheritCargoArtifactsHook
* Hopefully the updated name should be more clear that we are inhering
  some existing cargo artifacts and NOT inheriting something like
  CARGO_BUILD_TARGET which refers to the host target being built
2021-12-28 16:48:12 -08:00
Ivan Petkov
46e6e54b3b
Update inheritCargoTargetHook to run after source patching
* This allows us to copy over the cargo artifacts as early as possible
  so that any other phases/hooks (like running clippy) can take
  advantage of the cache
* It also avoids installing the artifacts too soon (and making them
  older than the source) and having cargo invalidate them
2021-12-28 16:15:57 -08:00
Ivan Petkov
7b80c23eb5
Update configureCargoVendoredDepsHook to use $CARGO_HOME/config.toml
* Rather than clobbering the project's .cargo/config.toml file (if it
  exists), the setup hook will update the base configuration used in
  $CARGO_HOME/config.toml
* This potentially allows for projects who know what they are doing to
  more easily replace their own sources, while falling back to our
  configuration
2021-12-28 16:05:20 -08:00
Ivan Petkov
c10fd1c8b1
Set CARGO_HOME in configureCargoCommonVarsHook
* This will define CARGO_HOME to $PWD/.cargo-home to ensure that cargo
  never tries to look for a missing HOME directory as it's default
  location
* The hook is also added to `postPatchHooks` (instead of
  `preConfigureHooks`) to ensure that it runs before all other
  configuration-related hooks
2021-12-28 16:00:50 -08:00
Ivan Petkov
fab2fa93cc
Explicitly define more defaults for buildWithCargo
* This should make it a bit easier to tell at a glance what inputs are
  significant for the derivation without having to look at the entire
  source (and corresponding hooks)
2021-12-28 15:27:49 -08:00
Ivan Petkov
65b984b4aa
Rename doCopyTarget to doCopyTargetToOutput
* The intention is to make it more clear that this flag controls copying
  the target directory so that *other* derivations can use it, and DOES
  NOT control whether we use an *existing* target directory from another
  derivation
2021-12-28 15:19:10 -08:00
Ivan Petkov
b8d083cd7e
Implement automatically setting up a vendor dir from source
* If the source root contains a Cargo.lock file it will be used to
  create a vendor directory
* Otherwise a (descriptive) error will be thrown describing how to
  remediate
* The caller can, of course, manually specify their own `cargoVendorDir`
  which will skip the default vendoring
2021-12-28 15:15:10 -08:00
Ivan Petkov
5abd4f6054
Implement compressing cargo target directory 2021-12-26 20:25:36 -08:00
Ivan Petkov
edcb983805
Change doCopyTarget to always imply a separate output
* We can simplify the configuration by removing the
  `doCopyTargetToSeparateOutput` parameter
* If a caller wants to copy target artifacts into any other output, it
  is pretty trivial for them to add their own logic for it
2021-12-26 20:11:22 -08:00
Ivan Petkov
2d9788eb8b
Add copyCargoTargetToOutputHook 2021-12-26 18:06:19 -08:00
Ivan Petkov
c2d7d083d5
Add configureCargoCommonVarsHook 2021-12-26 17:17:39 -08:00
Ivan Petkov
e1b7cea23c
Add buildWithCargo as a thin wrapper around mkDerivation 2021-12-26 16:27:09 -08:00
Ivan Petkov
83632355d2
Add configureCargoVendoredDepsHook 2021-12-26 16:21:08 -08:00
Ivan Petkov
3af378cfd7
Implement vendoring cargo dependencies 2021-12-26 14:05:23 -08:00
Ivan Petkov
2cec871d53
Initial commit 2021-12-26 11:47:59 -08:00