Skip to content
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

Add optional zerocopy trait derives #3407

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

Conversation

joshlf
Copy link
Contributor

@joshlf joshlf commented Oct 25, 2023

No description provided.

@rustbot
Copy link
Collaborator

rustbot commented Oct 25, 2023

r? @JohnTitor

(rustbot has picked a reviewer for you, use r? to override)

@joshlf
Copy link
Contributor Author

joshlf commented Oct 25, 2023

I'm uploading this as a draft early so I can run stuff through CI. Definitely not ready for review yet!

@joshlf joshlf force-pushed the zerocopy branch 2 times, most recently from e72740e to 9dd0f1b Compare October 25, 2023 18:07
Copy link
Contributor Author

@joshlf joshlf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: Update tests to exercise this feature.

@joshlf
Copy link
Contributor Author

joshlf commented Oct 25, 2023

@JohnTitor I do a have a question if you happen to have any insight: This PR adds a new Cargo feature which doesn't work on the MSRV of 1.13. I'm looking through the CI infrastructure but don't see an obvious place to put logic to test features only on more recent MSRVs. The README advertises various MSRVs for various features, so I assume such machinery must exist somewhere?

@joshlf joshlf force-pushed the zerocopy branch 6 times, most recently from 73a4cca to e1425e2 Compare October 26, 2023 02:39
@JohnTitor
Copy link
Member

@joshlf
Copy link
Contributor Author

joshlf commented Oct 27, 2023

You can tweak https://github.com/rust-lang/libc/blob/main/build.rs :)

It looks like the current logic in that file automatically enables features unconditionally if the compiler version is high enough (ie, it doesn't require the user to enable the corresponding Cargo feature). Is that the behavior we want here? I assumed y'all would want this to remain optional, but if that's not the case, I'd be happy to make this unconditional following the logic used with the other features.

@JohnTitor
Copy link
Member

Ah, hmm, fair enough.
So, let's just declare a normal Cargo feature then (with the MSRV note on README).

@joshlf
Copy link
Contributor Author

joshlf commented Oct 27, 2023

Sounds good. Do you have a sense of how I could enable this feature in CI, but only when the toolchain version is 1.61 (zerocopy's MSRV) or greater?

@JohnTitor
Copy link
Member

It'd be hacky but something like this should be possible:

libc/ci/build.sh

Lines 69 to 79 in 5e32df0

# Test the 'const-extern-fn' feature on nightly
if [ "${RUST}" = "nightly" ]; then
if [ "${NO_STD}" != "1" ]; then
cargo "+${RUST}" "${BUILD_CMD}" -vv --no-default-features --target "${TARGET}" \
--features const-extern-fn
else
RUSTFLAGS="-A improper_ctypes_definitions" cargo "+${RUST}" "${BUILD_CMD}" \
-Z build-std=core,alloc -vv --no-default-features \
--target "${TARGET}" --features const-extern-fn
fi
fi

@joshlf
Copy link
Contributor Author

joshlf commented Oct 27, 2023

Sounds good! Does this look good to you?

@joshlf joshlf force-pushed the zerocopy branch 4 times, most recently from c038816 to c137795 Compare October 27, 2023 17:00
@joshlf
Copy link
Contributor Author

joshlf commented Oct 27, 2023

Also, do these CI tests test on the MSRV (1.13)? I searched for code that enabled it, and found none:

$ rg '1\.13'
README.md
45:The minimum supported Rust toolchain version is currently **Rust 1.13.0**.

ci/build.sh
191:        if [ "${RUST}" != "1.13.0" ]; then

libc-test/build.rs
1198:            "MS_RMT_MASK" => true, // updated in glibc 2.22 and musl 1.1.13
1424:            "MS_RMT_MASK" => true, // updated in glibc 2.22 and musl 1.1.13

@joshlf joshlf force-pushed the zerocopy branch 2 times, most recently from fc8980d to 333bf03 Compare October 27, 2023 18:35
@@ -130,6 +130,7 @@ cargo-args = ["-Zbuild-std=core"]

[dependencies]
rustc-std-workspace-core = { version = "1.0.0", optional = true }
zerocopy = { version = "0.7.16", optional = true, features = ["derive"] }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leaving a TODO for myself:

  • Rename to zerocopy-0-7
  • Add zerocopy-0-6 (to be removed before merge) to test that multiple version trains work

Since libc doesn't specify an edition, we have to use the legacy approach of importing macros via #[macro_use] extern crate zerocopy;, which may not play nicely with having macros from multiple versions of the same crate. Instead, we may need to update build.rs to detect when the Rust version is early enough that editions are supported, and instruct rustc to use a recent-enough version that we can explicitly import different versions under different names. This would be necessary in case a build requires multiple zerocopy versions simultaneously.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See for more discussion: google/zerocopy#557

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once rust-lang/libs-team#72 gets a conclusion, we can specify the edition.

@JohnTitor
Copy link
Member

Also, do these CI tests test on the MSRV (1.13)? I searched for code that enabled it, and found none:

No, I remember that I removed it at some point as something on the test pipeline had been broken.

@bors
Copy link
Contributor

bors commented Nov 1, 2023

☔ The latest upstream changes (presumably #3393) made this pull request unmergeable. Please resolve the merge conflicts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants