tshort / StaticCompiler.jl

Compiles Julia code to a standalone library (experimental)
Other
490 stars 31 forks source link

Add `compile_executable` #56

Closed brenhinkeller closed 2 years ago

brenhinkeller commented 2 years ago

This PR adds a new exported function compile_executable, which compiles a standalone native executable (in comparison to the existing compile, which compiles a .dylib/.so shared library.

The restrictions on what can be done are largely the same as those of compile, except that here the function signature can only be either nothing (i.e.foo()) or those of a normal C program's main function (i.e. foo(argc::Int, argv::Ptr{Ptr{UInt8}})

brenhinkeller commented 2 years ago

Hmm, so the Julia 1.7 failures are expected, but the standalone executables ought to be able to work on linux on 1.8.

I assumed at first that error on ubuntu + nightly must just be a clang_jll thing, but looks like it happens with gcc too.

jpsamaroo commented 2 years ago

I would try by annotating your compiled function with Base.@ccallable, so that the function gets the right LLVM calling convention and such. It might be that the function doesn't actually get exported correctly, so clang/gcc can't find it in the object file.

brenhinkeller commented 2 years ago

Hmm, it doesn't seem to like that (mac started failing too) but now github is acting up and I can't read the ci output for some reason...

tshort commented 2 years ago

I'm okay with removing Julia v1.7.x support.

@MasonProtter, any issues with this PR?

MasonProtter commented 2 years ago

I kinda want to keep Julia 1.7 support since the other stuff does work there. I've almost got my pointer-patching branch ready for a PR, and it's going to shake some stuff up anyways.

brenhinkeller commented 2 years ago

I guess that'd make life easier, since the alloca test is failing on 1.7 too (unrelated to this PR, AFAIU).

The problem on Linux should be all fixed now; it turns out it was just that the trick I was using on mac (directly specifying a custom entry with the -e compiler option) only worked because mac no longer uses _start as the proper entry to setup things before proceeding to main, so the fact that I was bypassing that didn't matter. But linux does, so I can't take that shortcut.

brenhinkeller commented 2 years ago

Oh, that's fine with me too. Mason, do you know what the other 1.7 error is then? It's not from me, as far as I can tell

brenhinkeller commented 2 years ago

Although on the other hand I hear the 1.8 feature freeze is supposed to be in a matter of days (feb 14th?)

MasonProtter commented 2 years ago

Hmm, no I don't know what's causing that error. I don't experience it locally, I'm re-running CI on the master branch here: https://github.com/tshort/StaticCompiler.jl/pull/57 to see if there is a failure.

It might be something subtle caused by your changes, but I don't see what it could be at first glance.

brenhinkeller commented 2 years ago

Ok, found the problem -- the llvmcall was being run when I thought it wasn't. I added a more minimal test for v1.7 with no llvmcall, since everything should actually work fine there other than that