-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Unique id for ephemeral binaries #8340
Comments
is this what you are looking for? |
both my comments have been resolved by corresponding edits |
Yes, sorry, I also don't understand the issue. But note that right now running the compiler twice in parallel doesn't work well. |
Yes because the filenames clash. It looks like the crun solution from @wontruefree would do the trick. I just wish it were more tightly integrated. Also, I'm not sure if it's possible to pass the '--release' option to crystal through the shebang line. |
I recently found the same issue, in my case i have a program that process some text, for example cat "1 2 3\n4 5 6\n" | ./myprog.cr extract-first-line | ./myprog.cr get-first-col But some times the second compilation clashes with the first and we get the error
I also think it would be nice to have the crystal compiler handle this cases, so the user wont need to install minimal program# program.cr
#!/usr/bin/env crystal
while line = gets
puts line
end echo "Hello\nWorld\n" | program.cr | program.cr |
Simpler: #!/usr/bin/env crystal
sleep 1 Then |
My suggestion: don't use crystal a scripting language. Compile the program to a binary. Then it'll be faster (no need to wait for compilation) and you won't have this "compiler is running twice" problem. |
Yes compilation would render the problem moot, but there are times when I don't want to deal with separate source and binary files. This is one of the nice features of scripting languages. If crystal can already behave like a scripting language, why not go all the way solve this filename collision problem. Crun would work, but it's a work-around, not a genuine solution. Perhaps if it were more tightly integrated or simply subsumed into crystal then we'd basically be taking it all the way in terms of behaving like a scripting language -- I think, since I haven't looked into the code path of when crystal is called via the she-bang. Ideally crystal scripting language would behave like make and only recompile if any of the source files are newer than the executable. This would be an improvement, no? Maybe crun is doing that but like @NIFR91 said, it would be nice to bypass yet-another-dependency. Plus I don't know if it's possible to pass compiler arguments like '--release' via crun. |
I agree with @bkao also we have |
We can exclusively lock the compiler cache directory while the compiler is using it, and atomically replace the output file after linking (don't write it in place). Crystal already has flock bound, but it might have to be added to dirfds. |
Maybe crystal could have a parameter like "--unique-id=x" then you could use a wrapper script (wraps crystal) for your bash shebang, though...that doesn't feel optimal somehow... |
@rdp, I don't think the actual name of the executable is the problem. Simply make one component of the filename be a hash of the source code. For example: foo.cr --> .foo.6c1a0 (temp file) --> foo.6c1a0 (final exe) Have the crystal system first check for the hidden file indicating the compilation is in progress to prevent race conditions. Order of operations would be something like:
|
Just a general question: How would you determine the uid? I'd assume it should be some kind of hash over the source code? Considering that programs can contain dynamic data, such as the result of other programs (as
I assume you would only want to rebuild the binary when the (actual) source code has changed. That seems like a prototypical use case for a build management tool like |
I like @RX14 idea. Maybe each crystal "output filename" could go in its own separate cache folder somehow, then compiling could |
Would it be possible to name the ephemeral binaries in .cache with some type of unique id? I don't want to compile a permanent binary and prefer to use it like a scripting language, but when I do this in a MapReduce framework each instance of the script compiles to the same filename causing it to crash if two or more instances are simultaneously writing the binary.
I like to do something like this where myprog.cr has your typical shebang line: "#!/usr/bin/env crystal":
cat file.json | myprog.cr --release > out
Which generates this binary:
~/.cache/crystal/crystal-run-myprog.tmp
Would be nice if the binaries were named with unique id's like:
~/.cache/crystal/crystal-run-myprog-<someuniqid>.tmp
This way each instance in my MapReduce multi-process framework gets its own file.
The text was updated successfully, but these errors were encountered: