DelSkayn / rquickjs

High level bindings to the quickjs javascript engine
MIT License
434 stars 59 forks source link

`cargo build` hang on `rquickjs-sys(build)` #268

Closed fuyufjh closed 4 months ago

fuyufjh commented 4 months ago

cargo build hangs here forever:

image

I tried to find out the subprocess with ps command, and it turns out to hang on patch -p1

  501 56872 56853   0  5:39PM ttys020    0:00.01 /Users/eric/Workspace/risingwave/target/debug/build/rquickjs-sys-050e47b1f15a814b/build-script-build
  501 56894 56872   0  5:39PM ttys020    0:00.04 patch -p1

Environment:

DelSkayn commented 4 months ago

I am aware of the issue, however I have trouble finding a fix. The problem only seems to happen on mac as I personally haven't encountered this problem on linux. Users have told me that you seem to be able to fix the build by pressing enter twice in the terminal running the build. This makes this issue even more confusing since there shouldn't be any way for terminal input to make it's way to the hanging patch process as the build script pipes files from stdin. As I don't have access to a mac I can't really work on a fix so unfortunately this will probably remain an issue for a while.

One thing I can think of is that mac has a different patch binary then linux so you could try to install GNU-patch, the patch binary I use on linux.

wangrunji0408 commented 4 months ago

I can reproduce this bug on the same environment by:

  1. cargo clean && cargo check
  2. press Ctrl+C during building rquickjs-sys(build) to cancel it
  3. cargo check again

When I enabled the verbose output, it blocked with the following output:

$ cargo c -vv
...
[rquickjs-sys 0.5.0] Applying patch patches/error_column_number.patch
[rquickjs-sys 0.5.0] patching file cutils.c
[rquickjs-sys 0.5.0] patching file cutils.h
[rquickjs-sys 0.5.0] patching file quickjs-atom.h
[rquickjs-sys 0.5.0] patching file quickjs-opcode.h
[rquickjs-sys 0.5.0] patching file quickjs.c
[rquickjs-sys 0.5.0] patching file quickjs.h
[rquickjs-sys 0.5.0] patching file 'tests/test_line_column.js'
    Building [=======================> ] 360/365: rquickjs-sys(build)

Then I pressed enter, the build continued until completion:

    Building [=======================> ] 360/365: rquickjs-sys(build)                                                                                        
[rquickjs-sys 0.5.0] Patch creates file that already exists!  Assume -R? [y] patching file quickjs.c
[rquickjs-sys 0.5.0] patching file quickjs.c
[rquickjs-sys 0.5.0] Applying patch patches/get_function_proto.patch
[rquickjs-sys 0.5.0] patching file quickjs.c
[rquickjs-sys 0.5.0] patching file quickjs.h
...

The reason of the stuck appears to be that it prompts for user input, as it has been run once, so the file already exists.

Adding a -f option to the patch command seems to successfully resolve this issue for me.

https://github.com/DelSkayn/rquickjs/blob/9716bbb760f6cd5f08517f15eac70328e64307d9/sys/build.rs#L250-L251

 let mut child = Command::new("patch") 
-     .args(["-p1"]) 
+     .args(["-p1", "-f"]) 
DelSkayn commented 4 months ago

Thank you! I have been really annoyed with this bug and my lack of ability to diagnose it.

I will fix it shortly.