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

Support cargo (Rust) libraries #20619

Open
HappySeaFox opened this issue Oct 9, 2021 · 11 comments · May be fixed by #30251
Open

Support cargo (Rust) libraries #20619

HappySeaFox opened this issue Oct 9, 2021 · 11 comments · May be fixed by #30251
Assignees
Labels
category:tool-update The issue is with build tool or build script, which requires update or should be executed correctly no-stale Issue will not be marked as stale

Comments

@HappySeaFox
Copy link
Contributor


Is your feature request related to a problem? Please describe.

Some Rust libraries can be built with cargo tool into a C library with dll+lib files. For example, resvg. It would be great to enable vcpkg to build such libraries.

For example: to compile resvg C binding:

  1. Download and run rustup-init.exe from https://www.rust-lang.org/tools/install
  2. Compile resvg:
git clone https://github.com/RazrFalcon/resvg.git
cd resvg\c-api
%USERPROFILE%\.cargo\bin\cargo build --release

This creates resvg.dll and resvg.dll.lib.

Proposed solution
Add cargo as build tool.

Describe alternatives you've considered
-

Additional context
-

@JackBoosY JackBoosY added the category:tool-update The issue is with build tool or build script, which requires update or should be executed correctly label Oct 11, 2021
@JackBoosY
Copy link
Contributor

Can you provide more build documentation for cargo?

@JackBoosY JackBoosY added the requires:more-information This Issue requires more information to solve label Oct 11, 2021
@HappySeaFox
Copy link
Contributor Author

As per the docs https://github.com/rust-lang/cargo, cargo has a recursive build dependency on itself :) Yes, one needs cargo installed to build cargo from sources. I think installing a pre-compiled binary package is the only way to go to install it from scratch.

The pre-compiled package is available for different platforms and compilers. It also allows unattended install with specifying CLI options. Custom installation path can be set with environment variables, see rust-lang/rustup#618 (comment)

@JackBoosY JackBoosY removed the requires:more-information This Issue requires more information to solve label Oct 11, 2021
@JackBoosY
Copy link
Contributor

@HappySeaFox The last question is: are there other libraries that can be compiled with cargo?

@HappySeaFox
Copy link
Contributor Author

That's a good question. I haven't done any research as resvg is the only Rust lib I need. However, to support cargo, I can say that making C api for a Rust library is rather easy. I mean it's possible to patch a Rust-only library and add it in vcpkg rather easily.

@Be-ing
Copy link
Contributor

Be-ing commented Oct 18, 2021

This would be neat. I have an odd use case for this which I don't think I'd try to upstream, but it could be a nice hack for our overlay. In Mixxx we use sccache, which is a Rust program, for complier caching on Windows with MSVC. It would be nice if vcpkg could automatically install this as a build tool along with the libraries the application uses.

FWIW there is a Rust crate to do the opposite and integrate vcpkg into Cargo.

@soulmachine
Copy link

Rust libraries are can be easily converted to FFI compatible libraries, for example, crypto-crawler-ffi.

If vcpkg supports building cargo projects out-of-box, many rust libraries can be imported to vcpkg.io.

@JackBoosY
Copy link
Contributor

It looks like rustup doesn't provide a full tarball, but uses the built-in management tools to install and manage its dependencies.
So we can't easily add it as a tool, we can only follow vcpkg_acquire_msys.

@kLiHz
Copy link

kLiHz commented Sep 20, 2023

I think the question here might not be getting rustup ported to or integrated into vcpkg, since it's a installer that helps users to download and manage pre-built binaries of the Rust toolchain - such as rustc (Rust compiler), rust-std (Rust standard lib) and cargo (a package manager and also a build tool). In my opinion these binaries or the Rust toolchain should be installed by the user, just as they need to install MSVC or GCC C/C++ compiler to use vcpkg.

Although it seems that cargo can be optional, most of the time it's highly tied to Rust projects. So as far as I can see, to support Rust-based libraries, we might need to support cargo in vcpkg. Or maybe these Rust crates which provide C/C++ libraries are somehow different and not relying on cargo so much that we can develop/find something equivalent? It would be nice if someone familiar with Rust can tell me 😃.

And since I'm not quite familiar with vcpkg and how it works now (I saw discussion in #15441 but still not quite clear), I have no idea how Rust support can be added to vcpkg, or how possible/difficult it can be. What I know is that most C/C++ projects uses CMake or Makefile to manage the build, while Rust projects use cargo with Cargo.toml which defines the build.

Anyway I believe it would be nice if some Rust libraries can be brought onto vcpkg, like besides the resvg mentioned above, the quiche project can also be helpful for enabling HTTP/3 support for curl (#32109). 😇

@dg0yt
Copy link
Contributor

dg0yt commented Aug 2, 2024

Looking at how Debian packages librsvg (no resvg):
It has meson, cargo and cargo-c preinstalled. But:
The usually small set of Debian changes on top of the orig tarball has all the stuff which is required via Cargo.
https://sources.debian.org/src/librsvg/2.58.0%2Bdfsg-1/debian/README.source/
This adds 29 MB "changes" to a 7.7 MB "orig" tarball.
https://snapshot.debian.org/package/librsvg/2.58.0%2Bdfsg-1/
And it contributes a lengthy section to the copyright file:
https://tracker.debian.org/media/packages/libr/librsvg/copyright-2.58.0dfsg-1
(TLDNR: Apache-2.0, and BSD-2-clause, and BSD-3-clause, and Expat, and Apache-2.0 or Expat or 0BSD, and Apache-2.0 or Boost-1.0, and Apache-2.0 or Expat, and Expat or Unlicense, and MPL-2.0, and Sun-permissive, and zlib)

Copy link

This is an automated message. Per our repo policy, stale issues get closed if there has been no activity in the past 180 days. The issue will be automatically closed in 14 days. If you wish to keep this issue open, please add a new comment.

@github-actions github-actions bot added the Stale label Feb 15, 2025
@valgur
Copy link
Contributor

valgur commented Feb 17, 2025

I've added experimental support for a Rust/Cargo package on ConanCenter, if it helps: https://github.com/valgur/conan-center-index/tree/dev/recipes/rust/all
The core logic of using a pre-built toolchain plus any necessary extra stdlibs for cross-compilation support can probably be re-used for Vcpkg.

I've found Rust support necessary/useful for a few libraries: zenoh-c, gst-plugins-rs, icu4x, and librsvg.

Unfortunately, while librsvg is a very relevant and popular library, it's also by far the most fragile of the bunch and mostly does not work with relocated libraries. The system_deps wrapper crate for C libraries does not respect the correct order of the build flags it gets from the .pc files, so if any system libraries like OpenGL or X11 are used as dependencies it will simply place -L/usr/lib/x86_64-linux-gnu -I/usr/include at an arbitrary location in the build commands. As a result, it tends to also unintentionally use the system library versions for other packages that are supposed to come from Conan/Vcpkg, if they exist on the system, such as Cairo.

Also, Rust-based libraries tend to be picky about the version of the Rust toolchain used to build them. Vcpkg generally always wants to use the latest version of any packages. Would this be a problem or can this be simply overridden in vcpkg.json, perhaps?

@github-actions github-actions bot removed the Stale label Feb 18, 2025
@Cheney-W Cheney-W added the no-stale Issue will not be marked as stale label Feb 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category:tool-update The issue is with build tool or build script, which requires update or should be executed correctly no-stale Issue will not be marked as stale
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants