Commit graph

329 commits

Author SHA1 Message Date
Patryk Wychowaniec
3aa2c1e1ed readme: Add a section on overrideAttrs
Closes https://github.com/nix-community/naersk/issues/277.
2023-09-07 12:09:25 +02:00
Patryk Wychowaniec
78789c30d6 Fix support for .cargo/config
Before https://github.com/nix-community/naersk/pull/300, our
`builtinz.toTOML` used to return a string representing the serialized
document which was later redirected into a file:

https://github.com/nix-community/naersk/pull/300/files#diff-b6b537316f2d29c8faf178a110366796811d1bc72f694262c7d2efad79aa984bL238

Over that merge request, this was changed to return a path, to make it
consistent with how nixpkgs' formatters work - but I haven't noticed one
place that still _read_ the file instead of returning a path (which was
fine before, since the code did `echo ... > ...`, but is not a correct
thing to do for `cp`).

Closes https://github.com/nix-community/naersk/issues/305.
2023-08-18 11:40:12 +02:00
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
Patryk Wychowaniec
2593eab3ed code review: Pin nixpkgs to master 2023-08-16 11:32:57 +02:00
Patryk Wychowaniec
93844987ae ci: Bump 2023-08-16 11:32:57 +02:00
Patryk Wychowaniec
0e758b9648 Use custom writeTOML on older nixpkgs 2023-08-16 11:32:57 +02:00
Patryk Wychowaniec
eb2bdf3b0f Use TOML serializer from nixpkgs
Closes https://github.com/nix-community/naersk/issues/263
2023-08-16 11:32:57 +02:00
Patryk Wychowaniec
d9a33d69a9 Use checksums for recreating crates.io's directory
Closes https://github.com/nix-community/naersk/issues/138.
2023-07-26 14:15:29 +02:00
Patryk Wychowaniec
711ebec4c2 readme: Add a section on CMake usage 2023-07-26 14:14:20 +02:00
Patryk Wychowaniec
ad0240bbc9 test/agent-rs: Fix for aarch64-darwin 2023-07-26 14:14:20 +02:00
Patryk Wychowaniec
b03316b734 test/nushell: Fix for aarch64-darwin 2023-07-26 14:14:20 +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
Patryk Wychowaniec
a8906d20a9 readme: Add an example of examples
Closes #291.
2023-07-01 18:28: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
4d3bb30b8b Improve README
Closes https://github.com/nix-community/naersk/issues/283.
2023-06-12 13:30:34 +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
5c8dbab3d9 examples: Add multiple-binaries
Closes https://github.com/nix-community/naersk/issues/272.
2023-03-21 07:56:31 +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
Andrew Brooks
d998160d6a Disambiguate branches/tags when invoking builtins.fetchGit 2022-12-15 10:33:36 +01:00
Patryk Wychowaniec
6944160c19 Improve unpacking dependencies 2022-09-03 17:53:20 +02:00
Vladimir Romashchenko
8d2f4d00cb examples: Add i686-pc-windows-gnu to multi-target 2022-09-02 18:37:12 +02:00
Patryk Wychowaniec
c6a45e4277 Revamp examples & README 2022-08-04 12:56:43 +02:00
Daniel Goertzen
cddffb5aa2 remove fetchGit allRefs flag for nix <2.4
Prevent use of allRefs when nix <2.4 is in use.
nix <2.4 does not accept the `allRefs` flag, but has `allRefs` behavior
by default.  Note that this goes beyond the the initial intent of this
PR because it enables naersk's `gitAllRefs` flag to work on nix <2.4.
2022-06-12 16:08:02 +02:00
Daniel Goertzen
e300ddf8cb force fetchGit allRefs when a dependency is specified with "rev"
The usage of git "rev" dependencies in Cargo implies that the rev
will be found regardless of ref.  This is currently not true in naersk;
the following dependency fails:

