How can I build multiple binaries with Cargo?

后端 未结 3 710
离开以前
离开以前 2020-12-04 08:36

I\'d like to make a project with a daemon and a client, connecting through a unix socket.

A client and a daemon

3条回答
  •  星月不相逢
    2020-12-04 09:14

    You can specify multiple binaries using [[bin]], as mentioned here:

    [[bin]]
    name = "daemon"
    path = "src/daemon/bin/main.rs"
    
    [[bin]]
    name = "client"
    path = "src/client/bin/main.rs"
    

    Tip: If you instead put these files in src/bin/daemon.rs and src/bin/client.rs, you'll get two executables named daemon and client as Cargo compiles all files in src/bin into executables with the same name automatically. You need to specify names and paths like in the snippet above only if you don't follow this convention.

提交回复
热议问题