Commit graph

55 commits

Author SHA1 Message Date
Jos van den Oever
275010712c Look in [workspace.package] for the version number
Since Rust 1.64.0, a workpackage can define a version number that packages
in the workspace can inherit.
2023-08-16 16:01:06 +02:00
Patryk Wychowaniec
9bbe32cccf fix: Use separate sources for crates.io & Git deps 2023-08-16 11:32:57 +02:00
Robin Appelman
abca1fb7a6 add 'fmt' mode 2023-07-05 07:14:43 +02:00
Jens Östlund
714e701eb4 Add support for passing options to the Clippy command 2023-07-01 18:32:46 +02:00
Frarese
df10963b95 cratesDownloadUrl 2023-06-27 09:54:46 +02:00
Robin Appelman
8507af04eb fix clippy mode 2023-06-12 14:14:47 +02:00
Robin Appelman
fd1b74c213 switch from xOnly to mode option 2023-06-12 14:14:47 +02:00
Robin Appelman
9327600ac6 add option to run cargo check/test/clippy instead of building 2023-06-12 14:14:47 +02:00
Patryk Wychowaniec
88cd223801 Fix detection of symlinked Cargo.tomls
This commit fixes a bug introduced in #276 where symlinked Cargo.tomls
wouldn't get detected due to readDir() reporting them as - well -
_symlinks_ instead of regular files.

Note that we continue to keep the `if type == "directory"` condition for
recursion which means that we'll fail to detect "nested" Cargo.tomls if
someone decides to go wild and create workspace with symlinked crates.

That I'm not 100% sure on how to approach, but fortunately cases like
those seem to be practically non-existent (and Crane apparently not
supporting them builds a bit of confidence here as well).

Closes #280.
2023-03-23 11:29:54 +01:00
Patryk Wychowaniec
2b41e666c1 Improve Cargo.toml discovery algorithm
Our current Cargo.toml discovery algorithm is based on reading the main
Cargo.toml and looking at its `workspace.members` - unfortunately, as it
turns out there's actually no requirement for all workspace crates to be
listed there, and some applications do fancy things like:

```toml
[workspace]
members = [ "crates/foo" ]

[dependencies]
foo = { path = "crates/foo" }
bar = { path = "crates/bar" } # whoopsie
```

... which doesn't play nice with Naersk's incremental builds (that is,
the compilation fails unless `singleStep = true;` is turned on).

This commit changes the logic to use a different approach: now we simply
recursively scan the root directory, noting down all the Cargo.tomls we
find; Crane seems to use the same algorithm.

I think the only case where this approach falls short are spurious
Cargo.tomls that are present somewhere in the source directory but are
actually unused - for instance, imagine I'm writing a Cargo clone where
I've got files like `src/tests/broken-manifest/Cargo.toml` - in cases
like these, the current approach will cause the build to fail, because
we will try to fixup a broken Cargo.toml, thinking it's used somewhere.

We could try to handle cases like these by using an even different
approach: instead of traversing the source tree, we could load the main
Cargo.toml and traverse its `workspace.members` + all path-based
dependencies recursively, noting down all the *explicitly present*
Cargo.tomls.

That is, given a top-level manifest of:

```
[workspace]
members = [ "crates/foo" ]

[dependencies]
foo = { path = "crates/foo" }
bar = { path = "crates/bar" }
```

... we'd note down and load `crates/foo/Cargo.toml` +
`crates/bar/Cargo.toml`, and then load _their_ path-based dependencies,
to find all transitive Cargo.tomls that belong to this workspace.

(that is, we have to scan the crates recursively, because `bar` might
depend on `crates/zar` - and that's not an imaginary edge case, that's
actually what happens inside Nushell, for instance.)

I don't have enough time to implement this more extensive approach now,
and IMO the improvement presented here is still an improvement, so I
think it's safe to go with the new-but-still-subpar approach here and
consider the better algorithm in the future :-)

# Testing

All tests pass, I've also made sure that incremental builds are still
incremental.

Closes https://github.com/nix-community/naersk/issues/274
2023-03-21 07:54:44 +01:00
Patryk Wychowaniec
94beb7a3ed Add support for the postInstall hook
During compilation, we build two derivations - one for the dependencies
and another for the user's crate itself. Passing `postInstall` to
`buildPackage` pass-throughs it into both derivations, which is not what
most users would probably expect.

