-
Notifications
You must be signed in to change notification settings - Fork 29
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-platform replacement for c_compiler.lua? #516
Comments
To address #516, I'm planning to use Luarocks as a compilation backend. If we set things up the right way, we should be able to use Luarocks to compile our c files into shared libraries, in a cross-platform manner. This PR has some CFLAGS-related changes to pave the way for that. When using Luarocks to build C modules, the only way to pass CFLAGS is via the CFLAGS environment variable. So what this commit does is take the flags we were passing directly in the c_compiler.lua and passing them via CFLAGS environment variable instead. This implies in a change in behavior. By default we will no longer compile with -g and -Wall. IMO, that might actually be a good thing. The -g causes larger executables and the -Wall is not relevant to end-users. (I'm still leaving the -Wall in the ./run-tests though)
You could use zig's c compiler frontend to do the cross compilation. You can invoke I personally think using luarocks is not the solution because the onus is on the user to teach luarocks how to compile C modules on their system, for windows users this often requires a lot of extra work. |
Could you talk more about why Luarocks would be more difficult on Windows? I thought Luarocks also knew how to compile on Windows? Also, another reason we were thinking about Luarocks is that it knows where to find the Lua interpreters and header files. Even if we used zig cc, maybe we'd still need some help from Luarocks to sort out the compilation flags. |
Well given that pallene wants you to build a customized version of lua from source why not just have it be built as part of the set up? EDIT: In regards to setup on windows my main sticking point is having someone compile lua from source sourcing their own compiler toolchain, rather than specifically running the luarocks installer (which happens after you've got lua + a compiler ready). |
Sorry, I'm not sure I understand 100%. Currently we have to install the custom Lua by hand and the Pallene compiler using Luarocks. Are you suggesting that the whole thing (custom Lua + pallene compiler) should be packaged as a Luarocks rock? Or that we should ditch Luarocks and install the compiler with a custom installation script? Or something else? |
Okay so what I'm saying is: zig cc is a good compiler frontend for cross platform c compilation. It is also very easy to use on windows. I would like this project to be usable without luarocks since I – and many other prospective users I imagine – already have lua environments set up. Zig's c compiler seems like the best way to achieve cross platform c compilation without assuming luarocks has been set up by the user beforehand. |
I see. I suppose we can consider Zig if at some point we decide that we should bundle a C compiler into the project. In the mean time, one escape valve that already exists is that you can compile Pallene to C using --emit-c. This is 100% portable and then you can compile the C code however you want. |
I haven't actively used Pallene in quite some time, but continue to follow activity on the repository.
I guess a good place to start would be to make the installation process cross-platform. |
Hi Srijan, nice to hear from you again! How are you doing? :) By any chance, did you compile with |
I'm doing fine, thanks for asking! :D However
If I try to compile only 1 file however, it does work: I just posted it here as soon as I ran into the error, so I might be able to resolve this with some digging. |
Not that portable, currently luacore.h contains non C code, (gnu awk script), so not only is it nonportable, its only usable on gnu systems. |
Is that AWK script using something that only works on GNU? The plan was to work with any AWK. In any case, the AWK script is only used to generate luacore.h. If we distribute that in the tarball then the end user wouldn't need AWK. To be honest, when it comes to portability I'm more worried about the C99 code we're using here and there. |
Yes, BEGINFILE is gawk specific, it can probably be replaced by a NR==1 {}. Also, now I see why there was awk code in my luacore.h, it probably emitted itself because the awk code was incorrect? |
Interesting. Let's move the AWK discussion to pallene-lang/lua-internals#1 |
If we ever want to make Pallene more cross-platform, the c_compiler.lua part will be one of the sticking points. Currently, windows support is completely missing and the macOS support is not actively tested. (None of the devs still use macOS and it is not tested in our continuous integration). This is all very unfortunate, and it is a problem area that is out of our area of expertise. We should consider delegating this functionality to someone else. Perhaps Luarocks? It knows how to compile C code in a cross-platform way...
The text was updated successfully, but these errors were encountered: