pre-commit-ci / issues

public issues for https://pre-commit.ci
16 stars 3 forks source link

rustfmt fails on build #121

Closed AceofSpades5757 closed 2 years ago

AceofSpades5757 commented 2 years ago

While trying to get rustfmt to work, I ran into this error. The rustfmt repo was one I had forked and added a .pre-commit-config.yaml file to, matching Python's black repo for reference. Although this worked great on my machine, it doesn't seem to work when trying to use with pre-commit.ci.

Any suggestions? I saw some similar issues, but thought they'd be handled once the hook file was added to the repository, and the appropriate changes to the options, like language, be made.

If this is intended to fail, could there be a more clear message as to why the hook failed?

Error Output

build attempt 1...
    => error
    [INFO] Installing environment for https://github.com/AceofSpades5757/rustfmt.
    [INFO] Once installed this environment will be reused.
    [INFO] This may take a few minutes...
    An unexpected error has occurred: CalledProcessError: command: ('/opt/rust/cargo/bin/cargo', 'install', '--bins', '--root', '/pc/clone/jWRdRDeaQFyzu2V6YXMHIw/rustenv-default', '--path', '.')
    return code: 1
    expected return code: 0
    stdout: (none)
    stderr:
        info: syncing channel updates for 'nightly-2022-03-27-x86_64-unknown-linux-gnu'
        error: could not create temp file /opt/rust/rustup/tmp/pnvrh6gki54od4te_file: Read-only file system (os error 30)

    Check the log at /pc/pre-commit.log
build attempt 2...

Added hook config file

Note: Unsure as to what information would be useful here.

- id: rustfmt
  name: rustfmt
  description: "A tool for formatting Rust code according to style guidelines."
  entry: rustfmt
  language: rust
  types: [rust]
asottile commented 2 years ago

do you have a link to your run? this is supposed to work (I've used rustfmt myself before)

AceofSpades5757 commented 2 years ago

Yeah, here you go: https://results.pre-commit.ci/run/github/481453952/1651103136.fLOGLt7dR629nADKzzK34A

Is it? They don't have the hook file and the hook repo I found that allowed you to use rustfmt wouldn't work (this one). I think it was because it required cargo installed on pre-commit.ci with the option language: system set.

asottile commented 2 years ago

I used it with repo: local before, let me see if I can get that working again (it was mostly just to demonstrate the rust support)

it looks like installing rustfmt tries to install a nightly rust globally, which isn't supported -- you could perhaps try and review / complete this pre-commit feature which would make that possible: https://github.com/pre-commit/pre-commit/pull/1863

asottile commented 2 years ago

yeah the latest version of rustfmt requires nightly rustc to build, we only ship stable rustc

asottile commented 2 years ago

if you can figure out how to ship both that'd be acceptable as well -- https://github.com/pre-commit-ci/runner-image -- I don't know quite enough about cargo to make that happen myself unfortunately

AceofSpades5757 commented 2 years ago

Got it, thanks. It should work on stable just fine, so I'll take a look.

asottile commented 2 years ago

oh it looks like we ship rustfmt as a global component already so it might not need to be installed? https://github.com/pre-commit-ci/runner-image/blob/9e9e4bc58407b77f3103e4c1fbf4632f7d5db415/Dockerfile#L125

AceofSpades5757 commented 2 years ago

If the component is added, then the command would be cargo fmt, but I'm not sure how to explain that to pre-commit.ci.

asottile commented 2 years ago
-   repo: local
    hooks:
    -   id: cargo-fmt
        name: cargo fmt
        language: rust
        entry: cargo fmt
        types: [rust]

that should work (assuming I remembered all the fields while typing a pre-commit config on my phone!)

AceofSpades5757 commented 2 years ago

Close! I changed the entry to rustfmt to accept paths and it worked! Thank you very much.

Here's that some piece from my config file. Hope someone else finds this useful.

- repo: local
  hooks:
  - id: cargo-fmt
    name: Rust Formatter
    description: "A tool for formatting Rust code according to style guidelines."
    language: rust
    entry: rustfmt
    types: [rust]

pre-commit.ci link for ref