Skip to content

fix(moonutil) *nix targets output executable files with .exe extension. #775

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

hanbings
Copy link

Related Issues

Type of Pull Request

  • Bug fix
  • New feature
    • I have already discussed this feature with the maintainers.
  • Refactor
  • Performance optimization
  • Documentation
  • Other (please describe):

Does this PR change existing behavior?

  • Yes (please describe the changes below)
    • When building on the Windows operating system, the output will be an executable file with a .exe extension, whereas on Linux, the output will be an executable file with a .out extension.
  • No

Does this PR introduce new dependencies?

  • No
  • Yes (please check binary size changes)

Checklist:

  • Tests added/updated for bug fixes or new features
  • Compatible with Windows/Linux/macOS

Copy link

peter-jerry-ye-code-review bot commented Apr 26, 2025

Consider using a platform-agnostic constant for executable extension

Category
Maintainability
Code Snippet
impl TargetBackend { pub fn get_executable_extension() -> &'static str { #[cfg(windows)] "exe" #[cfg(not(windows))] "out" } }
Recommendation
Create a single function that returns the platform-specific extension rather than using cfg attributes in multiple places
Reasoning
Currently the .exe vs .out extension check is repeated in multiple places. Having a single source of truth would make the code more maintainable and reduce potential inconsistencies.

Test case for single.exe output has inconsistent expectation on non-Windows

Category
Maintainability
Code Snippet
$ROOT/a/b/target/single.out
$ROOT/a/b/target/single.exe

Recommendation
Fix test case to use correct extension in expectation for non-Windows platforms
Reasoning
The test checks for .out extension on non-Windows but one expectation still shows .exe, which could cause test failures

Documentation comment for extension handling is separated from implementation

Category
Correctness
Code Snippet
/// Returns the appropriate file extension for the target backend.
/// On Windows, native and LLVM targets use '.exe'
/// On other platforms, native and LLVM targets use '.out'
Recommendation
Move documentation closer to the actual extension selection logic to keep related code and docs together
Reasoning
The documentation explaining the extension logic is physically separated from the actual implementation, which could lead to out-of-sync documentation as code evolves

@hanbings
Copy link
Author

hanbings commented Apr 26, 2025

Just to add a small point: changing *.exe to *.out is mainly based on the convention that gcc and clang default to producing files with the .out suffix.

When I searched online, most of the discussions I found were about compatibility. What I would like to ask is: since moonbit is a new language, is it necessary to carry over such historical conventions?
Perhaps it could follow an approach similar to Rust (apologies for bringing up another language here, but I thought it would be an appropriate example), and by default, output an ELF file without any suffix on *nix systems?

cc @ftcai

@hanbings hanbings force-pushed the fix-extension branch 2 times, most recently from 920da48 to 70bb356 Compare April 27, 2025 21:16
@waterlens
Copy link
Collaborator

waterlens commented Apr 28, 2025

Use .exe extensions makes it possible to have a consistent binary name among all OSs we supported. It's not something just about compatibility.
Is there a specific case where users need a file name without the extension, otherwise something won't work?

By the way, removing .exe on Unix can lead to many duplicated test cases, which is not ideal for maintainability:
https://github.com/moonbitlang/moon/blob/df8b155ac39349359c71624633eb62581d5edac7/crates/moon/tests/test_cases/mod.rs

cc @Young-Flash

@hanbings
Copy link
Author

hanbings commented Apr 28, 2025

Is there a specific case where users need a file name without the extension, otherwise something won't work?

I don't think there are any programs that actually rely on the file extension to work; it's just that its behavior on *nix systems is a bit unusual. :)

If this is not a bug but an intended feature, then I think we can go ahead and close this PR.

Thanks.


Edit: Additionally, if the output binary carries an .exe extension, it would mean that when used in the terminal, the extension has to be included, which feels a bit odd.

For example: moon.exe build

Although it's true that developers can specify the output filename manually using -o, I feel that this adds a bit of unnecessary burden for them.

@hanbings
Copy link
Author

By the way, removing on Unix .exe can lead to many duplicated test cases, which is not ideal for maintainability: https://github.com/moonbitlang/moon/blob/df8b155ac39349359c71624633eb62581d5edac7/crates/moon/tests/test_cases/mod.rs

For testing, I think there might be a way to selectively (e.g., only in tests, by additionally using -o to specify a name) output binaries with a consistent extension. Meanwhile, we could separately maintain some test cases to verify the default extensions on different operating systems. I am willing to spend time in the long term to help maintain this.

If you’re okay with it, I’d like to continue working on this PR until we find a solution that we can all agree on — either using the .out extension or not adding any extension on *nix. :)

@Young-Flash
Copy link
Collaborator

for maintainability, I prefer to keep the extension for now.

thanks

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

Successfully merging this pull request may close these issues.

3 participants