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 a compilation error if neither std nor libm features are specified #595

Merged

Conversation

LikeLakers2
Copy link
Contributor

@LikeLakers2 LikeLakers2 commented Jan 8, 2025

Glam would previously cryptically error out during compilation, if neither the std nor libm features were specified. This is due to no_std being turned on, which removed many methods from the f32 and f64 primitives, while glam simultaneously would try to use those methods.

To solve this, I added a compilation error if no math backend is specified.

However, this compile_error!() does not silence the compilation errors generated by the use of non-existent methods. To silence them, I added a new module to glam::f32::math and glam::f64::math - one which defines the methods, but points them all to unimplemented!().

The end result is that, if a backend is specified, glam compiles as normal - but if no backend is specified, glam returns a compilation error:

PS $root\bitshifter.glam-rs> cargo build --no-default-features
   Compiling glam v0.29.2 ($root\bitshifter.glam-rs)
error: You must specify a math backend using either the `std` feature or `libm` feature
   --> src\lib.rs:276:1
    |
276 | compile_error!("You must specify a math backend using either the `std` feature or `libm` feature");
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: could not compile `glam` (lib) due to 1 previous error

PS $root\bitshifter.glam-rs> cargo build --no-default-features --features std
   Compiling glam v0.29.2 ($root\bitshifter.glam-rs)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 8.90s

PS $root\bitshifter.glam-rs> cargo build --no-default-features --features libm
   Compiling glam v0.29.2 ($root\bitshifter.glam-rs)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 8.34s

PS $root\bitshifter.glam-rs> cargo build --no-default-features --features std,libm
   Compiling glam v0.29.2 ($root\bitshifter.glam-rs)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 8.31s

@bitshifter bitshifter merged commit 717f05d into bitshifter:main Jan 9, 2025
18 checks passed
@bitshifter
Copy link
Owner

Makes sense, thanks!

@LikeLakers2 LikeLakers2 deleted the compile_error_unless_backend_specified branch January 10, 2025 06:27
@LikeLakers2
Copy link
Contributor Author

No problem! :D

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.

2 participants