# Build-Only Package

**URL:** <https://internals.rust-lang.org/t/build-only-package/22051>\
**Category:** compiler\
**Created:** [December 20, 2024, 6:15pm UTC](https://internals.rust-lang.org/t/build-only-package/22051 "2024-12-20T18:15:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anatoly03](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/anatoly03/32/10941_2.png) [@Anatoly03](https://internals.rust-lang.org/u/Anatoly03)\
**Post date:** [December 20, 2024, 6:15pm UTC](https://internals.rust-lang.org/t/build-only-package/22051/1 "2024-12-20T18:15:23Z")

</div>

Currently if a Rust module does not have `src/lib.rs` or `src/main.rs`, it will not even build. The build script should still have a life cycle so those files could be generated from the build script itself, additionally, a cargo.toml flag could be set, that this is a "build" module and run the build script on `cargo build`, but not have any Rust code, here is the use case:

A workspace with mostly Rust code, but also non-rust javascript frontend and directories with other programming languages. I think it'd be pretty neat if running I could startup all these components from a single cargo command. This way Rust could be used to execute build scripts for non-Rust fragments.

```toml
# Cargo.toml
[package]
build="build.rs"

```

---

<div class="post-metadata">

**Author:** ![epage](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/epage/32/3171_2.png) [@epage](https://internals.rust-lang.org/u/epage)\
**Post date:** [December 20, 2024, 6:29pm UTC](https://internals.rust-lang.org/t/build-only-package/22051/2 "2024-12-20T18:29:58Z")

</div>

> [@Anatoly03](#):
>
> Currently if a Rust module does not have `src/lib.rs` or `src/main.rs`, it will not even build. The build script should still have a life cycle so those files could be generated from the build script itself, additionally, a cargo.toml flag could be set, that this is a "build" module and run the build script on `cargo build`, but not have any Rust code, here is the use case:

In working with `build.rs` files, there is the general expectation and assumption that they do not write to `src` but only `OUT_DIR`, e.g. [Files generated by build script into src/ are compiled twice · Issue #3076 · rust-lang/cargo · GitHub](https://github.com/rust-lang/cargo/issues/3076)

On top of that, Cargo enumerates all build-targets at the very beginning and allowing dynamically generated build-targets would be a massive undertaking and may even run into fundamental problems where we need to know something before we know it. Requiring users to explicitly enumerate these in `Cargo.toml` may help. In fact, you might even be able to do that today.

> [@Anatoly03](#):
>
> A workspace with mostly Rust code, but also non-rust javascript frontend and directories with other programming languages. I think it'd be pretty neat if running I could startup all these components from a single cargo command. This way Rust could be used to execute build scripts for non-Rust fragments.

There is a somewhat related request at [Allow a build script (build.rs) in a virtual manifest Cargo.toml · Issue #8732 · rust-lang/cargo · GitHub](https://github.com/rust-lang/cargo/issues/8732)

I suspect trying to use cargo as a general purpose build tool will lead to frustrations. For example,

- For correctness of regular build scripts, we intentionally do not tell them of some details that more general purpose tooling may way, see [Need a reliable way to get the target dir from the build script · Issue #9661 · rust-lang/cargo · GitHub](https://github.com/rust-lang/cargo/issues/9661)
- You'd likely want to have more control over them that we don't provide today, e.g. [Command to run only build scripts · Issue #7178 · rust-lang/cargo · GitHub](https://github.com/rust-lang/cargo/issues/7178)
- There is nuance to writing build scripts that can be lost track of and cause needless rebuilds

btw I've started a discussion in the opposite direction, on finding in what ways people use build scripts and what we features we can provide to replace them, see [Reduce the need for users to write build scripts · Issue #14948 · rust-lang/cargo · GitHub](https://github.com/rust-lang/cargo/issues/14948)

---

<div class="post-metadata">

**Author:** ![steffahn](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/steffahn/32/13288_2.png) [@steffahn](https://internals.rust-lang.org/u/steffahn)\
**Post date:** [June 13, 2026, 6:30pm UTC](https://internals.rust-lang.org/t/build-only-package/22051/3 "2026-06-13T18:30:21Z")

</div>

This topic was automatically closed 540 days after the last reply. New replies are no longer allowed.