This commit adds `postInstall` as an explicit configuration option (so
that it's neatly documented), zeroing it out for the dependencies-only
derivation.

I don't think there's any use case for something like `postInstallDeps`,
so it's not introduced here.

Closes https://github.com/nix-community/naersk/issues/237
2022-05-16 19:33:31 +02:00
Patryk Wychowaniec
d626f73332 code review: allRefs -> gitAllRefs, refresh README 2022-04-04 20:16:32 +02:00
Yusuf Bera Ertan
99c7fce671 feat: optional submodule fetching 2022-04-04 20:16:32 +02:00
Yusuf Bera Ertan
8be5c0059d feat: simplify git dependency detection by only using cargo lock, allRefs support 2022-04-04 20:16:32 +02:00
Anders Christiansen Sørby
ebde51ec0e Fix typo and add target to .gitignore 2021-12-09 13:02:23 +01:00
Anders Christiansen Sørby
ec031156ca Throw a better error when Cargo.lock is missing 2021-12-09 13:02:23 +01:00
Anders Christiansen Sørby
67be312127 Throw a better error when Cargo.lock is missing 2021-12-09 13:02:23 +01:00
Eli Flanagan
5bed2dbf07 ci: attempt to fix readme test
From what I can tell the readme test is failing because the config.nix differs from the README.md source

To regenerate the README, run:
```sh
./script/gen
```
and commit the results.
2021-11-01 15:38:16 +01:00
Dawid Ciężarkiewicz
08afb3d1db Don't rely on unstable flags 2021-09-07 10:44:10 +02:00
Nicolas Mattia
df71f5e4ba Revert "Don't rely on unstable flags."
This reverts commit f9e6e8dd78. We should
`export CARGO_TARGET_DIR`, otherwise subsequent `cargo` calls will
rebuild everything (because they won't find the target dir).
2021-08-23 10:26:39 +02:00
Dawid Ciężarkiewicz
f9e6e8dd78 Don't rely on unstable flags. 2021-08-23 09:54:46 +02:00
Milan Pässler
683f785848 add cargoDocOptions and cargoDocCommands 2021-04-19 16:47:23 +02:00
Léo Gaspard
bc1069f52a expose copySource for dealing with path-based dependencies 2021-01-18 14:39:52 +01:00
Nicolas Mattia
22b96210b2 Make top-level override easier
This adds `overrideMain f` which is equivalent to calling
`drv.overrideAttrs f`.
2020-10-08 18:05:41 +02:00
Nicolas Mattia
dcee40445c Disable copyLibs by default
Most of the time we only want the executables.
2020-07-20 12:18:14 +02:00
Nicolas Mattia
20ec73e49b Move copyLibs documentation to code 2020-07-20 12:18:14 +02:00
Moritz Angermann
876c051887 Adds support for collecting libs
Using rust as library provider requires us to collect the
libraries (shared and static) to link against.

Ideally we'd also copy headers, but I didn't find those yet.

Fixes #104
2020-07-20 12:18:14 +02:00
Tobias Happ
0b7c5880c0 Add nativeBuildInputs as config parameter 2020-04-14 10:45:11 +02:00
Sean Bennett
a57c617636 Change to hasSuffix 2020-03-20 12:27:48 +01:00
Sean Bennett
96d36884e7 Make sure expandMember works with a trailing slash 2020-03-20 12:27:48 +01:00
Nicolas Mattia
1538d66ea1 Remap path prefix dynamically 2020-02-18 18:52:59 +01:00
Nicolas Mattia
d6c055717b Set doCheck in test.nix 2020-02-18 15:55:26 +01:00
Nicolas Mattia
d6ba33f942 Forward extra arguments to mkDerivation 2020-02-18 15:55:26 +01:00
Nicolas Mattia
c435f39d6b Fallback to message-format=json for cargo < 1.38 2020-02-12 14:35:11 +01:00
Nicolas Mattia
206cf17e20 Add copyBinsFilter option for configuring which executables are copied 2020-02-10 14:03:08 +01:00
Nicolas Mattia
7b5659aacd Use --message-format for finding executables
Use message-format for executable list
2020-02-10 14:03:08 +01:00
Nicolas Mattia
fe0e683d1d Only accept function in allowFun params 2020-02-10 12:53:55 +01:00
Nicolas Mattia
362405f643 Document environment variables 2020-02-10 12:53:55 +01:00
Nicolas Mattia
6a33730b34 Document and format config.nix 2020-02-10 12:53:55 +01:00
Nicolas Mattia
92432c40d9 Disable --locked by default 2020-02-10 12:53:55 +01:00
Nicolas Mattia
45bee2e6b5 Refactor config.nix for cargo options 2020-02-10 12:53:55 +01:00
Nicolas Mattia
560601e3ab Expand wildcard members in manifests 2020-01-14 19:50:32 +01:00
Nicolas Mattia
f5dce6453d Disable doDoc by default
The documentation building step takes a fair bit of time and most users
won't care about it. By default we turn it off.
2019-12-19 10:59:02 +01:00
Nicolas Mattia
cfbaf2a6f2 Clean up git dependency code 2019-12-17 17:03:10 +01:00
Nicolas Mattia
47b22494d9 Add experimental support for git dependencies 2019-12-16 10:33:10 +01:00
Nicolas Mattia
b9310fdcf7 Add global cargo options to config 2019-12-16 10:32:44 +01:00
Nicolas Mattia
1d18095496 Generate configuration documentation from code 2019-12-02 20:30:50 +01:00
Nicolas Mattia
cd6d9bcec3 Add basic documentation parser 2019-12-02 16:44:45 +01:00
Nicolas Mattia
ad0580c8d8 Split source between src and root 2019-11-21 15:46:20 +01:00
zimbatm
9a72012540
stylistic changes
these are not mandated by nixpkgs-fmt
2019-11-19 20:12:42 +00:00