-
-
Notifications
You must be signed in to change notification settings - Fork 810
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 packages dependencies can conflict #2227
Comments
It is only a static lib. Can you provide a whole test example project? |
But xmake just add three libs. like adding links actix_web.dylib will contains tokio codes?
|
Yes but as static libraries, each of them will embed the code for tokio.
Sure, it's just taking that Rust file and compiling it with Cargo and with xmake, I can make you a quick example soon. |
test_actix_twitchirc.zip XMake output:
Cargo output:
(note that you need xmake dev for this) |
This solution is also not very well implemented. Each add_requires uniquely corresponds to a package instance for parallel installation. Even if combined into a single cargo.toml, several different cargo.toml may be required if different targets require different dependency groups. We need to improve the add_requires interface to support the description of all cargo deps in a single add_requires. Solution1Use Cargo.toml add_requires("cargo::test_actix_twitchirc", {configs = {tomlfile = path.join(os.scriptdir(), "Cargo.toml")}}) Cargo.toml
Solution2Write cargo.toml configuarion in xmake.lua add_requires("cargo::test_actix_twitchirc", {configs = {dependencies = [[
actix-web = "4.0"
env_logger = "0.9"
log = "0.4"
twitch-irc = "4.0"
tokio = { version = "1", features = ["rt-multi-thread", "macros", "time"] }
]]}}) Both solutions can also be supported and are compatible with the current single If we only use a single rust package, we can still continue to use |
Both solutions are great but I think the first one is the best because Cargo.toml are part of the Rust ecosystem and may be needed by other tools such as Visual Studio Code for auto-completion. |
I have supported the solution1, and tested it for your example. It works now. #2235 add_rules("mode.release", "mode.debug")
add_requires("cargo::test", {configs = {cargo_toml = path.join(os.projectdir(), "Cargo.toml")}})
target("test")
set_kind("binary")
add_files("src/main.rs")
add_packages("cargo::test") |
Does it work? |
Sorry I couldn't test until today. Yes it works well, thank you. However it's not taking Cargo.toml updates into account, could it be possible to automatically handle this, or should I use version number for package? Thanks a lot. |
you need add version to add_requires("cargo::test 1.0") |
Xmake Version
xmake v2.6.4+HEAD.9361ffcc1 (dev)
Operating System Version and Architecture
Windows 11
Describe Bug
When using xmake with the Rust language, there seem to be a problem with the way it handles Cargo packages.
I have the following requires:
and the following target:
(syslinks are required for Rust features but that's another issue)
xmake installs those packages without issue, but when I use them, they don't work quite right.
The issue is that xmake handle every cargo package separately, which means that actix-web, twitch-irc and tokio are three separate libs, and there is in fact 3 times tokio (as it's a dep of actix-web and twitch-irc).
Since tokio relies on global variables, it can lead to this famous Rust error:
which happens when you have multiple Tokio runtimes (which happens when you have different tokio versions).
I did try the very same Rust file with this Cargo.toml:
which worked.
I see two possibles fixes here:
Expected Behavior
That xmake manages to reuse tokio and other rust dependencies to have a working program.
Project Configuration
Rust source for reference:
With cargo, it works:
With xmake, it fails:
Additional Information and Error Logs
Here's how Cargo linked my app:
Here's how xmake builds my lib:
The text was updated successfully, but these errors were encountered: