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

Build hangs for some build scripts #13

Open
aldanor opened this issue Oct 11, 2023 · 5 comments
Open

Build hangs for some build scripts #13

aldanor opened this issue Oct 11, 2023 · 5 comments

Comments

@aldanor
Copy link

aldanor commented Oct 11, 2023

For larger projects, chances are there's always going to be some proc-macro dependencies involved, seems like cargo remark build just hangs; here's the simplest example (taken from paste docs):

use paste::paste; // add `paste = "1.0"` to deps

paste! { const [<Q R S T>]: &str = "success!"; }

fn main() {
    assert_eq!(paste! { [<Q R S T>].len() }, 8);
}

which results in hanging forever here:

❯ cargo +nightly remark build
[2023-10-11T15:19:31Z INFO  cargo_remark::cargo] Optimization remarks will be stored into target/remarks/yaml.
   Compiling paste v1.0.14
    Building [====>                        ] 1/5: paste(build.rs)

Edit: not sure if it's proc-macro-related, or if it's something to do with paste. Or dependencies that have a custom build.rs perhaps?

@aldanor
Copy link
Author

aldanor commented Oct 11, 2023

Update, tracked it down to a single line in paste's build.rs; minimal example that seems to hang is this: add build.rs with

fn main() {
    _ = "".split('.'); // <-- ???
}

This causes it to hang forever:

❯ cargo +nightly remark build
   Compiling test-remark v0.1.0 (test-remark)
    Building [                             ] 0/3: test-remark(build.rs)

@aldanor aldanor changed the title Build hangs if there's proc-macros involved Build hangs for some build scripts Oct 11, 2023
@aldanor
Copy link
Author

aldanor commented Oct 11, 2023

Looking into it a bit further, just running

RUSTFLAGS="-Cremark=all -Cdebuginfo=1" cargo +nightly build --release

causes

note: /rustc/59edd67056919c83c59001a8b4f2d8749359377a/library/core/src/char/methods.rs:1767:0 asm-printer (analysis): 179 instructions in function

note: /rustc/59edd67056919c83c59001a8b4f2d8749359377a/library/core/src/str/pattern.rs:544:32 gisel-irtranslator-memsize (analysis): Call to memset. Memory operation size: 4 bytes.
       Written Variables: <unknown> (4 bytes).

note: /rustc/59edd67056919c83c59001a8b4f2d8749359377a/library/core/src/str/pattern.rs:543:0 size-info (analysis): IRTranslator: Function: _ZN52_$LT$char$u20$as$u20$core..str..pattern..Pattern$GT$13into_searcher17h80469adc07d8dc57E: MI Instruction count changed from 0 to 43; Delta: 43

note: /rustc/59edd67056919c83c59001a8b4f2d8749359377a/library/core/src/str/pattern.rs:543:0 size-info (analysis): AArch64O0PreLegalizerCombiner: Function: _ZN52_$LT$char$u20$as$u20$core..str..pattern..Pattern$GT$13into_searcher17h80469adc07d8dc57E: MI Instruction count changed from 43 to 40; Delta: -3

note: /rustc/59edd67056919c83c59001a8b4f2d8749359377a/library/core/src/str/pattern.rs:546:9 gisel-legalize (missed): unable to legalize instruction: G_STORE %26:_(<4 x s8>), %25:_(p0) :: (store (<4 x s8>) into %ir.18, align 8)

error: could not compile `test-remark` (build script)

So,

  • Why does ^ happen?... Could/should -Cremark be disabled for build-scripts if possible?
  • cargo-remark should probably crash loudly and not hang in cases like this?

Perhaps related: rust-lang/cargo#6375 (re: not passing RUSTFLAGS down to build scripts which can cause all sorts of problems like here)

@Kobzol
Copy link
Owner

Kobzol commented Oct 12, 2023

Hi, thanks for investigating this! To be clear, you were able to reproduce this with an empty Cargo project containing the mentioned build script? I can't reproduce the build script error on such an empty project with a build script.

@aldanor
Copy link
Author

aldanor commented Oct 12, 2023

Yes, the following hangs:

cargo new --bin foo
cd foo
echo 'fn main() { _ = "".split(\'.\'); }' > build.rs
cargo +nightly remark build

(to clarify, this is on M1 macOS, things may behave different on x64/linux I think)

rustc version: rustc 1.75.0-nightly (59edd6705 2023-10-09)

@Kobzol
Copy link
Owner

Kobzol commented Oct 13, 2023

I see. This works for me on Linux, so it's hard for me to reproduce 😅 I think that the fact that it errors out for you (not the cargo remark hang, but the -Cremark=all error) should be reported to rust-lang/rust as a bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants