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

Cross-compilation from Linux to Windows #27

Closed
CyuHat opened this issue Jan 22, 2024 · 4 comments
Closed

Cross-compilation from Linux to Windows #27

CyuHat opened this issue Jan 22, 2024 · 4 comments

Comments

@CyuHat
Copy link

CyuHat commented Jan 22, 2024

Hi!

First of all, thank you so much for this amazing project! It has clearly encouraged me to start using Nim to create simple and shareable apps (still a beginner). Combining Nim's performance with a nice frontend in HTML/CSS/JS is a fantastic idea.

I have successfully created my first app on Linux, which works well. I am still figuring out how to bind C header files and shared libraries to the executable, but that's another subject. Now, I wanted to inquire if there is support for cross-compilation from Linux to Windows using Nim. According to the Nim Compiler User Guide, I tried to compile my app into a Windows executable using the following command:

nim c -d:mingw --threads:on --mm:orc --app:gui -d:release main.nim

This command successfully creates a main.exe binary. However, when I try to run it on Windows, I encounter a black screen with the following error message (translated from French):

"This page does not work
Impossible to process this request via localhost at this time.
HTTP ERROR 500"

I have also attempted to compile the "filepicker" example, which works perfectly when compiled for Linux but encounters the same problem when compiled for Windows. Am I doing something wrong, or is cross-compilation not supported (yet)?

Thanks in advance

@Niminem
Copy link
Owner

Niminem commented Jan 23, 2024

@CyuHat Thank you for the kind words and I'm glad I could help you on the journey of learning Nim! While I don't have any experience at all with cross-compiling from Linux to Windows, the issue seems that it may be from the procedure that finds chrome. To be a little more performant, it uses a 'when' statement (which is assessed at compiletime) to figure out which OS it's compiling to and uses that path. That may be the reason. I'm not exactly sure how Nim handles this internally when cross-compiling:

Snag_63cfcdb

Another guess is that it could be a window's security issue when running the application?

Those would be my two guesses. Please let me know when you manage to figure this out

@CyuHat
Copy link
Author

CyuHat commented Jan 23, 2024

@Niminem thank your for your fast and precise answer! I will check both hypotheses and come back to you if I find something. Meanwhile I have done some tests. I think that Neel manage to find the chrome browser in windows since it open a chrome window (text in french):

localhost error

The screen is the same as if I haven't added the -d:release flag to attach the assets folder (maybe it is related). Furthermore, adding the assets folder to a Linux executable (compiled without the -d:release) solve the issue, but not for a Windows cross-compiled one. Is it maybe something relevant to check?

@CyuHat
Copy link
Author

CyuHat commented Feb 2, 2024

Hi @Niminem
Good news, there is no problem with Neel. The error was on my side. After asking my brother to test my app on his linux machine, he realized that it was looking for the assets/index.html in a path from my computer. It is because I have written the full path instead of a relative path in the startApp() macro:

# Copied from the filepicker.nim example - line 20
startApp(webDirPath = currentSourcePath.parentDir / "assets")

After replacing it with a relative path, it worked under Windows too:

startApp(webDirPath = "assets")

Then, all I need is the assets folder alongside the executable. I apologise for the false issue and thank you for your valuable time!

@Niminem
Copy link
Owner

Niminem commented Feb 6, 2024

@CyuHat That's awesome, glad to hear everything is working as intended now! Remember, if you use -d:release Neel will embed your assets inside of the executable itself so you don't have to have to worry about that. Debug builds are just for your testing!

@Niminem Niminem closed this as completed Feb 6, 2024
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