Commit graph

37 commits

Author SHA1 Message Date
exfalso
e7a060f655 Fix .cargo-home/config warning on nightly, bump probe-rs 2024-04-19 11:58:44 +02:00
Patryk Wychowaniec
3f976d822b Support unused dependencies
Cargo stashes unused patches into a special section of the Cargo.lock
file:

```
[[patch.unused]]
name = "uuid"
version = "1.4.1"
source = "git+https://github.com/uuid-rs/uuid#50f70278de02c106650b8d6deb325dd59b5f2a24"
```

... a section that we, currently, don't read.

Ignoring that section causes the build to fail because even if the patch
is unused, when the source is unavailable, Cargo tries to fetch it
(which, understandably, is not possible inside the sandbox).

This commit extends our logic so that we download both the "used" and
"unused" dependencies.

Closes https://github.com/nix-community/naersk/issues/308.
2023-09-07 12:09:35 +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
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
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
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
6944160c19 Improve unpacking dependencies 2022-09-03 17:53:20 +02:00
Patryk Wychowaniec
c6a45e4277 Revamp examples & README 2022-08-04 12:56:43 +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
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
Nicolas Mattia
f5ecd757b3 Add default-run failing test 2020-11-13 12:33:04 +01:00
Sean Bennett
96d36884e7 Make sure expandMember works with a trailing slash 2020-03-20 12:27:48 +01:00
Bas van Dijk
3e1f71f453 Support branch and tag attributes in git sources 2020-03-16 13:08:01 +01:00
Nicolas Mattia
65e8bba46a Add reproduction for workspace build.rs failure 2020-02-11 23:44:42 +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
560601e3ab Expand wildcard members in manifests 2020-01-14 19:50:32 +01:00
Nicolas Mattia
32b0dd73d9 Fix failure on duplicate git dependencies
The git dependencies were indexed by crate name, which is an issue if a dependency is imported through git at various commits. Moreover, if a crate is imported several time at _the same commit_, it is now unpacked only once.
2020-01-10 11:52:24 +01:00
Nicolas Mattia
47b22494d9 Add experimental support for git dependencies 2019-12-16 10:33:10 +01:00
Bas van Dijk
59921aa707 Copy paths from the [patch] section into the dummy-src
This allows users to override the source of crates using:

```
[patch.crates-io]
bar = { path = 'my/local/bar' }
```
2019-10-29 14:57:28 +01:00
Bas van Dijk
a9cade2ca2 Remove build scripts during dummyfication
Otherwise builds fail with an error like:

Compiling simple-dep v0.1.0 (/private/var/folders/5h/b11m6fxj2tqgbxwz5bgjy42c0000gn/T/nix-build-some-name.drv-0/dummy-src)
error: couldn't read build.rs: No such file or directory (os error 2)
2019-10-09 16:33:27 +02:00
Nicolas Mattia
566c70a395 Properly fixup cargo tomls for dep build 2019-10-09 10:37:22 +02:00
Nicolas Mattia
4c2daf7ccd Fix workspaces 2019-07-11 11:39:40 +02:00
Nicolas Mattia
0068d11d38 POC of incrementality 2019-06-27 12:43:01 +02:00
Nicolas Mattia
d8de7a0c2e wip 2019-06-24 18:04:34 +02:00