Cargo package doesn't include entire source code

I'm trying to publish GitHub - project-machine/puzzlefs to crates.io and it fails to build due to missing files in the package. Here is my library's structure:

├── build.rs
├── Cargo.toml
└── src
    ├── builder
    ├── builder.rs
    ├── common
    ├── common.rs
    ├── compression
    ├── compression.rs
    ├── extractor
    ├── extractor.rs
    ├── format
    ├── format.rs
    ├── fsverity_helpers
    ├── fsverity_helpers.rs
    ├── lib.rs
    ├── oci
    ├── oci.rs
    ├── reader
    └── reader.rs

And cargo package -l only shows the top level .rs files:

.cargo_vcs_info.json
Cargo.toml
Cargo.toml.orig
build.rs
src/builder.rs
src/common.rs
src/compression.rs
src/extractor.rs
src/format.rs
src/fsverity_helpers.rs
src/lib.rs
src/oci.rs
src/reader.rs

None of the directories builder, common, compression, extractor, format, fsverity_helpers, oci and reader are included.
The project builds successfully with cargo build.

Are there any files inside the missing directories? If there are rust files, are they referenced with mod foo; somewhere?

1 Like

You could try setting the include field in the Cargo.toml The Manifest Format - The Cargo Book

I see you have additional Cargo.toml files in there. I don't think that'll work as-is. Think about whether you want those published separately to crates.io. It's probably better to rewrite those as simple sub-modules instead.

2 Likes

Yes, e.g. here: https://github.com/project-machine/puzzlefs/blob/master/puzzlefs-lib/src/builder.rs#L34

If the folders contain sub-crates, they must each be published separately.

There are two crates in there, but I'm only trying to package puzzlefs-lib. cargo-package -l's output is from the puzzlefs-lib directory.

I actually forgot to delete the Cargo.toml files when I reorganized the repository:

src/builder/Cargo.toml
src/common/Cargo.toml
src/compression/Cargo.toml
src/extractor/Cargo.toml
src/format/Cargo.toml
src/fsverity_helpers/Cargo.toml
src/oci/Cargo.toml
src/reader/Cargo.toml

This is mentioned in The Manifest Format - The Cargo Book

Regardless of whether `exclude` or `include` is specified, the following files are always excluded:

* Any sub-packages will be skipped (any subdirectory that contains a `Cargo.toml` file).
* A directory named `target` in the root of the package will be skipped.