Skip to content

Commit c825a4d

Browse files
Update readme to explain both compilation interfaces
1 parent 1471088 commit c825a4d

1 file changed

Lines changed: 20 additions & 3 deletions

File tree

README.md

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@
99
This is an experimental package to compile Julia code to standalone libraries. A system image is not needed.
1010

1111
## Installation and Usage
12-
12+
Installation is the same as any other registered Julia package
1313
```julia
1414
using Pkg
1515
Pkg.add("StaticCompiler")
1616
```
1717

18+
There are two main ways to use this package. The first is via the `compile` function, which can be used when you want to compile a Julia function for later use from within Julia:
1819
```julia
1920
julia> using StaticCompiler
2021

@@ -40,9 +41,25 @@ fib(::Int64) :: Int64
4041
julia> fib_compiled(10)
4142
55
4243
```
44+
See the file `tests/runtests.jl` for some examples of functions that work with `compile` (and some that don't, marked with `@test_skip`).
45+
46+
The second way to use this package is via the `compile_executable` and `compile_shlib` functions, for use when you want to compile a Julia function to a native executable or shared library for use from outside of Julia:
47+
```julia
48+
julia> using StaticCompiler, StaticTools
49+
50+
julia> hello() = println(c"Hello, world!")
51+
hello (generic function with 1 method)
4352

44-
See the file `tests/runtests.jl` for some examples of functions that work with static compilation (and some that don't,
45-
marked with `@test_skip`)
53+
julia> compile_executable(hello, (), "./")
54+
"/Users/user/hello"
55+
56+
shell> ls -alh hello
57+
-rwxrwxr-x. 1 user user 8.4K Oct 20 20:36 hello
58+
59+
shell> ./hello
60+
Hello, world!
61+
```
62+
This latter approach comes with substantially more limitations, as you cannot rely on `libjulia` (see, e.g., [StaticTools.jl](https://github.com/brenhinkeller/StaticTools.jl) for some ways to work around these limitations).
4663

4764
## Approach
4865

0 commit comments

Comments
 (0)