Skip to content

Commit 0d537cd

Browse files
committed
Add wasm test and fixup macos
1 parent 0e0f872 commit 0d537cd

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

src/StaticCompiler.jl

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ using Base:BinaryPlatforms.Platform, BinaryPlatforms.HostPlatform, BinaryPlatfor
1717
export load_function, compile_shlib, compile_executable
1818
export static_code_llvm, static_code_typed, static_llvm_module, static_code_native
1919
export @device_override, @print_and_throw
20+
export StaticTarget
2021

2122
include("interpreter.jl")
2223
include("target.jl")
@@ -465,7 +466,7 @@ end
465466
"""
466467
```julia
467468
generate_obj(f, tt, path::String = tempname(), filenamebase::String="obj";
468-
target = (),
469+
target::StaticTarget=StaticTarget(),
469470
demangle = true,
470471
strip_llvm = false,
471472
strip_asm = true,
@@ -477,7 +478,7 @@ a tuple type `tt` characterizing the types of the arguments for which the
477478
function will be compiled.
478479
479480
`target` can be used to change the output target. This is useful for compiling to WebAssembly and embedded targets.
480-
This is a named tuple with fields `triple`, `cpu`, and `features` (each of these are strings).
481+
This is a struct of the type StaticTarget()
481482
The defaults compile to the native target.
482483
483484
If `demangle` is set to `false`, compiled function names are prepended with "julia_".
@@ -487,7 +488,7 @@ If `demangle` is set to `false`, compiled function names are prepended with "jul
487488
julia> fib(n) = n <= 1 ? n : fib(n - 1) + fib(n - 2)
488489
fib (generic function with 1 method)
489490
490-
julia> path, name, table = StaticCompiler.generate_obj_for_compile(fib, Tuple{Int64}, "./test")
491+
julia> path, name, table = StaticCompiler.generate_obj(fib, Tuple{Int64}, "./test")
491492
("./test", "fib", IdDict{Any, String}())
492493
493494
shell> tree \$path
@@ -505,7 +506,7 @@ end
505506
"""
506507
```julia
507508
generate_obj(funcs::Union{Array,Tuple}, path::String = tempname(), filenamebase::String="obj";
508-
target = (),
509+
target::StaticTarget=StaticTarget(),
509510
demangle =false,
510511
strip_llvm = false,
511512
strip_asm = true,
@@ -517,7 +518,7 @@ Low level interface for compiling object code (`.o`) for an array of Tuples
517518
which will be compiled.
518519
519520
`target` can be used to change the output target. This is useful for compiling to WebAssembly and embedded targets.
520-
This is a named tuple with fields `triple`, `cpu`, and `features` (each of these are strings).
521+
This is a struct of the type StaticTarget()
521522
The defaults compile to the native target.
522523
"""
523524
function generate_obj(funcs::Union{Array,Tuple}, path::String = tempname(), filenamebase::String="obj";

src/target.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ does not behave as expected.
2020
By default `StaticTarget()` is the native target.
2121
"""
2222
struct StaticTarget
23-
platform::Platform
23+
platform::Union{Platform,Nothing}
2424
tm::LLVM.TargetMachine
2525
end
2626

@@ -29,6 +29,7 @@ StaticTarget() = StaticTarget(HostPlatform(), unsafe_string(LLVM.API.LLVMGetHost
2929
StaticTarget(platform::Platform) = StaticTarget(platform, LLVM.TargetMachine(LLVM.Target(triple = clean_triple(platform)), clean_triple(platform)))
3030
StaticTarget(platform::Platform, cpu::String) = StaticTarget(platform, LLVM.TargetMachine(LLVM.Target(triple = clean_triple(platform)), clean_triple(platform), cpu))
3131
StaticTarget(platform::Platform, cpu::String, features::String) = StaticTarget(platform, LLVM.TargetMachine(LLVM.Target(triple = clean_triple(platform)), clean_triple(platform), cpu, features))
32+
StaticTarget(triple::String, cpu::String, features::String) = StaticTarget(nothing, LLVM.TargetMachine(LLVM.Target(triple = triple), triple, cpu, features))
3233

3334
"""
3435
```julia

test/scripts/wasm.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Test that we can compile an object to wasm
2+
# WebAssemblyCompiler.jl is a better tool for this, but this exercises the cross compilation pipeline
3+
4+
using StaticCompiler
5+
using LLVM
6+
InitializeAllTargets()
7+
InitializeAllTargetInfos()
8+
InitializeAllAsmPrinters()
9+
InitializeAllAsmParsers()
10+
InitializeAllTargetMCs()
11+
12+
fib(n) = n <= 1 ? n : fib(n - 1) + fib(n - 2)
13+
14+
target=StaticTarget("wasm32","","")
15+
16+
StaticCompiler.generate_obj(fib, Tuple{Int64}, "./test", target=target)

0 commit comments

Comments
 (0)