Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions examples/HelloApp/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name = "HelloApp"
uuid = "e15c76da-89c0-4887-b28e-6f026571847c"
version = "0.1.0"
8 changes: 8 additions & 0 deletions examples/HelloApp/src/HelloApp.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module HelloApp

function @main(args::Vector{String})
println(Core.stdout, "Hello, world!")
return 0
end

end
59 changes: 59 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -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
```
3 changes: 3 additions & 0 deletions examples/TinyLibm/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name = "TinyLibm"
uuid = "e15c76da-89c0-4887-b28e-6f026571848d"
version = "0.1.0"
10 changes: 10 additions & 0 deletions examples/TinyLibm/src/TinyLibm.jl
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions examples/gen_c_header.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
using JuliaLibWrapping

name = ARGS[1]
dest = CProject(".", name)
abi = import_abi_info(name * ".json")
wrapper(dest, abi)