-
Notifications
You must be signed in to change notification settings - Fork 196
stop enabling dependencies in build.rs by default? #680
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I'm confused about what's happening here. If I understand correctly, you're enabling the "use-libc" feature in your build. In rustix's Cargo.toml, it has: use-libc = ["libc_errno", "libc"] Enabling "use-libc" ought to pull in the "libc" dependency, without build.rs' help. |
The project under discussion is https://github.com/coreos/coreos-installer/ which is not enabling I'm pretty sure (but not 100%) that the chain of events here is:
Then tempfile updates to pull that in: Then coreos-installer bumps to that version of tempfile: And because coreos-installer didn't (but does now) test a build from vendored sources we didn't detect that that PR broke the build. I've reduced the failing case to
And then:
Whereas if I revert to an earlier
Then things build fine. |
In a nutshell again, I think the problem is that rustix 0.37's default build (without any features set) has a dynamic dependency on And if we're going to depend on libc by default, then it seems to me we can just drop all the gyrations here in |
Actually a required ingredient here too in this chain of events I think is Because if errno hadn't done an incompatible semver bump, then there would have only been one version in the dependency graph. (It's why |
There's actually one more ingredient necessary for this failure to appear, which is that coreos-installer was using
Whereas some of our other projects include It's really one of those "perfect storm" issues 😄 |
In your reduced testcase, the error is:
This is odd, because it's not saying that the When I try that example (and fix the missing $ ls -l target/vendor/errno*/src/lib.rs
-rw-rw-r-- 1 sunfish sunfish 0 Jun 6 13:55 target/vendor/errno-0.2.8/src/lib.rs
-rw-rw-r-- 1 sunfish sunfish 0 Jun 6 13:55 target/vendor/errno-dragonfly/src/lib.rs
-rw-r--r-- 1 sunfish sunfish 3744 Jun 6 13:55 target/vendor/errno/src/lib.rs
$ errno-0.2.8's src/lib.rs is not empty, but the vendored file that I get here is. The build says it's getting errno-0.2.8 here:
and the src/lib.rs in that directory is not empty. Is cargo-vendor-filterer deleting the contents of src/lib.rs? |
Yes, that's how cargo-vendor-filterer works. (And it does this because it believes the crate is unused) See rust-lang/cargo#7058 (comment) where this approach was originally proposed a long time ago because it's possible without invasive changes to cargo. |
Backing up a higher level; it's certainly within your rights to say that cargo-vendor-filterer should be invoking But two things:
|
I should clarify that I don't think this is any kind of urgent issue because IMO everyone using cargo-vendor-filterer and targeting Linux systems in general is almost certainly going to want to use the new tier = "2" filtering which happens to work around this today., But it's just a fragile fix because if rustix ever did the "no-libc" path for s390x it'd re-break. |
I'm open to making changes here, it's just that there are a lot of moving parts here, and I don't fully understand what's happening yet. I don't think there are any dynamic dependencies here. What build.rs does is dynamically print "cargo:rustc-cfg=libc", which has the effect of adding |
I just came across this issue and I think I know what's going on. I needed to deal with a very similar problem when I wrote the functionality that detects "foreign target" dependencies in our "rust2rpm" packaging tooling (and a bug in the first version of that function caused me to report #439, only to realize later that the bug was on my side). If you're stripping dependencies from the vendor tarball based on logic that the target is Basically, you need the same logic that I ended up implementing in rust2rpm (i.e. dependencies MUST NOT be stripped if they are needed on any supported target platform). So this is a bug in cargo-vendor-filterer, not in rustix. The updated code in "rust2rpm" that now produces correct results is here: https://pagure.io/fedora-rust/rust2rpm/blob/main/f/rust2rpm/cfg.py, and specifically, the "if |
Hi @decathorpe thanks for commenting here. At a higher level there's some architectural overlap between rust2rpm and cargo-vendor-filterer and it may make sense to share code in the future. It feels to me like vendor-filterer is basically a more generally useful, less-tied-to-rpm tool and what may make sense in the future is to have rust2rpm e.g. parse metadata filtered through vendor-filterer or so.
Indeed, this part is the bug in coreos-installer's config. And a bug which has now been fixed by coreos/coreos-installer@84efd15 In this case I'd say that cargo-vendor-filterer was doing exactly what it was asked to do. (But it's not the effect we wanted, we wanted again something compatible with the Linux architectures we care about). I would guess that rust2rpm is always filtering dependencies to all of the Fedora-supported primary architectures, right? So if it had a bug, I think it'd be a different bug. |
Yes, there's some amount of overlap, but the approach taken is different. IIUC cargo-vendor-filterer replaces crate sources with empty files, while rust2rpm patches Cargo.toml files (which is, IMO, the cleaner approach).
That is the case now, but the original code had a very similar flaw (i.e. it only checked for compatibility with the host platform, not for any supported host platform, which resulted in a) architecture-specific patches, and b) wrong results if host platform != target platform). These two patches fixed the issue in rust2rpm:
As far as I can tell, the second commit is basically equivalent to the change you linked for the cargo-vendor-filterer configuration in coreos-installer. |
Hmmm...ah, wow I hadn't realized that rust2rpm has its own implementation of Cargo.toml evaluation! In vendor-filterer we just fork off
Hmmm...I'd say the effect is equivalent yes. Anyways long story short I still feel there's something odd going on with the build.rs here, but the status quo is still true so there's no urgency. |
No, we don't have our own evaluation. We use
Nothing weird is going on in build.rs, as far as I can tell. All the logic for enabling and disabling dependencies lives in Cargo.toml. The only thing that build.rs script can do is to do the equivalent of passing |
(I'm basically using issues as a communication mechanism here)
See coreos/cargo-vendor-filterer#71
TL;DR when rustix 0.37 came along with a2c6c7a this ended up enabling
libc
by default and that pulled in theerrno
dependency by default.However,
cargo metadata
doesn't see this dependency, it's only enabled viabuild.rs
.And that ends up breaking
cargo vendor-filterer
.Since in reality, libc is enabled by default, ISTM we can rework the features and build scripts here right?
The text was updated successfully, but these errors were encountered: