xmake-io / xmake

🔥 A cross-platform build utility based on Lua
https://xmake.io
Apache License 2.0
10.08k stars 784 forks source link

Cargo packages dependencies can conflict #2227

Closed SirLynix closed 2 years ago

SirLynix commented 2 years ago

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:

add_requires("cargo::cxx", 
    "cargo::actix-web 4.0",
    "cargo::env_logger 0.9",
    "cargo::log 0.4",
    "cargo::twitch-irc 4.0")
add_requires("cargo::tokio 1.17", { configs = { features = {"rt-multi-thread", "macros", "time"}}})

and the following target:

target("WebService")
    set_kind("static")
    add_files("src/Nazatwitch/WebService/**.rs")
    add_packages("cargo::actix-web", "cargo::env_logger")
    add_packages("cargo::cxx")
    add_packages("cargo::tokio")
    add_packages("cargo::twitch-irc")
    set_values("rust.cratetype", "staticlib")
    if is_plat("windows", "mingw") then
        add_syslinks("bcrypt", "Crypt32", "Ncrypt", "NtDll", "Secur32", "ws2_32", "Userenv", { public = true })
    end

(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:

thread '<unnamed>' panicked at 'there is no reactor running, must be called from the context of a Tokio 1.x runtimeInitializing Platform...',
C:\Users\lynix\.cargo\registry\src\github.com-1ecc6299db9ec823\twitch-irc-4.0.0\src\client\event_loop.rs:84:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

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:

[package]
name = "test_actix_twitchirc"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[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"] }

which worked.

I see two possibles fixes here: 1) That xmake collects all Cargo dependencies to build one single Cargo.toml to allow it to merge dependencies and collect the result, this is the easiest fix I think. 2) That xmake collects every cargo package dependency (actix-web => tokio and more), like it does for C++ packages, and install it separately (and allows it to reuse them). But it means to have a lot of dependencies in the list. XMake should also merge packages by features.

Expected Behavior

That xmake manages to reuse tokio and other rust dependencies to have a working program.

Project Configuration

Rust source for reference:

use std::{sync::mpsc, thread, time};
use std::io::{self, Write};
use tokio::runtime::Runtime;

use actix_web::{dev::ServerHandle, middleware, rt, web, App, HttpRequest, HttpServer};
use twitch_irc::login::StaticLoginCredentials;
use twitch_irc::TwitchIRCClient;
use twitch_irc::{ClientConfig, SecureTCPTransport};

extern "C" {
    //fn SpawnBurger(context: u64);
}

async fn index(req: HttpRequest, context: web::Data<u64>) -> &'static str {
    println!("REQ: {:?}", req);
    //unsafe { SpawnBurger(**context); }
    "Hello world!"
}

async fn run_app(tx: mpsc::Sender<ServerHandle>, context: u64) -> std::io::Result<()> {
    println!("starting HTTP server at http://localhost:8080");

    // srv is server controller type, `dev::Server`
    let server = HttpServer::new(move || {
        App::new()
            // enable logger
            .wrap(middleware::Logger::default())
            .app_data(web::Data::new(context))
            .service(web::resource("/burger").to(index))
    })
    .bind(("127.0.0.1", 8080))?
    .workers(2)
    .run();

    // Send server handle back to the main thread
    let _ = tx.send(server.handle());

    server.await
}

async fn start_chatservice(context: u64) {
    println!("start_chatservice");
    io::stdout().flush();

    // default configuration is to join chat as anonymous.
    let config = ClientConfig::default();
    let (mut incoming_messages, client) =
        TwitchIRCClient::<SecureTCPTransport, StaticLoginCredentials>::new(config);

    // first thing you should do: start consuming incoming messages,
    // otherwise they will back up.
    let join_handle = tokio::spawn(async move {
        println!("Twitch chat thread");
        while let Some(message) = incoming_messages.recv().await {
            println!("Received message: {:?}", message);
        }
    });

    // join a channel
    // This function only returns an error if the passed channel login name is malformed,
    // so in this simple case where the channel name is hardcoded we can ignore the potential
    // error with `unwrap`.
    client.join("sirlynixvanfrietjes".to_owned()).unwrap();
    println!("Joining Twitch channel");

    // keep the tokio executor alive.
    // If you return instead of waiting the background task will exit.
    join_handle.await.unwrap()
}

fn run_chatservice(context: u64) {
    println!("run_chatservice");

    let rt = Runtime::new().unwrap();

    // Spawn the root task
    rt.block_on(async {
        start_chatservice(context).await
    });

/*/

    tokio::runtime::Builder::new_multi_thread()
        .enable_all()
        .build()
        .unwrap()
        .block_on(async {
            start_chatservice(context).await
        });*/
}

fn run_webservice(context: u64) {
    env_logger::init_from_env(env_logger::Env::new().default_filter_or("info"));

    let (tx, rx) = mpsc::channel();

    println!("spawning thread for server");
    thread::spawn(move || {
        let server_future = run_app(tx, context);
        rt::System::new().block_on(server_future)
    });

    let server_handle = rx.recv().unwrap();

    println!("waiting 10 seconds");
    thread::sleep(time::Duration::from_secs(100000000));

    // Send a stop signal to the server, waiting for it to exit gracefully
    println!("stopping server");
    rt::System::new().block_on(server_handle.stop(true));
}

fn main() {
    let context: u64 = 0;
    run_chatservice(context);
    run_webservice(context);
}

fn stop_webservice() {

}

With cargo, it works:

    Finished dev [unoptimized + debuginfo] target(s) in 4.29s
     Running `target\debug\test_actix_twitchirc.exe`
run_chatservice
start_chatservice
Twitch chat thread
Joining Twitch channel
Received message: Generic(HiddenIRCMessage(IRCMessage { tags: IRCTags({}), prefix: Some(HostOnly { host: "tmi.twitch.tv" }), command: "CAP", params: ["*", "ACK", "twitch.tv/tags twitch.tv/commands"] }))
Received message: Generic(HiddenIRCMessage(IRCMessage { tags: IRCTags({}), prefix: Some(HostOnly { host: "tmi.twitch.tv" }), command: "001", params: ["justinfan12345", "Welcome, GLHF!"] }))
Received message: Generic(HiddenIRCMessage(IRCMessage { tags: IRCTags({}), prefix: Some(HostOnly { host: "tmi.twitch.tv" }), command: "002", params: ["justinfan12345", "Your host is tmi.twitch.tv"] }))
Received message: Generic(HiddenIRCMessage(IRCMessage { tags: IRCTags({}), prefix: Some(HostOnly { host: "tmi.twitch.tv" }), command: "003", params: ["justinfan12345", "This server is rather new"] }))
Received message: Generic(HiddenIRCMessage(IRCMessage { tags: IRCTags({}), prefix: Some(HostOnly { host: "tmi.twitch.tv" }), command: "004", params: ["justinfan12345", "-"] }))
Received message: Generic(HiddenIRCMessage(IRCMessage { tags: IRCTags({}), prefix: Some(HostOnly { host: "tmi.twitch.tv" }), command: "375", params: ["justinfan12345", "-"] }))
Received message: Generic(HiddenIRCMessage(IRCMessage { tags: IRCTags({}), prefix: Some(HostOnly { host: "tmi.twitch.tv" }), command: "372", params: ["justinfan12345", "You are in a maze of twisty passages, all alike."] }))
Received message: Generic(HiddenIRCMessage(IRCMessage { tags: IRCTags({}), prefix: Some(HostOnly { host: "tmi.twitch.tv" }), command: "376", params: ["justinfan12345", ">"] }))
Received message: Join(JoinMessage { channel_login: "sirlynixvanfrietjes", user_login: "justinfan12345", source: IRCMessage { tags: IRCTags({}), prefix: Some(Full { nick: "justinfan12345", user: Some("justinfan12345"), host: Some("justinfan12345.tmi.twitch.tv") }), command: "JOIN", params: ["#sirlynixvanfrietjes"] } })
Received message: RoomState(RoomStateMessage { channel_login: "sirlynixvanfrietjes", channel_id: "179294452", emote_only: Some(false), follwers_only: Some(Disabled), r9k: Some(false), slow_mode: Some(0ns), subscribers_only: Some(false), source: IRCMessage { tags: IRCTags({"subs-only": Some("0"), "r9k": Some("0"), "emote-only": Some("0"), "slow": Some("0"), "followers-only": Some("-1"), "rituals": Some("1"), "room-id": Some("179294452")}), prefix: Some(HostOnly { host: "tmi.twitch.tv" }), command: "ROOMSTATE", params: ["#sirlynixvanfrietjes"] } })
Received message: Generic(HiddenIRCMessage(IRCMessage { tags: IRCTags({}), prefix: Some(HostOnly { host: "justinfan12345.tmi.twitch.tv" }), command: "353", params: ["justinfan12345", "=", "#sirlynixvanfrietjes", "justinfan12345"] }))
Received message: Generic(HiddenIRCMessage(IRCMessage { tags: IRCTags({}), prefix: Some(HostOnly { host: "justinfan12345.tmi.twitch.tv" }), command: "366", params: ["justinfan12345", "#sirlynixvanfrietjes", "End of /NAMES list"] }))
Received message: Privmsg(PrivmsgMessage { channel_login: "sirlynixvanfrietjes", channel_id: "179294452", message_text: "Test", is_action: false, sender: TwitchUserBasics { id: "179294452", login: "sirlynixvanfrietjes", name: "SirLynixVanFrietjes" }, badge_info: [Badge { name: "subscriber", version: "52" }], badges: [Badge { name: "broadcaster", version: "1" }, Badge { name: "subscriber", version: "3012" }, Badge { name: "premium", version: "1" }], bits: None, name_color: Some(RGBColor { r: 0, g: 125, b: 155 }), emotes: [], message_id: "8f6dff23-a10a-4075-85ce-b997a1c371ab", server_timestamp: 2022-03-30T06:08:37.775Z, source: IRCMessage { tags: IRCTags({"first-msg": Some("0"), "mod": Some("0"), "turbo": Some("0"), "flags": Some(""), "tmi-sent-ts": Some("1648620517775"), "emotes": Some(""), "id": Some("8f6dff23-a10a-4075-85ce-b997a1c371ab"), "badge-info": Some("subscriber/52"), "user-id": Some("179294452"), "color": Some("#007D9B"), "subscriber": Some("1"), "badges": Some("broadcaster/1,subscriber/3012,premium/1"), "client-nonce": Some("a2890976bc4c16b915db52915bf1fe97"), "display-name": Some("SirLynixVanFrietjes"), "room-id": Some("179294452"), "user-type": Some("")}), prefix: Some(Full { nick: "sirlynixvanfrietjes", user: Some("sirlynixvanfrietjes"), host: Some("sirlynixvanfrietjes.tmi.twitch.tv") }), command: "PRIVMSG", params: ["#sirlynixvanfrietjes", "Test"] } })

With xmake, it fails:

lynix@SirDesktop:/mnt/c/Projets/Perso/Nazatwitch$ xmake.exe run
Initializing Core...
run_chatservice
Initializing Utility...
start_chatservice
thread '<unnamed>' panicked at 'there is no reactor running, must be called from the context of a Tokio 1.x runtimeInitializing Platform...',
C:\Users\lynix\.cargo\registry\src\github.com-1ecc6299db9ec823\twitch-irc-4.0.0\src\client\event_loop.rs:84:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Additional Information and Error Logs

Here's how Cargo linked my app:

  = note: "C:\\Program Files\\Microsoft Visual Studio\\2022\\Professional\\VC\\Tools\\MSVC\\14.31.31103\\bin\\HostX64\\x64\\link.exe" "/NOLOGO" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\test_actix_twitchirc.test_actix_twitchirc.c142d0c6-cgu.0.rcgu.o" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\test_actix_twitchirc.test_actix_twitchirc.c142d0c6-cgu.1.rcgu.o" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\test_actix_twitchirc.test_actix_twitchirc.c142d0c6-cgu.10.rcgu.o" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\test_actix_twitchirc.test_actix_twitchirc.c142d0c6-cgu.11.rcgu.o" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\test_actix_twitchirc.test_actix_twitchirc.c142d0c6-cgu.12.rcgu.o" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\test_actix_twitchirc.test_actix_twitchirc.c142d0c6-cgu.13.rcgu.o" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\test_actix_twitchirc.test_actix_twitchirc.c142d0c6-cgu.14.rcgu.o" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\test_actix_twitchirc.test_actix_twitchirc.c142d0c6-cgu.15.rcgu.o" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\test_actix_twitchirc.test_actix_twitchirc.c142d0c6-cgu.2.rcgu.o" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\test_actix_twitchirc.test_actix_twitchirc.c142d0c6-cgu.3.rcgu.o" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\test_actix_twitchirc.test_actix_twitchirc.c142d0c6-cgu.4.rcgu.o" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\test_actix_twitchirc.test_actix_twitchirc.c142d0c6-cgu.5.rcgu.o" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\test_actix_twitchirc.test_actix_twitchirc.c142d0c6-cgu.6.rcgu.o" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\test_actix_twitchirc.test_actix_twitchirc.c142d0c6-cgu.7.rcgu.o" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\test_actix_twitchirc.test_actix_twitchirc.c142d0c6-cgu.8.rcgu.o" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\test_actix_twitchirc.test_actix_twitchirc.c142d0c6-cgu.9.rcgu.o" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\test_actix_twitchirc.bqfvby0lj3ot87d.rcgu.o" "/LIBPATH:C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps" "/LIBPATH:C:\\Users\\lynix\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\windows_x86_64_msvc-0.32.0\\lib" "/LIBPATH:C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\build\\zstd-sys-89efee4c6c5a814b\\out" "/LIBPATH:C:\\Users\\lynix\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libenv_logger-4f2a57e3b4464042.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libatty-f0a836e11e9aa6af.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libtermcolor-4a3d44893c1f4386.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libwinapi_util-435d0802c50e4921.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libhumantime-5853f89fd221ff5f.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libtwitch_irc-60d246d80734c0ca.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libtokio_native_tls-8111e1e14048b6d5.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libnative_tls-71eb5c511de08597.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libschannel-71c8270a74955c2d.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libtokio_stream-517614f706031c9a.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libchrono-0592e03201911a43.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libnum_integer-02335b6f13df3354.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libnum_traits-b1580f1e9ea6247f.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\liblibc-ccbc5f8c373d523a.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libtime-45d712e0eb336b80.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libthiserror-cccfa362c368572f.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libitertools-b4cb68bf09a0a841.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libeither-b495461ca5fa85a0.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libactix_web-d8b8ea9cd71a7424.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libcookie-0de6406fadda170a.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libtime-ac602db1b6c334f8.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\liburl-cb9b74115eee8115.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libidna-f89acd340c30f1e7.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libunicode_normalization-d64fefa87c2acdef.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libtinyvec-4bdb16ed9388cf28.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libtinyvec_macros-e34fd26d36cf26b8.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libunicode_bidi-677438b7635625e1.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libserde_urlencoded-0862eb5d60e93bf5.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libform_urlencoded-29be5006553664b7.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libmatches-c48b2fa5d188260a.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libserde_json-f80fa5f5789daf79.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libryu-0fbd43c215b774d5.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libactix_server-43a94db64fb065d8.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libactix_router-b1ac04531c67ed58.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libregex-13dd2da10136c987.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libaho_corasick-069fccb3b8b18c75.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libregex_syntax-f1d953790de3dec3.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libfirestorm-f8e8fde46a1336b8.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libserde-88e86de3cf15d799.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libactix_http-3f68ce5827fddfca.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libbase64-c6ba8f9c487cb1f7.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\librand-38383238f45a0e34.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\librand_chacha-85950a185544d20a.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libppv_lite86-e25f86590ed3bddb.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\librand_core-cd434884b91fe9ec.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libhttparse-d9711539fb687147.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libbrotli-73e5058aaa87e489.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libbrotli_decompressor-9cd07db29f06b3ca.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\liballoc_stdlib-5968a1107f05475d.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\liballoc_no_stdlib-8e71dd70604a5eab.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libhttpdate-eddda9191c54f557.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libsha1-5e453076b0e9faf2.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libcpufeatures-6af8649e9594cb63.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libdigest-4088a218002258c0.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libblock_buffer-bbfabd64f5098106.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libcrypto_common-cfa4b302967469e6.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libgeneric_array-87d91c510ad8b9ae.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libtypenum-56b761558ae12819.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\liblocal_channel-080821a2a5839e44.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libbytestring-aa23911ba371d22b.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libencoding_rs-b38eca8b1dbbf140.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\liblanguage_tags-70ba8829c40d296a.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libmime-fdd6ab1e61b0f76f.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libpercent_encoding-101b8226d1bcb66c.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libh2-3a842518bcb29fd1.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libindexmap-d1f729b800d1b134.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libhashbrown-52b9bb096f42d512.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libfutures_util-ebe30026a00e779c.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libslab-d4e275a6a551ba0a.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libfutures_task-f759efe690c5f631.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libpin_utils-312a215a9002b588.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libtokio_util-5b2e3e9814eaf2e8.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libahash-067874cdb1b5ce20.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libgetrandom-d75992503f2acc44.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libzstd-6ec167116a0f9efe.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libzstd_safe-3c600fad4724a4a1.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libzstd_sys-db2b9b11ab6e2d74.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libflate2-99ea1302383b121c.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libminiz_oxide-ca383d447c2d548f.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libadler-596c601d28339c8e.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libcrc32fast-148c5295f184d6b3.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libactix_service-321e96f7aa8a5750.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libactix_codec-27276ad588482c18.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libtokio_util-d9dd9db468b0cc5d.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libtracing-4d1147e4f34f88b9.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libtracing_core-acbe5944f488dc66.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\liblazy_static-66e00e49ee9a504b.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libfutures_sink-18e355b85a69e004.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libbitflags-9078158de72b3dd8.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libactix_utils-2c03adcfa7e39f96.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\liblocal_waker-13934c42ec6f4ad2.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libactix_rt-3a4f82218769be25.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libfutures_core-8351b5949cff88fa.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libhttp-57069850e2fd7dec.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libitoa-0e12e3ba529257e5.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libfnv-5bacd6f124cca4b4.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libtokio-3b5e48efb80035ab.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libnum_cpus-2ac0a3c2af21395c.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libsocket2-40e570c41cfd1d8b.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libmemchr-4dcd4d8686494f7b.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libonce_cell-5317c3a88ca57f5a.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libbytes-2738216f196a776b.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libpin_project_lite-f0ecbb69bb7b18c4.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libmio-2b1aedf47c4b0866.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libmiow-9f88c353fbf05880.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libntapi-00a5d80419b559bf.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\liblog-b2623af42c8e644a.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libwinapi-be1e7e10ca80ab7e.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libparking_lot-50c8274c74509059.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libparking_lot_core-f77b1825931378c3.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libwindows_sys-a8de70aec9103c88.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libcfg_if-ab37e4e2ee9068dd.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libsmallvec-fe76b005d03aacb1.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\liblock_api-3589aefaff6f79e5.rlib" "C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\libscopeguard-fd78124af5d4ffb0.rlib" "C:\\Users\\lynix\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libstd-ca7b0c28ec762872.rlib" "C:\\Users\\lynix\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libpanic_unwind-1b050a71ed5c4477.rlib" "C:\\Users\\lynix\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libstd_detect-ba9f9c006950f110.rlib" "C:\\Users\\lynix\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\librustc_demangle-4e228cbffbe5e3cd.rlib" "C:\\Users\\lynix\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libhashbrown-d3d7c65121bb0d35.rlib" "C:\\Users\\lynix\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\librustc_std_workspace_alloc-2cedaf2947cb8622.rlib" "C:\\Users\\lynix\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libunwind-7d6cff0c7b8f0c2b.rlib" "C:\\Users\\lynix\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcfg_if-63bdfcda4a65748c.rlib" "C:\\Users\\lynix\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\liblibc-c331c9d260094b22.rlib" "C:\\Users\\lynix\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\liballoc-34d0a2dd4a5dbc91.rlib" "C:\\Users\\lynix\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\librustc_std_workspace_core-e7b8421abede5598.rlib" "C:\\Users\\lynix\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcore-08b052fa5e861ac2.rlib" "C:\\Users\\lynix\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcompiler_builtins-18761c3bc8f2e6ea.rlib" "bcrypt.lib" "ntdll.lib" "advapi32.lib" "bcrypt.lib" "cfgmgr32.lib" "credui.lib" "crypt32.lib" "cryptnet.lib" "fwpuclnt.lib" "gdi32.lib" "kernel32.lib" "msimg32.lib" "mswsock.lib" "ncrypt.lib" "ntdll.lib" "opengl32.lib" "secur32.lib" "synchronization.lib" "user32.lib" "winspool.lib" "ws2_32.lib" "windows.lib" "kernel32.lib" "ws2_32.lib" "bcrypt.lib" "advapi32.lib" "userenv.lib" "kernel32.lib" "msvcrt.lib" "/NXCOMPAT" "/LIBPATH:C:\\Users\\lynix\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib" "/OUT:C:\\Projets\\Perso\\Tests\\test_actix_twitchirc\\target\\debug\\deps\\test_actix_twitchirc.exe" "/OPT:REF,NOICF" "/DEBUG" "/NATVIS:C:\\Users\\lynix\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\intrinsic.natvis" "/NATVIS:C:\\Users\\lynix\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\liballoc.natvis" "/NATVIS:C:\\Users\\lynix\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\libcore.natvis" "/NATVIS:C:\\Users\\lynix\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\libstd.natvis"

Here's how xmake builds my lib:

rustc -C debuginfo=2 -C opt-level=0 --edition 2018 -L dependency=C:\Projets\Perso\Nazatwitch\build\.packages\c\cargo_actix-web\4.0\8b3b7a6a832f4f28b8a7672001103769\lib -L dependency=C:\Projets\Perso\Nazatwitch\build\.packages\c\cargo_env_logger\0.9\8b3b7a6a832f4f28b8a7672001103769\lib -L dependency=C:\Projets\Perso\Nazatwitch\build\.packages\c\cargo_cxx\latest\8b3b7a6a832f4f28b8a7672001103769\lib -L dependency=C:\Projets\Perso\Nazatwitch\build\.packages\c\cargo_tokio\1.17\9cca7c91eeb143c0bd6548986090f4d3\lib -L dependency=C:\Projets\Perso\Nazatwitch\build\.packages\c\cargo_twitch-irc\4.0\8b3b7a6a832f4f28b8a7672001103769\lib -C debuginfo=2 --extern actix_web=C:\Projets\Perso\Nazatwitch\build\.packages\c\cargo_actix-web\4.0\8b3b7a6a832f4f28b8a7672001103769\lib\libactix_web-0513c9c76fe15aac.rlib --extern env_logger=C:\Projets\Perso\Nazatwitch\build\.packages\c\cargo_env_logger\0.9\8b3b7a6a832f4f28b8a7672001103769\lib\libenv_logger-79d0cf0323312a15.rlib --extern cxx=C:\Projets\Perso\Nazatwitch\build\.packages\c\cargo_cxx\latest\8b3b7a6a832f4f28b8a7672001103769\lib\libcxx-49e59a8be51f1d4c.rlib --extern tokio=C:\Projets\Perso\Nazatwitch\build\.packages\c\cargo_tokio\1.17\9cca7c91eeb143c0bd6548986090f4d3\lib\libtokio-77481dbf354f79e6.rlib --extern twitch_irc=C:\Projets\Perso\Nazatwitch\build\.packages\c\cargo_twitch-irc\4.0\8b3b7a6a832f4f28b8a7672001103769\lib\libtwitch_irc-b655d15fff7075ae.rlib --crate-type=staticlib -o bin\windows_x64_debug\WebService.lib src\Nazatwitch\WebService\main.rs
waruqi commented 2 years ago

It is only a static lib. Can you provide a whole test example project?

waruqi commented 2 years ago
/Users/ruki/.cargo/bin//rustc --edition 2018 -L dependency=/Users/ruki/share/testrs/build/.packages/c/cargo_actix-web/4.0/8f4a704fdf4c4b41ae8b958686b2ddb0/lib -L dependency=/Users/ruki/share/testrs/build/.packages/c/cargo_env_logger/0.9/8f4a704fdf4c4b41ae8b958686b2ddb0/lib -L dependency=/Users/ruki/share/testrs/build/.packages/c/cargo_cxx/latest/8f4a704fdf4c4b41ae8b958686b2ddb0/lib -L dependency=/Users/ruki/share/testrs/build/.packages/c/cargo_tokio/1.17/abaedbc7e3b7456ebb39218449efbcfd/lib -L dependency=/Users/ruki/share/testrs/build/.packages/c/cargo_twitch-irc/4.0/8f4a704fdf4c4b41ae8b958686b2ddb0/lib --extern actix_web=/Users/ruki/share/testrs/build/.packages/c/cargo_actix-web/4.0/8f4a704fdf4c4b41ae8b958686b2ddb0/lib/libactix_web-38446e15a082db0e.rlib --extern env_logger=/Users/ruki/share/testrs/build/.packages/c/cargo_env_logger/0.9/8f4a704fdf4c4b41ae8b958686b2ddb0/lib/libenv_logger-cb0b7cebc529cd65.rlib --extern cxx=/Users/ruki/share/testrs/build/.packages/c/cargo_cxx/latest/8f4a704fdf4c4b41ae8b958686b2ddb0/lib/libcxx-4263bb78ed14d042.rlib --extern tokio=/Users/ruki/share/testrs/build/.packages/c/cargo_tokio/1.17/abaedbc7e3b7456ebb39218449efbcfd/lib/libtokio-89e3519f918141fa.rlib --extern twitch_irc=/Users/ruki/share/testrs/build/.packages/c/cargo_twitch-irc/4.0/8f4a704fdf4c4b41ae8b958686b2ddb0/lib/libtwitch_irc-e01eee7d8ce49708.rlib --crate-type=staticlib -o build/macosx/x86_64/release/libWebService.a src/test.rs

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).

