aardappel / lobster

The Lobster Programming Language
http://strlen.com/lobster
2.25k stars 119 forks source link

Help with compiling to binaries #165

Closed eboatwright closed 2 years ago

eboatwright commented 2 years ago

So, I'm trying to compile some of the example projects to Linux and Windows (WebAssembly would be nice too, but I'm starting simple(-ish)). So, I look around the website and find the compiling page. I try the --pak, and it makes this lpak file. What is that? So, then I tried the --cpp option, and it makes the cpp file. But, I try to compile it (with gcc compiled_lobster.cpp) and I get this error:

src/compiled_lobster.cpp:1:10: fatal error: lobster/stdafx.h: No such file or directory
    1 | #include "lobster/stdafx.h"
      |          ^~~~~~~~~~~~~~~~~~

So, I copy the file into that folder, and I get another error asking for another file, and another, and another, and after a while it starts asking for files that don't even exist, for files inside folders, that also need that same file in an infinite recursion directory spiral into the infinity of nothingness. Sorry, I got on a little tangent, but you get the point

Also, I'm on Pop! OS 21.04 an Ubuntu based distro.

eboatwright commented 2 years ago

P.S. I know I'm probably using the wrong C++ compiler or something, but I don't know much about C++ so :/

aardappel commented 2 years ago

If you just want to run stuff, you shouldn't need either option, since Lobster contains a JIT, just run programs like on https://aardappel.github.io/lobster/getting_started.html: bin/lobster samples/pythtree.lobster.

--cpp is for making a binary with the c++ you should only need if you're shipping to customers. The error you're getting is because you can't compile that file by itself, it needs all of the rest of Lobster compiled into it, so you need to build it thru CMake, see instuctions on https://aardappel.github.io/lobster/implementation.html, in particular under Compiling Lobster code to C++.

eboatwright commented 2 years ago

Yeah, I tried to read those docs, but for some reason my brain skipped over the part where it said to be in the dev directory :( sorry, So I got compiling to Linux working, how would I go about cross compiling to Windows?

aardappel commented 2 years ago

I've never cross-compiled to Windows, so I have no idea. I use an actual Windows to build (with Visual Studio).

Lobster build depends on graphics/sound/opengl and what not, so would need Windows system headers etc, so I bet a cross-compile is not that easy.

eboatwright commented 2 years ago

oh, ok. Thank you for your time, and help :)

JobLeonard commented 2 years ago

Maybe using the Zig toolchain could help out? I've heard multiple people say that they don't even write in Zig itself but still use it to cross-compile stuff because it simplifies a lot of the headaches involved:

https://zig.news/kristoff/cross-compile-a-c-c-project-with-zig-3599

eboatwright commented 2 years ago

Hm, I'll look into that! I don't really like the Zig programming language, but I might be able to write a few build scripts with it :) Thanks!

aardappel commented 2 years ago

@JobLeonard yeah the zig toolchain is really cool.. had thoughts at some point to include it in Lobster such that the Lobster compiler can uniformly build on all platforms in --cpp mode.

michaeldesu commented 1 year ago

@aardappel I started to try Lobster (thanks for making & maintaining it) - regarding the pak file, I initially was misunderstood about the compiler (hoping for a self-contained exe directly) until I read about the pak file and how to run it with lobster.exe, or generate the cpp file to compile separately. I believe other languages (like Nim that can emit to C or similar) offer compilation as an automated next step to produce the self-contained exe directly - it would be nice for Lobster to do the same eventually, however it may not be a goal.

So I had a suggestion for the people who are ok with the pak file (or not requiring to compile the cpp separately): offer a bundling option, i.e. embed the pak file (and other assets) with the lobster exe, so the user is given a self-contained exe as a result, which loads & runs the embedded pak file.

aardappel commented 1 year ago

@michaeldesu Self-contained exe generation is tricky in our case, since that requires including a C++ compiler (hence the discussion about Zig above). Lobster has a fairly large runtime and engine written in C++ that needs to be compiled/linked into every Lobster executable.

While including a C++ toolchain would probably be welcomed by Lobster Windows users, people on Linux would typically demand to use their chosen system toolchain.

As for the pak file, the bytecode that is typically inside that pak file already gets emitted into the exe. But the pak file contains also the data files, in the very least if the program is graphical, it will be loading data/shaders/default.materials and maybe other things. Those could be packed into the exe, but to this day C++ doesn't have a portable way to do that, you'd end up generating source code for it, and since Lobster is meant for games and games can come with large amounts of data that doesn't sound so great.

I understand the desire for a single exe, but thought in most cases having a single extra data file would not be a big deal.