Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specifying jobs = 0 in .cargo/config hangs cargo forever without output #9219

Closed
orlp opened this issue Mar 1, 2021 · 9 comments · Fixed by #9584
Closed

Specifying jobs = 0 in .cargo/config hangs cargo forever without output #9219

orlp opened this issue Mar 1, 2021 · 9 comments · Fixed by #9584
Assignees
Labels
A-diagnostics Area: Error and warning messages generated by Cargo itself. C-bug Category: bug E-easy Experience: Easy

Comments

@orlp
Copy link
Contributor

orlp commented Mar 1, 2021

If you specify jobs = 0 in .cargo/config, your cargo build invocations will hang forever without output. Note that if you try to invoke cargo build -j 0 it will warn you:

$ cargo build -j 0
error: jobs must be at least 1

Steps

  1. Place a .cargo/config in any valid location with the following content:

     [build]
     jobs = 0
    
  2. Run cargo build.

  3. You will never reach step 3.

Possible Solution(s)

Check for jobs being 0 when reading the config file.

Notes

Output of cargo version: latest master commit, 0b2059e.

@Eh2406

This comment has been minimized.

@Eh2406 Eh2406 closed this as completed May 27, 2021
@ehuss

This comment has been minimized.

@Eh2406

This comment has been minimized.

@Eh2406 Eh2406 reopened this May 27, 2021
@ehuss ehuss added the E-easy Experience: Easy label May 28, 2021
@henrifrancois
Copy link
Contributor

Does the issue still persist? If so I would like to give it a try

@Eh2406
Copy link
Contributor

Eh2406 commented Jun 10, 2021 via email

@henrifrancois
Copy link
Contributor

@rustbot claim

@henrifrancois
Copy link
Contributor

Hey, @Eh2406 could you help me out with this? I have something I think should work, but I am not sure why it isn't making a difference at all.

In build_context.rs I have:

impl BuildConfig {
    /// Parses all config files to learn about build configuration. Currently
    /// configured options are:
    ///
    /// * `build.jobs`
    /// * `build.target`
    /// * `target.$target.ar`
    /// * `target.$target.linker`
    /// * `target.$target.libfoo.metadata`
    pub fn new(
        config: &Config,
        jobs: Option<u32>,
        requested_targets: &[String],
        mode: CompileMode,
    ) -> CargoResult<BuildConfig> {
        let cfg = config.build_config()?;
        let requested_kinds = CompileKind::from_requested_targets(config, requested_targets)?;
        if jobs == Some(0) {
            anyhow::bail!("jobs must be at least 1")
        }
        if jobs.is_some() && config.jobserver_from_env().is_some() {
            config.shell().warn(
                "a `-j` argument was passed to Cargo but Cargo is \
                 also configured with an external jobserver in \
                 its environment, ignoring the `-j` parameter",
            )?;
        }
        let jobs = match jobs.or(cfg.jobs) {
            None => ::num_cpus::get() as u32,
            Some(j) if j != 0 => (::num_cpus::get() as u32).max(j),
            Some(_) => anyhow::bail!("jobs may not be 0"),
        }; //.unwrap_or(::num_cpus::get() as u32);

which I assumed would be enough to handle the case where the jobs argument has a value of 0. Any pointers?

@Eh2406
Copy link
Contributor

Eh2406 commented Jun 14, 2021

That is what I would have expected to work. And when I am careful to run the Cargo I just build and not the cargo from rustup, it worked for me!

@henrifrancois
Copy link
Contributor

Oop, nevermind. I think I got it working.

bors added a commit that referenced this issue Jun 14, 2021
Handle "jobs = 0" case in cargo config files

Cargo hangs without output if the jobs argument under build in a cargo/config file is set to 0. This PR handles this case by providing an appropriate error.

Closes #9219
@bors bors closed this as completed in d95b29b Jun 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Error and warning messages generated by Cargo itself. C-bug Category: bug E-easy Experience: Easy
Projects
None yet
4 participants