But xmake just add three libs. like adding links actix_web tokio twitch_irc

actix_web.dylib will contains tokio codes?

--extern actix_web=/Users/ruki/share/testrs/build/.packages/c/cargo_actix-web/4.0/8f4a704fdf4c4b41ae8b958686b2ddb0/lib/libactix_web-38446e15a082db0e.rlib
--extern tokio=/Users/ruki/share/testrs/build/.packages/c/cargo_tokio/1.17/abaedbc7e3b7456ebb39218449efbcfd/lib/libtokio-89e3519f918141fa.rlib
--extern twitch_irc=/Users/ruki/share/testrs/build/.packages/c/cargo_twitch-irc/4.0/8f4a704fdf4c4b41ae8b958686b2ddb0/lib/libtwitch_irc-e01eee7d8ce49708.rlib
SirLynix commented 2 years ago

But xmake just add three libs. like adding links actix_web tokio twitch_irc

Yes but as static libraries, each of them will embed the code for tokio.

It is only a static lib. Can you provide a whole test example project?

Sure, it's just taking that Rust file and compiling it with Cargo and with xmake, I can make you a quick example soon.

SirLynix commented 2 years ago

test_actix_twitchirc.zip Here's a small project (with a bad code but that doesn't matter) which runs fine with cargo run but fails with xmake && xmake run.

XMake output:

lynix@SirDesktop:/mnt/c/Projets/Perso/Tests/test_actix_twitchirc$ xmake run
run_chatservice
start_chatservice
thread 'main' panicked at 'there is no reactor running, must be called from the context of a Tokio 1.x runtime', /home/lynix/.cargo/registry/src/github.com-1ecc6299db9ec823/twitch-irc-4.0.0/src/client/event_loop.rs:84:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
error: execv(/mnt/c/Projets/Perso/Tests/test_actix_twitchirc/bin/linux_x86_64_release/WebService) failed(101)

Cargo output:

    Finished dev [unoptimized + debuginfo] target(s) in 1m 09s
     Running `target/debug/test_actix_twitchirc`
run_chatservice
start_chatservice
Joining Twitch channel
Twitch chat thread
Received message: Generic(HiddenIRCMessage(IRCMessage { tags: IRCTags({}), prefix: Some(HostOnly { host: "tmi.twitch.tv" }), command: "CAP", params: ["*", "ACK", "twitch.tv/tags twitch.tv/commands"] }))
Received message: Generic(HiddenIRCMessage(IRCMessage { tags: IRCTags({}), prefix: Some(HostOnly { host: "tmi.twitch.tv" }), command: "001", params: ["justinfan12345", "Welcome, GLHF!"] }))
Received message: Generic(HiddenIRCMessage(IRCMessage { tags: IRCTags({}), prefix: Some(HostOnly { host: "tmi.twitch.tv" }), command: "002", params: ["justinfan12345", "Your host is tmi.twitch.tv"] }))
Received message: Generic(HiddenIRCMessage(IRCMessage { tags: IRCTags({}), prefix: Some(HostOnly { host: "tmi.twitch.tv" }), command: "003", params: ["justinfan12345", "This server is rather new"] }))
Received message: Generic(HiddenIRCMessage(IRCMessage { tags: IRCTags({}), prefix: Some(HostOnly { host: "tmi.twitch.tv" }), command: "004", params: ["justinfan12345", "-"] }))
Received message: Generic(HiddenIRCMessage(IRCMessage { tags: IRCTags({}), prefix: Some(HostOnly { host: "tmi.twitch.tv" }), command: "375", params: ["justinfan12345", "-"] }))
Received message: Generic(HiddenIRCMessage(IRCMessage { tags: IRCTags({}), prefix: Some(HostOnly { host: "tmi.twitch.tv" }), command: "372", params: ["justinfan12345", "You are in a maze of twisty passages, all alike."] }))
Received message: Generic(HiddenIRCMessage(IRCMessage { tags: IRCTags({}), prefix: Some(HostOnly { host: "tmi.twitch.tv" }), command: "376", params: ["justinfan12345", ">"] }))
Received message: Join(JoinMessage { channel_login: "sirlynixvanfrietjes", user_login: "justinfan12345", source: IRCMessage { tags: IRCTags({}), prefix: Some(Full { nick: "justinfan12345", user: Some("justinfan12345"), host: Some("justinfan12345.tmi.twitch.tv") }), command: "JOIN", params: ["#sirlynixvanfrietjes"] } })
...

(note that you need xmake dev for this)

waruqi commented 2 years ago

That xmake collects all Cargo dependencies to build one single Cargo.toml to allow it to merge dependencies and collect the result, this is the easiest fix I think.

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.

Solution1

Use Cargo.toml

add_requires("cargo::test_actix_twitchirc", {configs = {tomlfile = path.join(os.scriptdir(), "Cargo.toml")}})

Cargo.toml

[package]
name = "test_actix_twitchirc"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[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"] }

Solution2

Write 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 add_requires("cargo::actix-web 4.0") configuration.

If we only use a single rust package, we can still continue to use add_requires("cargo::actix-web 4.0")

SirLynix commented 2 years ago

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.

waruqi commented 2 years ago

I have supported the solution1, and tested it for your example. It works now. https://github.com/xmake-io/xmake/pull/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")

https://github.com/xmake-io/xmake/blob/dev/tests/projects/rust/cargo_deps_with_toml/xmake.lua

waruqi commented 2 years ago

Does it work?

SirLynix commented 2 years ago

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.

waruqi commented 2 years ago

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?

you need add version to add_requires("cargo::test 1.0")