usbfs = {git = "https://github.com/goertzenator/usbfs-rs", rev = "7c35b46e41ad76f838cd99b493f9337f475b5b70"}
2022-06-12 16:08:02 +02:00
dependabot[bot]
14997a79cd Bump spin from 0.5.0 to 0.5.2 in /test/fast/workspace/fixtures
Bumps [spin](https://github.com/mvdnes/spin-rs) from 0.5.0 to 0.5.2.
- [Release notes](https://github.com/mvdnes/spin-rs/releases)
- [Changelog](https://github.com/mvdnes/spin-rs/blob/master/CHANGELOG.md)
- [Commits](https://github.com/mvdnes/spin-rs/commits)

---
updated-dependencies:
- dependency-name: spin
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-06-07 15:28:37 +02:00
dependabot[bot]
af8ba73597 Bump regex from 1.1.8 to 1.5.5 in /test/fast/workspace-patched/fixtures
Bumps [regex](https://github.com/rust-lang/regex) from 1.1.8 to 1.5.5.
- [Release notes](https://github.com/rust-lang/regex/releases)
- [Changelog](https://github.com/rust-lang/regex/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rust-lang/regex/compare/1.1.8...1.5.5)

---
updated-dependencies:
- dependency-name: regex
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-06-07 15:28:24 +02:00
dependabot[bot]
5b76e39b2a Bump regex from 1.1.8 to 1.5.5 in /test/fast/simple-dep/fixtures
Bumps [regex](https://github.com/rust-lang/regex) from 1.1.8 to 1.5.5.
- [Release notes](https://github.com/rust-lang/regex/releases)
- [Changelog](https://github.com/rust-lang/regex/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rust-lang/regex/compare/1.1.8...1.5.5)

---
updated-dependencies:
- dependency-name: regex
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-06-07 13:21:23 +02:00
dependabot[bot]
1eb62c040d Bump spin from 0.5.0 to 0.5.2 in /test/fast/simple-dep/fixtures
Bumps [spin](https://github.com/mvdnes/spin-rs) from 0.5.0 to 0.5.2.
- [Release notes](https://github.com/mvdnes/spin-rs/releases)
- [Changelog](https://github.com/mvdnes/spin-rs/blob/master/CHANGELOG.md)
- [Commits](https://github.com/mvdnes/spin-rs/commits)

---
updated-dependencies:
- dependency-name: spin
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-06-07 12:38:24 +02:00
dependabot[bot]
97ed834a86 Bump regex from 1.1.8 to 1.5.5 in /test/fast/workspace/fixtures
Bumps [regex](https://github.com/rust-lang/regex) from 1.1.8 to 1.5.5.
- [Release notes](https://github.com/rust-lang/regex/releases)
- [Changelog](https://github.com/rust-lang/regex/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rust-lang/regex/compare/1.1.8...1.5.5)

---
updated-dependencies:
- dependency-name: regex
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-06-07 12:13:04 +02:00
dependabot[bot]
138faef421 Bump regex from 1.3.1 to 1.5.5 in /test/fast/dummyfication/fixtures
Bumps [regex](https://github.com/rust-lang/regex) from 1.3.1 to 1.5.5.
- [Release notes](https://github.com/rust-lang/regex/releases)
- [Changelog](https://github.com/rust-lang/regex/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rust-lang/regex/compare/1.3.1...1.5.5)

---
updated-dependencies:
- dependency-name: regex
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-06-07 12:12:53 +02:00
dependabot[bot]
059feac06f Bump regex from 1.1.8 to 1.5.5 in /test/fast/simple-dep-patched/fixtures
Bumps [regex](https://github.com/rust-lang/regex) from 1.1.8 to 1.5.5.
- [Release notes](https://github.com/rust-lang/regex/releases)
- [Changelog](https://github.com/rust-lang/regex/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rust-lang/regex/compare/1.1.8...1.5.5)

---
updated-dependencies:
- dependency-name: regex
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-06-07 12:12:33 +02:00
ranfdev
69daaceebe Make dummy-src respect cargo fmt 2022-05-24 19:34:10 +02: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
66883c7d6d readme: Fix ./script/gen
I've accidentally broken the script during the recent test refactoring,
since now test.nix doesn't evaluate to an attrset.
2022-05-16 19:33:31 +02:00
Patryk Wychowaniec
f21309b38e refactor: Refactor tests into separate files 2022-05-03 12:41:13 +02:00
Patryk Wychowaniec
e8f9f8d037 Support dependencies with slashes in their names
When a dependency gets fetched from Git, it's possible for its name to
contain slashes - e.g. because the dependency's branch name contains
one:

```
something-something = { git = "...", branch = "JIRA-123/dev" }
```

Currently, because we don't sanitize those slashes, trying to compile
such `Cargo.toml` / `Cargo.lock` would fail - e.g. given a dependency
from branch `JIRA-123/dev`, we'd try to extract it into path
`JIRA-123/dev` instead of something flat such as `JIRA-123_dev`.

This commit fixes this issue by sanitizing all the `nkey`s - basically,
for all dependency paths, we replace `/` with `_`.

The choice of underscore is arbitrary, just seemed like a good fit.
2022-04-18 09:12:25 +02:00
Patryk Wychowaniec
8cc3794788 chore: Add myself to .github/CODEOWNERS 2022-04-16 11:37:57 +02:00
Patryk Wychowaniec
d626f73332 code review: allRefs -> gitAllRefs, refresh README 2022-04-04 20:16:32 +02:00
Florian Franzen
4c9c275343 build: unpack only named git deps (#1)
Instead of unpacking all crates in a git dep, this only unpacks the
crates specified in the cargo lock file.
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
Patryk Wychowaniec
e30ef9a5ce readme: Remove invalid link for Comparison 2022-03-29 11:01:30 +02:00
Maximilian Bosch
2fc8ce9d3c Correctly fetch git tags
Without this change you'd get errors like this when adding a
`git`-dependency to a `Cargo.toml` which is pinned to a tag:

    fetching Git repository 'git://github.com/ma27/nixpkgs-fmt'fatal: couldn't find remote ref refs/heads/v1.2.0-rnix-0.10
    error: program 'git' failed with exit code 128
2021-12-19 22:05:39 +01:00
Ivan Petkov
5415c70453 ci: bump nixpkgs versions
* Update to a more recent revision of nixpkgs
* Add nixpkgs-21.11 for testing
* Add nixpkgs-21.05 for testing
* Drop nixpkgs-20.09, branch is EOL
* Drop nixpkgs-20.05, branch is EOL
* Bump ripgrep-all to v0.9.6 to make tests pass
2021-12-17 10:00:02 +01:00
Anders Christiansen Sørby
ebde51ec0e Fix typo and add target to .gitignore 2021-12-09 13:02:23 +01:00