{"record":{"id":"14ae698d639d0108","repo":"rust-lang/cargo","slug":"no-library-targets-found-in-packages","errorCode":null,"errorMessage":"no library targets found in packages: {}","messagePattern":"no library targets found in packages: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/ops/cargo_compile/unit_generator.rs","lineNumber":454,"sourceCode":"                            self.ws.gctx().shell().warn(format!(\n                                \"doc tests are not supported for crate type(s) `{}` in package `{}`\",\n                                types_str.join(\", \"),\n                                pkg.name()\n                            ))?;\n                        } else {\n                            libs.push(proposal)\n                        }\n                    }\n                    if !all_targets && libs.is_empty() && *lib == LibRule::True {\n                        let names = self\n                            .packages\n                            .iter()\n                            .map(|pkg| pkg.name())\n                            .collect::<Vec<_>>();\n                        if names.len() == 1 {\n                            anyhow::bail!(\"no library targets found in package `{}`\", names[0]);\n                        } else {\n                            anyhow::bail!(\n                                \"no library targets found in packages: {}\",\n                                names.join(\", \")\n                            );\n                        }\n                    }\n                    proposals.extend(libs);\n                }\n\n                let default_mode = to_compile_mode(self.intent);\n\n                // If `--tests` was specified, add all targets that would be\n                // generated by `cargo test`.\n                let test_filter = match tests {\n                    FilterRule::All => Target::tested,\n                    FilterRule::Just(_) => Target::is_test,\n                };\n                let test_mode = match self.intent {\n                    UserIntent::Build => CompileMode::Test,","sourceCodeStart":436,"sourceCodeEnd":472,"githubUrl":"https://github.com/rust-lang/cargo/blob/eb98b54bc9f3c74519f43d066cb3fd02ebc88df0/src/ops/cargo_compile/unit_generator.rs#L436-L472","documentation":"Plural-form sibling of errors 75/76: same condition (LibRule::True, libs empty, not all_targets) but multiple packages are in scope, so cargo lists all of them. It indicates that NONE of the selected packages expose a library target.","triggerScenarios":"Running `cargo build --lib` (or a workspace-wide doc/test intent needing libs) across a workspace where no member has a [lib] target; selecting several binary-only packages.","commonSituations":"Workspace of binary-only crates; misconfigured CI invoking --lib across the workspace; default-members set to bin-only packages.","solutions":["Drop the --lib flag, or scope to the package that has a library: `-p <lib-pkg>`.","Add [lib] sections to the crates that should expose libraries.","Adjust workspace default-members so library-needing intents include a lib crate."],"exampleFix":"# before\ncargo build --lib  # workspace of bin crates\n# after\ncargo build -p shared-lib --lib","handlingStrategy":"validation","validationCode":"// For workspace-wide lib intents, ensure at least one member has a lib.\nfn any_lib(members: &[Package]) -> bool {\n    members.iter().flat_map(|p| &p.targets).any(|t| matches!(t.kind, TargetKind::Lib(_)))\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Scope --lib to a package that actually has a [lib] via -p.","Ensure workspace default-members include a lib crate for lib-needing intents.","Avoid `cargo build --lib` across all-binary workspaces."],"tags":["cargo-compile","target-selection","library","workspace","manifest"],"backgroundTag":null,"analyzedSha":"eb98b54bc9f3c74519f43d066cb3fd02ebc88df0","analyzedAt":"2026-08-11T17:42:36.556Z","contentChangedAt":"2026-08-11T17:42:36.556Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}