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

Build error using --no-default-features #6

Closed
riklus opened this issue Feb 17, 2023 · 7 comments
Closed

Build error using --no-default-features #6

riklus opened this issue Feb 17, 2023 · 7 comments

Comments

@riklus
Copy link

riklus commented Feb 17, 2023

My Issue

System info: MacBook Pro Retina Late-2013 (Intel)

  • cargo 1.67.1 (8ecd4f20a 2023-01-10)
  • rustc 1.67.1 (d5a82bbd2 2023-02-07)
  • Target: x86_64-apple-darwin

To reproduce this bug:

  1. Clone this repo with the --recurse-submodules option and cd rs-nfc1-sys
  2. Run cargo check --no-default-features
   Compiling memchr v2.5.0
   Compiling glob v0.3.1
   Compiling libc v0.2.139
   Compiling proc-macro2 v1.0.51
   Compiling cfg-if v1.0.0
   Compiling quote v1.0.23
   Compiling unicode-ident v1.0.6
   Compiling clang-sys v1.4.0
   Compiling log v0.4.17
   Compiling minimal-lexical v0.2.1
   Compiling syn v1.0.107
   Compiling nom v7.1.3
   Compiling libloading v0.7.4
   Compiling regex-syntax v0.6.28
   Compiling either v1.8.1
   Compiling bindgen v0.63.0
   Compiling which v4.4.0
   Compiling regex v1.7.1
   Compiling cexpr v0.6.0
   Compiling shlex v1.1.0
   Compiling lazy_static v1.4.0
   Compiling peeking_take_while v0.1.2
   Compiling rustc-hash v1.1.0
   Compiling lazycell v1.3.0
   Compiling bitflags v1.3.2
   Compiling pkg-config v0.3.26
   Compiling cc v1.0.79
   Compiling nfc1-sys v0.3.1 (/Users/username/github/rs-nfc1-sys)
error[E0463]: can't find crate for `cmake`
 --> build.rs:2:1
  |
2 | extern crate cmake;
  | ^^^^^^^^^^^^^^^^^^^ can't find crate

warning: unused macro definition: `on_by_feature`
  --> build.rs:15:14
   |
15 | macro_rules! on_by_feature {
   |              ^^^^^^^^^^^^^
   |
   = note: `#[warn(unused_macros)]` on by default

error[E0425]: cannot find function `make_source` in this scope
   --> build.rs:225:3
    |
225 |         make_source(&nfc_dir, &out_dir)
    |         ^^^^^^^^^^^ not found in this scope

Some errors have detailed explanations: E0425, E0463.
For more information about an error, try `rustc --explain E0425`.
warning: `nfc1-sys` (build script) generated 1 warning
error: could not compile `nfc1-sys` due to 2 previous errors; 1 warning emitted

Seems like disabling all features also disables cmake that it's needed to link the libraries.

I encountered this problem here as well: alexrsagen/rs-nfc1#8 (comment)

The fixes I tried

By reenabling cmake with this cargo check --no-default-features --features=cmake:

   Compiling nfc1-sys v0.3.1 (/Users/username/github/rs-nfc1-sys)
warning: unused macro definition: `on_by_feature`
  --> build.rs:15:14
   |
15 | macro_rules! on_by_feature {
   |              ^^^^^^^^^^^^^
   |
   = note: `#[warn(unused_macros)]` on by default

error[E0425]: cannot find function `make_source` in this scope
   --> build.rs:225:3
    |
225 |         make_source(&nfc_dir, &out_dir)
    |         ^^^^^^^^^^^ not found in this scope

For more information about this error, try `rustc --explain E0425`.
warning: `nfc1-sys` (build script) generated 1 warning
error: could not compile `nfc1-sys` due to previous error; 1 warning emitted

The function make_source is not found in the scope that's because the function is declared like this:

rs-nfc1-sys/build.rs

Lines 118 to 119 in 6247d15

#[cfg(feature = "vendored")]
fn make_source(nfc_dir: &PathBuf, out_dir: &PathBuf) -> Package {

And by disabling all features we also disable the vendored feature and the function make_source goes out of scope. A fix for this could be removing the #[cfg(feature = "vendored")] macro since the control on the feature is also done in the main

rs-nfc1-sys/build.rs

Lines 224 to 229 in 6247d15

let libnfc_pkg = if cfg!(feature = "vendored") {
make_source(&nfc_dir, &out_dir)
} else {
find_libnfc_pkg(cfg!(target_feature = "crt-static"))
.expect("libnfc not found.")
};

Done that it compiles and all tests pass. ✅

   Compiling nfc1-sys v0.3.1 (/Users/username/github/rs-nfc1-sys)
    Finished dev [unoptimized + debuginfo] target(s) in 17.89s

Suggestions

Disabling all features shouldn't make the module not buildable.

Solutions could be:

  • Declaring cmake as not optional?
  • Remove the #[cfg(feature = "vendored")] macro on make_source?

Let me know what you think an I could pull a request to fix these.

@alexrsagen
Copy link
Owner

Thanks for reporting this (great description and good detail!)

I've implemented some of your suggestions in #7 and tested using cargo check --no-default-features before and after.

I believe this should be solved in 0.3.2, can you confirm @riklus ?

@riklus
Copy link
Author

riklus commented Mar 11, 2023

Tried compiling and it returns this error:

error[E0433]: failed to resolve: use of undeclared crate or module `cmake`
   --> build.rs:112:18
    |
112 |     config: &mut cmake::Config,
    |                  ^^^^^ use of undeclared crate or module `cmake`

For more information about this error, try `rustc --explain E0433`.

I think it's because cmake is not imported when all features are disabled and the function set_unix_like_libusb_config uses it.

@alexrsagen
Copy link
Owner

Yep, missed that one. Should be fixed in ca4642c / v0.3.3.

If it works fine now, I will publish v0.3.3 to crates.io

@riklus
Copy link
Author

riklus commented Mar 11, 2023

Unfortunatley no. It displays the same error.
On a macos/linux system this #[cfg(not(all(target_os = "windows", feature = "vendored")))] evaluates to true.

@alexrsagen
Copy link
Owner

alexrsagen commented Mar 11, 2023

Yeah my bad, too hasty fix.

This should work: #[cfg(all(not(target_os = "windows"), feature = "vendored"))]

Pushed v0.3.4 now, can you test if this works @riklus ?

@riklus
Copy link
Author

riklus commented Mar 11, 2023

Yay it works! Good job!

@alexrsagen
Copy link
Owner

Thanks for your help diagnosing/fixing the issue.
v0.3.4 now published to crates.io 😄

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

No branches or pull requests

2 participants