-
-
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
Make compiler aware of output extension when building programs #13370
Make compiler aware of output extension when building programs #13370
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO the code for determining the output filename gets quite confusing. Maybe it could use some refactoring?
For example, the calculation of original_output_filename
is completely unnecessary if an explicit output file is given.
This PR now adds # on x86_64-linux-gnu
$ echo 1 > foo
$ mkdir bar
$ crystal build --cross-compile --target=x86_64-linux-gnu foo
Error: compilation will overwrite source file 'foo', either change its extension to '.cr' or specify an output file with '-o'
$ crystal build --cross-compile --target=x86_64-linux-gnu -obar foo
Error: can't use `bar` as output filename because it's a directory Neither build should produce an error because |
.exe
extension when building programsCrystal 1.9+ has made the `.s` and `.ll` files follow the base name of the output rather than the input (I think this is due to crystal-lang/crystal#13370), this PR matches the Crystal compiler's behavior
The compiler is currently unaware of the use of
.exe
when building a program on Windows, and incorrectly reports about existing files:In the above example, it is always
foo.exe
orbar.exe
that is being built, so the existence of a file calledfoo
orbar
should not generate an error.This PR adds
.exe
right after the output filename is collected from the command-line arguments. The above builds will succeed, whereas files calledfoo.exe
orbar.exe
will now block the builds:30f656c extends this to object files on all platforms.