Skip to content

Commit

Permalink
Enable command line arguments when compiling with juliac
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikekre committed Sep 3, 2024
1 parent 8d011ec commit 8d1dde8
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions juliac/runicc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,21 @@ module RunicC

using Runic: Runic

# TODO: Why do we need this shim? Wouldn't it be possible to just compile `src/Runic.jl`?
Base.@ccallable function main()::Cint
argv = String[]
return Runic.main(argv)
# Compileable main function corresponding to `int main(int argc, char** argv)`
Base.@ccallable function main(argc::Cint, argv::Ptr{Ptr{UInt8}})::Cint
# Load command line arguments. Note that the first argument is the
# executable name so we skip it.
args = Vector{String}(undef, argc - 1)
for i in 2:argc
argptr = unsafe_load(argv, i)
arg = unsafe_string(argptr)
args[i - 1] = arg
end
# Call Runic's main function
return Runic.main(args)
end

# Tell juliac about the main entrypoint
Base.Experimental.entrypoint(main, (Cint, Ptr{Ptr{UInt8}}))

end

0 comments on commit 8d1dde8

Please sign in to comment.