How to build multi workspace cargo project in rust











up vote
0
down vote

favorite












I have multi-workspace Cargo project. It has two workspaces, common and server. common is a lib project and server is a bin project.



The location of the project in Github is here.



Below is the project structure.



.
├── Cargo.toml
├── common
│   ├── Cargo.toml
│   └── src
│   └── lib.rs
├── README.md
└── server
├── Cargo.toml
└── src
└── main.rs

4 directories, 6 files


And the file contents of ./Cargo.toml file is



[package]
name = "multi_module_cargo_project"
version = "0.1.0"
authors = ["rajkumar"]

[workspace]
members = ["common", "server"]

[dependencies]


When I run the command cargo build --all:



error: failed to parse manifest at `/home/rajkumar/Coding/Rust/ProgrammingRust/multi_module_cargo_project/Cargo.toml`

Caused by:
no targets specified in the manifest
either src/lib.rs, src/main.rs, a [lib] section, or [[bin]] section must be present


So I added below in Cargo.toml but still couldn't build the project.



[[bin]]
name = "server/src/main.rs"


How can I build the project. What I'm missing?










share|improve this question




















  • 1




    I think you should only put [workspace] inside the root manifest and so remove [package] and [dependencies], put that only in the manifest inside server and common.
    – Stargateur
    Nov 3 at 17:27












  • @Stargateur - You are right. That works. I would've accepted your answer if you answered the question.
    – Rajkumar Natarajan
    Nov 3 at 18:35















up vote
0
down vote

favorite












I have multi-workspace Cargo project. It has two workspaces, common and server. common is a lib project and server is a bin project.



The location of the project in Github is here.



Below is the project structure.



.
├── Cargo.toml
├── common
│   ├── Cargo.toml
│   └── src
│   └── lib.rs
├── README.md
└── server
├── Cargo.toml
└── src
└── main.rs

4 directories, 6 files


And the file contents of ./Cargo.toml file is



[package]
name = "multi_module_cargo_project"
version = "0.1.0"
authors = ["rajkumar"]

[workspace]
members = ["common", "server"]

[dependencies]


When I run the command cargo build --all:



error: failed to parse manifest at `/home/rajkumar/Coding/Rust/ProgrammingRust/multi_module_cargo_project/Cargo.toml`

Caused by:
no targets specified in the manifest
either src/lib.rs, src/main.rs, a [lib] section, or [[bin]] section must be present


So I added below in Cargo.toml but still couldn't build the project.



[[bin]]
name = "server/src/main.rs"


How can I build the project. What I'm missing?










share|improve this question




















  • 1




    I think you should only put [workspace] inside the root manifest and so remove [package] and [dependencies], put that only in the manifest inside server and common.
    – Stargateur
    Nov 3 at 17:27












  • @Stargateur - You are right. That works. I would've accepted your answer if you answered the question.
    – Rajkumar Natarajan
    Nov 3 at 18:35













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I have multi-workspace Cargo project. It has two workspaces, common and server. common is a lib project and server is a bin project.



The location of the project in Github is here.



Below is the project structure.



.
├── Cargo.toml
├── common
│   ├── Cargo.toml
│   └── src
│   └── lib.rs
├── README.md
└── server
├── Cargo.toml
└── src
└── main.rs

4 directories, 6 files


And the file contents of ./Cargo.toml file is



[package]
name = "multi_module_cargo_project"
version = "0.1.0"
authors = ["rajkumar"]

[workspace]
members = ["common", "server"]

[dependencies]


When I run the command cargo build --all:



error: failed to parse manifest at `/home/rajkumar/Coding/Rust/ProgrammingRust/multi_module_cargo_project/Cargo.toml`

Caused by:
no targets specified in the manifest
either src/lib.rs, src/main.rs, a [lib] section, or [[bin]] section must be present


So I added below in Cargo.toml but still couldn't build the project.



[[bin]]
name = "server/src/main.rs"


How can I build the project. What I'm missing?










share|improve this question















I have multi-workspace Cargo project. It has two workspaces, common and server. common is a lib project and server is a bin project.



The location of the project in Github is here.



Below is the project structure.



.
├── Cargo.toml
├── common
│   ├── Cargo.toml
│   └── src
│   └── lib.rs
├── README.md
└── server
├── Cargo.toml
└── src
└── main.rs

4 directories, 6 files


And the file contents of ./Cargo.toml file is



[package]
name = "multi_module_cargo_project"
version = "0.1.0"
authors = ["rajkumar"]

[workspace]
members = ["common", "server"]

[dependencies]


When I run the command cargo build --all:



error: failed to parse manifest at `/home/rajkumar/Coding/Rust/ProgrammingRust/multi_module_cargo_project/Cargo.toml`

Caused by:
no targets specified in the manifest
either src/lib.rs, src/main.rs, a [lib] section, or [[bin]] section must be present


