Commit Graph

29 Commits

Author SHA1 Message Date
Ivan Petkov
5c8e7f732f
Fix callPackage scopes for build hooks so cross compiling works
* Previously all build hooks were instantiated in a single
  `callPackages` call which led to several issues:
  - changes via `lib.overrideScope'` were ignored because the build
    hooks were only ever instantiated with the nixpkgs instance of our
    flake (not whatever overlays the caller may have made)
  - the pkgs splicing was not done quite right, meaning when we pull in
    the build hooks as nativeBuildInputs the splicing wasn't picking up
    the overridden versions of `cargo` but was instead trying to
    recompile the nixpkgs version each time
2022-02-14 18:31:45 -08:00
Ivan Petkov
f0612a9940
configureCargoVendoredDepsHook: tweak logging
* Make it more obvious exactly which file is being used for vendoring
  (when a manifest is found) instead of just printing out the parent
  directory
2022-02-06 17:17:47 -08:00
Bernardo Meurer
91c9a89625
fix(pkgs): use zstd from pkgsBuildBuild
This allows for crane to work when `buildPlatform != hostPlatform`, such
as well `crossSystem` is set.
2022-02-08 18:23:55 -08:00
Ivan Petkov
47fbae6dc3 Add support for alternative cargo registries 2022-01-30 23:58:56 +00:00
Ivan Petkov
92d185d877
Fix some formatting 2022-01-15 19:56:46 -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
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
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
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
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
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
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