Demos and libraries using workspaces


I’m trying to get started by making a wasm library which also has demo binaries/webpages - but hit a roadblock in the basic project structure. I think I should use workspaces, so specific help for that is what I’m looking for, but any advice is appreciated.

So far I tried the following:

$ mkdir foo
$ cd foo
$ touch Cargo.toml
$ cargo new lib/bar --lib
$ cargo new examples/bar-demo --bin

The idea is that there will be more crates under lib/ and they can be demoed via separate example binaries (or web pages) under examples/. Eventually they’ll depend on eachother, but I’m having trouble getting started without dependencies so far.

I edited foo/Cargo.toml to have the following:

name = "foo"
edition = '2018'
version = "0.0.1"

members = [

However, running cargo build results in the following error:

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

This is the same error whether I run it in foo/, foo/lib/bar, or foo/examples/bar-demo

Oddly - those files do exist, specifically foo/lib/bar/src/ and foo/examples/bar-demo/src/

What am I doing wrong? :slight_smile:


You don’t have rust code “on the top level”, the root Cargo.toml exists only to define other members of workspace. With [package] section, however, Cargo expects to find sources for the root package. Luckly, just removing the package section works: here’s an example:


Awesome, that fixed it- thanks!

Followup question - what is the relationship of the top-level [profile.release] to the individual crates?

i.e. I see for wasm libs I want lto = true - do I put that in the top-level or in each lib crate’s Cargo.toml?


Currently, all crates in workpsace must use the single profile. I want to enable debug symbols in release for one of my binaries, so I have to do it via the root manifest.


Oh I see trying to specify them in each lib gives that exact warning :smiley: