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

Supporting manifest mode #41

Open
SwishSwushPow opened this issue Aug 13, 2021 · 8 comments
Open

Supporting manifest mode #41

SwishSwushPow opened this issue Aug 13, 2021 · 8 comments

Comments

@SwishSwushPow
Copy link

SwishSwushPow commented Aug 13, 2021

Hey everyone 👋
I was looking into vcpkg and how it could work with cargo and Rust and found this crate. I like how easily the integration works with the build.rs file, but since I would like to use the "version" feature of vcpkg. Yet versions are only supported in the manifest mode in which dependencies are read from the manifest file and then being installed in the project directory.

I had a look at the code and noticed that, to support manifest mode, the paths like e.g. status_path, lib_path, bin_path etc. need to be changed. Hardcoding a different root directory seemed to easily allow me to use this crate even in manifest mode.

Now I would like to discuss how to go about this. In manifest mode, a vcpkg.json file exists in the root of the Rust project. Would it make sense to check the existence of such a file and then automatically make the adjustments to the paths? Or should the user set an environment variable to let the crate now that it should look for packages in the project directory first? Or maybe it should always check the project directory first?

I'm hoping that we can make this crate even better! If we find a valid approach I can give it a go to implement it myself and then create a pull request.

Best regards,
Björn

@SwishSwushPow
Copy link
Author

An example for a very simple approach can be seen here: GiGainfosystems@ccdf745

Again, I do not know if that is a good approach, but it seems to work for the small examples that I've been trying.

@waych
Copy link
Collaborator

waych commented Aug 14, 2021

I don't know much about vcpkg's manifest mode, and haven't used it before, but I just read the online docs for it and I think I understand what you are trying to do.

I think it helps to differentiate the purpose and function of the vcpkg-rs crate vs cargo-vcpkg. The vcpkg-rs crate simply reads info and files from an already installed vcpkg setup, whereas the cargo-vcpkg tool extends the cargo command to ease creating an installed vcpkg setup.

It sounds like the mode of operation you are using is to do the vcpkg install directly rather than via cargo vcpkg install, and then using vcpkg-rs to pick up those dependencies. In that case I think something like an environment variable that defaults to ON according to presence of $(CARGO_MANIFEST_DIR)/vcpkg.json is probably okay (mimicking what VCPKG_MANIFEST_MODE does), so that by default it does the right thing (find the installed files in the new path location) but the behavior can be controlled.

Regarding cargo-vcpkg, it feels like some functionality overlaps between what vcpkg manifest mode does and the intent of cargo-vcpkg's metadata in Cargo.toml. An potential path could have the metadata extended to cover versioning and have that generate a vcpkg.json on the backend, but that feels unnecessary if vcpkg.json is the upstream canonical way to express this. In either case, it could use the --x-install-root to still keep the installed tree inside ./target which seems desirable but not critical.

@SwishSwushPow
Copy link
Author

You are correct. I haven't used cargo vcpkg build so far because it doesn't support pinning versions (yet). That's why I opted for the manifest mode of vcpkg directly. I think it's worth to update vcpkg-rs to support this mode as well and I think I will open a PR including your suggestion to automatically set this environment variable.

I have also just noticed that cargo-vcpkg fails to install as soon as a vcpkg.json file is present. I've opened an issue over there (mcgoo/cargo-vcpkg#11). Also I agree with you that it makes sense to stay true to the specific purposes of both of these tools, but I don't know how deeply cargo vcpkg is integrated into vcpkg-rs, so it's hard for me to say much about this on my own. Some discussion might be in order for that.

@Be-ing
Copy link

Be-ing commented Feb 14, 2022

I just did a quick experiment with vcpkg manifest mode running:

RUSTFLAGS="-L /path/to/vcpkg_installed/lib" PKG_CONFIG_PATH="/path/to/vcpkg_installed/lib/pkgconfig" cargo build

and that seems to works fine without a need for this crate nor cargo vcpkg.

@ras0219-msft
Copy link

From a conversation over on system-deps [1] gdesmott/system-deps#8, they would like to use this package to improve their search paths for pkg-config to include vcpkg.

Of course, manifest mode is very important for this as well :)

@SwishSwushPow
Copy link
Author

Just FYI I still have an eye on this but I'm currently enjoying my holidays so it'll take a bit until I'll respond more thoroughly 👍

@SwishSwushPow
Copy link
Author

I just did a quick experiment with vcpkg manifest mode running:

RUSTFLAGS="-L /path/to/vcpkg_installed/lib" PKG_CONFIG_PATH="/path/to/vcpkg_installed/lib/pkgconfig" cargo build

and that seems to works fine without a need for this crate nor cargo vcpkg.

Sorry for taking a while to come back to this. Do I understand correctly that these flags would have to be set for each individual library/dependency? If that is the case then I don't think that this crate or cargo vcpkg is superfluous.

@ras0219-msft
Copy link

You should only need to set RUSTFLAGS="-L /path/to/vcpkg_installed/lib" PKG_CONFIG_PATH="/path/to/vcpkg_installed/lib/pkgconfig" once. Because vcpkg puts all packages into a common sysroot, a single entry should be sufficient for pkg-config.

However, this crate provides integration with packages that don't provide .pc files. I think it could also be useful for a crate to mediate knowledge of a vcpkg instance for other packages; for example, would it be possible to automatically add the RUSTFLAGS="-L /path/to/vcpkg_installed/lib" PKG_CONFIG_PATH="/path/to/vcpkg_installed/lib/pkgconfig" based on knowledge of the instance?

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

4 participants