So I added below in Cargo.toml but still couldn't build the project.



[[bin]]
name = "server/src/main.rs"


How can I build the project. What I'm missing?







rust rust-cargo






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 3 at 18:58









Peter Hall

14.2k73778




14.2k73778










asked Nov 3 at 17:11









Rajkumar Natarajan

9041032




9041032








  • 1




    I think you should only put [workspace] inside the root manifest and so remove [package] and [dependencies], put that only in the manifest inside server and common.
    – Stargateur
    Nov 3 at 17:27












  • @Stargateur - You are right. That works. I would've accepted your answer if you answered the question.
    – Rajkumar Natarajan
    Nov 3 at 18:35














  • 1




    I think you should only put [workspace] inside the root manifest and so remove [package] and [dependencies], put that only in the manifest inside server and common.
    – Stargateur
    Nov 3 at 17:27












  • @Stargateur - You are right. That works. I would've accepted your answer if you answered the question.
    – Rajkumar Natarajan
    Nov 3 at 18:35








1




1




I think you should only put [workspace] inside the root manifest and so remove [package] and [dependencies], put that only in the manifest inside server and common.
– Stargateur
Nov 3 at 17:27






I think you should only put [workspace] inside the root manifest and so remove [package] and [dependencies], put that only in the manifest inside server and common.
– Stargateur
Nov 3 at 17:27














@Stargateur - You are right. That works. I would've accepted your answer if you answered the question.
– Rajkumar Natarajan
Nov 3 at 18:35




@Stargateur - You are right. That works. I would've accepted your answer if you answered the question.
– Rajkumar Natarajan
Nov 3 at 18:35












1 Answer
1






active

oldest

votes

















up vote
1
down vote



accepted










You included a [package] section in your main Cargo.toml file. This section indicates that you want to build a main package in addition to the packages in the workspace. However, you don't have any source files for the main package, so Cargo complains.



The solution is to simply omit the [package] section, and only include [workspace]. This configures a virtual workspace – a workspace that is only a container for member packages, but does not build a package itself.



See the main Cargo.toml file of Rocket for a real-world example of a virtual workspace, and Tokio for a real-world example of a workspace with a main package.






share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53133637%2fhow-to-build-multi-workspace-cargo-project-in-rust%23new-answer', 'question_page');
    }
    );

    Post as a guest
































    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    1
    down vote



    accepted










    You included a [package] section in your main Cargo.toml file. This section indicates that you want to build a main package in addition to the packages in the workspace. However, you don't have any source files for the main package, so Cargo complains.



    The solution is to simply omit the [package] section, and only include [workspace]. This configures a virtual workspace – a workspace that is only a container for member packages, but does not build a package itself.



    See the main Cargo.toml file of Rocket for a real-world example of a virtual workspace, and Tokio for a real-world example of a workspace with a main package.






    share|improve this answer

























      up vote
      1
      down vote



      accepted










      You included a [package] section in your main Cargo.toml file. This section indicates that you want to build a main package in addition to the packages in the workspace. However, you don't have any source files for the main package, so Cargo complains.



      The solution is to simply omit the [package] section, and only include [workspace]. This configures a virtual workspace – a workspace that is only a container for member packages, but does not build a package itself.



      See the main Cargo.toml file of Rocket for a real-world example of a virtual workspace, and Tokio for a real-world example of a workspace with a main package.






      share|improve this answer























        up vote
        1
        down vote



        accepted







        up vote
        1
        down vote



        accepted






        You included a [package] section in your main Cargo.toml file. This section indicates that you want to build a main package in addition to the packages in the workspace. However, you don't have any source files for the main package, so Cargo complains.



        The solution is to simply omit the [package] section, and only include [workspace]. This configures a virtual workspace – a workspace that is only a container for member packages, but does not build a package itself.



        See the main Cargo.toml file of Rocket for a real-world example of a virtual workspace, and Tokio for a real-world example of a workspace with a main package.






        share|improve this answer












        You included a [package] section in your main Cargo.toml file. This section indicates that you want to build a main package in addition to the packages in the workspace. However, you don't have any source files for the main package, so Cargo complains.



        The solution is to simply omit the [package] section, and only include [workspace]. This configures a virtual workspace – a workspace that is only a container for member packages, but does not build a package itself.



        See the main Cargo.toml file of Rocket for a real-world example of a virtual workspace, and Tokio for a real-world example of a workspace with a main package.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 4 at 10:04









        Sven Marnach

        335k75737685




        335k75737685






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53133637%2fhow-to-build-multi-workspace-cargo-project-in-rust%23new-answer', 'question_page');
            }
            );

            Post as a guest




















































































            這個網誌中的熱門文章

            Tangent Lines Diagram Along Smooth Curve

            Yusuf al-Mu'taman ibn Hud

            Zucchini