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

Cargo pulling in source dependencies even when the source feature is disabled #229

Open
bkirwi opened this issue Jan 15, 2024 · 4 comments

Comments

@bkirwi
Copy link

bkirwi commented Jan 15, 2024

For example, this section means that compiling for a linux target will always require fontconfig to be available, even when the source feature is not enabled: https://github.com/servo/font-kit/blob/master/Cargo.toml#L61-L62

This means that eg. cross-compiling becomes more difficult, since you now need fontconfig compiled for the target system, even though you don't intend to use it.

@jdm
Copy link
Member

jdm commented Jan 17, 2024

The fact that the dependency is pulled in is a limitation of cargo. However it will only be built if it's part of the active dependency graph based on the features selected, since it's marked as an optional dependency.

@bkirwi
Copy link
Author

bkirwi commented Jan 17, 2024

However it will only be built if it's part of the active dependency graph based on the features selected, since it's marked as an optional dependency.

Heartbreakingly, I don't think this is quite right in practice.

yeslogic-fontconfig-sys is listed twice in Cargo.toml, once as an optional dependency, and one as a normal dependency for systems that match cfg(not(any(target_family = "windows", target_os = "macos", target_os = "ios", target_arch = "wasm32"))). The source feature -- which requires yeslogic-fontconfig-sys to build correctly! -- has no dependencies in the Cargo.toml at all, on yeslogic-fontconfig-sys or anything else.

This is visible in the build output when compiling on Linux:

bkirwi@bkirwi-2023:~/Code/font-kit$ cargo build --no-default-features
[...]
   Compiling yeslogic-fontconfig-sys v5.0.0

This passes on my Linux dev machine, where fontconfig is available... but on my embedded system, where it is not available, I get:

error: could not find system library 'fontconfig' required by the 'yeslogic-fontconfig-sys' crate
Package fontconfig was not found in the pkg-config search path.
Perhaps you should add the directory containing `fontconfig.pc'
to the PKG_CONFIG_PATH environment variable

If I comment out the previously-linked section of Cargo.toml, though, it passes.

@jayvdb
Copy link
Contributor

jayvdb commented Jul 5, 2024

I believe that due to rust-lang/cargo#1197 , and the auto-backend-selection approach for font-kit , the only way this issue might be fixable is to introduce an extra package, e.g. "font-kit-core" which has all the current code.

Then font-kit would add dependency font-kit-core with different features enabled per target.
Even then I am not sure it would work, as this issue is about deselecting a platform specific default dependency.

@jayvdb
Copy link
Contributor

jayvdb commented Jul 5, 2024

#180 is related to splitting off source related features to a separate crate.

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

3 participants