diff --git a/examples/HelloApp/Project.toml b/examples/HelloApp/Project.toml new file mode 100644 index 0000000..04f3924 --- /dev/null +++ b/examples/HelloApp/Project.toml @@ -0,0 +1,3 @@ +name = "HelloApp" +uuid = "e15c76da-89c0-4887-b28e-6f026571847c" +version = "0.1.0" diff --git a/examples/HelloApp/src/HelloApp.jl b/examples/HelloApp/src/HelloApp.jl new file mode 100644 index 0000000..fcbf8d5 --- /dev/null +++ b/examples/HelloApp/src/HelloApp.jl @@ -0,0 +1,8 @@ +module HelloApp + +function @main(args::Vector{String}) + println(Core.stdout, "Hello, world!") + return 0 +end + +end diff --git a/examples/README.md b/examples/README.md new file mode 100644 index 0000000..2048f41 --- /dev/null +++ b/examples/README.md @@ -0,0 +1,59 @@ +## JuliaC examples + +This directory contains simple examples of how to use the core JuliaC features of +generating executables and shared libraries, together with bundling and/or trimming. + +Follow these steps to try out the examples: + +### Install the juliac app + +``` +julia +]app add JuliaC +``` + +### Generate an executable with trimming + +The following commands assume this `examples` directory is your current directory. + +``` +~/.julia/bin/juliac HelloApp --output-exe hello --trim + +./hello +``` + +### Generate a self-contained bundle for an executable + +``` +~/.julia/bin/juliac HelloApp --output-exe hello --trim --bundle hellodir + +./hellodir/bin/hello +``` + +### Generate a shared library + +``` +~/.julia/bin/juliac TinyLibm --output-lib tinylibm --compile-ccallable --trim + +objdump -T tinylibm.so | less +``` + +With symbol privatization, allowing the library to be loaded within a julia process: + +``` +~/.julia/bin/juliac TinyLibm --output-lib tinylibm --compile-ccallable --trim --bundle tinylibm --privatize + +julia + +ccall((:sin, "tinylibm/lib/tinylibm.so"), Float64, (Float64,), 2.1) +``` + +### Generate a C header file + +``` +~/.julia/bin/juliac TinyLibm --output-lib tinylibm --compile-ccallable --trim --bundle tinylibm --privatize --export-abi tinylibm.json + +julia gen_c_header.jl tinylibm + +cat tinylibm.h +``` diff --git a/examples/TinyLibm/Project.toml b/examples/TinyLibm/Project.toml new file mode 100644 index 0000000..eb9c8c1 --- /dev/null +++ b/examples/TinyLibm/Project.toml @@ -0,0 +1,3 @@ +name = "TinyLibm" +uuid = "e15c76da-89c0-4887-b28e-6f026571848d" +version = "0.1.0" diff --git a/examples/TinyLibm/src/TinyLibm.jl b/examples/TinyLibm/src/TinyLibm.jl new file mode 100644 index 0000000..a20a185 --- /dev/null +++ b/examples/TinyLibm/src/TinyLibm.jl @@ -0,0 +1,10 @@ +module TinyLibm + +import Base: @ccallable + +@ccallable sin(x::Float64)::Float64 = Base.sin(x) +@ccallable sinf(x::Float32)::Float32 = Base.sin(x) +@ccallable cos(x::Float64)::Float64 = Base.cos(x) +@ccallable cosf(x::Float32)::Float32 = Base.cos(x) + +end diff --git a/examples/gen_c_header.jl b/examples/gen_c_header.jl new file mode 100644 index 0000000..04036d4 --- /dev/null +++ b/examples/gen_c_header.jl @@ -0,0 +1,6 @@ +using JuliaLibWrapping + +name = ARGS[1] +dest = CProject(".", name) +abi = import_abi_info(name * ".json") +wrapper(dest, abi)