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 features for kurbo's std/libm features #23

Merged
merged 1 commit into from
Feb 14, 2024

Conversation

ratmice
Copy link
Contributor

@ratmice ratmice commented Feb 6, 2024

This tries to enable the case where people want peniko with a non-default kurbo features selected.
It does not enable the --no-default-features CI tests because we inherit from kurbo the following compile_error when --no-default-features is selected alone.

https://github.com/linebender/kurbo/blob/6ea9f53498749703606f6f8d019fe0bc9080ea30/src/lib.rs#L83

I personally don't use this in a no_std or anything, I just wanted to go through the list of default-features given the pending release.

Copy link
Member

@DJMcNab DJMcNab left a comment

Choose a reason for hiding this comment

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

Thanks for making these changes so quickly

Do we also need #![no_std] at the top of src/lib.rs?

@@ -100,7 +99,7 @@ jobs:
toolchain: ${{ env.MINIMUM_SUPPORTED_RUST_VERSION }}
components: clippy

# We don't currently have features, so there's no need to run these checks
# Because we re-export kurbo features --no-default-features alone is not a valid set features.
Copy link
Member

Choose a reason for hiding this comment

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

Do we instead need to check that we still work with only the libm feature?

Copy link
Contributor Author

@ratmice ratmice Feb 6, 2024

Choose a reason for hiding this comment

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

Probably, perhaps another option might be to: cargo hack --exclude-no-default-features --feature-powerset
This could reduce the number amount of stuff in ci.yml, but that requires bringing cargo hack into the ci, any preferences?

Edit: actually --exclude-no-default-features --feature-powerset isn't quite right, since we do want --no-default-features --features libm to be tested. Probably better to just add that regardless of cargo hack, and that could go in some other patch if it is wanted.

Cargo.toml Outdated Show resolved Hide resolved
@ratmice
Copy link
Contributor Author

ratmice commented Feb 6, 2024

Yeah, probably (as I said I don't really use no_std), but adding that pointed out a few places where we were relying on things in the prelude.

@ratmice
Copy link
Contributor Author

ratmice commented Feb 6, 2024

So, this basically runs into kurbo::common::FloatFuncs being a private trait, and these functions being missing on #![no_std] thoughts on making that pub in kurbo, or duplicating them from peniko?

These started triggering only after I added the #![no_std] 🗡️

@raphlinus
Copy link
Contributor

I'd be open to exporting from kurbo, but I'd also be worried because they're not intended to be complete, just what kurbo needs.

@ratmice
Copy link
Contributor Author

ratmice commented Feb 6, 2024

There is currently one function peniko needs, that kurbo doesn't, that is sin/sinf.
patch for exporting those posted at linebender/kurbo#332

@ratmice
Copy link
Contributor Author

ratmice commented Feb 9, 2024

So, this one is passing CI on top of the kurbo PR which has been approved, so if this one looks okay in theory (minus the hard coded revision), I'll go ahead an land that one, then we can work towards getting rid of that hard coded rev here?

src/lib.rs Outdated
@@ -1,3 +1,4 @@
#![no_std]
Copy link
Member

Choose a reason for hiding this comment

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

I'm surprised we compile with default features enabled now - https://github.com/linebender/kurbo/blob/6ea9f53498749703606f6f8d019fe0bc9080ea30/src/lib.rs#L80 enables this conditionally

Clearly if CI passes, it does work though? Any explanation

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are kind of 2 things going on, the cfg_attr there allows #[test] to use std, even though the library is linked no_std, while peniko currently doesn't have any tests.

The other thing that is relevant is this warning at the bottom of the following:
https://doc.rust-lang.org/reference/names/preludes.html#the-no_std-attribute

Using no_std does not prevent the standard library from being linked in. It is still valid to put extern crate std; into the
crate and dependencies can also link it in.

So, my understanding was that std being a re-export of core, etc, when build with default features this just uses those re-exported libs.

I'm definitely no no_std expert though (that was my assumption though) so in this sense, I understand why the code in your link is doing it conditionally on test, but not on the feature = "std".

Copy link
Contributor Author

@ratmice ratmice Feb 9, 2024

Choose a reason for hiding this comment

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

So, I removed the features = "std" from kurbo leaving just #![cfg_attr(not(test)), no_std)] the thing that is going on there is the svg module in lib.rs #[cfg(feature = "std")] mod svg and uses std freely rather than core/alloc.

This is part of the reason actually that cargo test --no-default-features --features libm breaks on kurbo :D
Because that should be #[cfg(any(feature = "std", test)))] mod svg; I think.

Copy link
Contributor Author

@ratmice ratmice Feb 9, 2024

Choose a reason for hiding this comment

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

Anyhow to summarize my feeling here is that the feature = "std" part of that cfg_attr is specific to kurbo only conditionally exporting the svg module, and this combination becomes pretty fragile. As evidenced by the fact that cargo build --no-default-features --features libm works but cargo test ... compile fails on a few things. So I would rather avoid that aspect.

The test part of the cfg_attr we may want to add now or in the future, but it doesn't currently affect us absent tests.

Copy link
Member

Choose a reason for hiding this comment

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

So, this suggests that to test properly, we need to build Peniko with the libm feature on a platform without the standard library available?
Because at the moment (ignoring Kurbo) the reason that features=std works is because the std float functions are being used, but nothing about the feature itself actually enables those? Is there a cargo command to force non-usage of std on all targets?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ahh, now I see the problem you are indicating, that even though the lib defined #![no_std] and never imports std, the kurbo feature enabling causes std to be included thus f32::sin and friends work without error.

I don't see anything that looks solid beyond what you suggest (building for a target that doesn't have std).
There is some discussion and a PR here.
rust-lang/rust-clippy#1570

Copy link
Contributor

Choose a reason for hiding this comment

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

If it helps, that's why kurbo has a CI thing that builds for thumbv7m-none-eabi.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It does, I had to go with armv7a-none-eabi because of AtomicU64, but tested that that fails with default features,
and succeeds with --no-default-features --libm.

@ratmice ratmice force-pushed the default_features branch 2 times, most recently from 157ddbb to af21d38 Compare February 9, 2024 19:13
Copy link
Member

@DJMcNab DJMcNab left a comment

Choose a reason for hiding this comment

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

Looks good, pending the kurbo release

- name: cargo clippy (all features) (auxiliary)
run: cargo clippy --workspace --tests --benches --examples --all-features -- -D warnings

- run: rustup target add armv7a-none-eabi
Copy link
Member

Choose a reason for hiding this comment

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

I'd probably add this to the step which adds the rust toolchain, similarly to the WASM task

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should be fixed in 241ddb4

@ratmice
Copy link
Contributor Author

ratmice commented Feb 9, 2024

Thank you for all the reviewing Daniel, I went ahead and merged the kurbo patch, so once that has seen a release will update the Cargo.toml here.

@ratmice ratmice added this pull request to the merge queue Feb 14, 2024
Merged via the queue into linebender:main with commit e8e53e4 Feb 14, 2024
9 checks passed
@ratmice ratmice deleted the default_features branch November 4, 2024 18:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants