@@ -18,18 +18,37 @@ Beware that currently the compilation assumes that the code is on the host so pl
18
18
```
19
19
does not behave as expected.
20
20
By default `StaticTarget()` is the native target.
21
+
22
+ For cross-compilation of executables and shared libraries, one also needs to call `set_compiler!` with the path to a valid C compiler
23
+ for the target platform. For example, to cross-compile for aarch64 using a compiler from homebrew, one can use:
24
+ ```julia
25
+ set_compiler!(StaticTarget(parse(Platform,"aarch64-gnu-linux")), "/opt/homebrew/bin/aarch64-unknown-linux-gnu-gcc")
26
+ ```
21
27
"""
22
- struct StaticTarget
28
+ mutable struct StaticTarget
23
29
platform:: Union{Platform,Nothing}
24
30
tm:: LLVM.TargetMachine
31
+ compiler:: Union{String,Nothing}
25
32
end
26
33
27
34
clean_triple (platform:: Platform ) = arch (platform) * os_str (platform) * libc_str (platform)
28
35
StaticTarget () = StaticTarget (HostPlatform (), unsafe_string (LLVM. API. LLVMGetHostCPUName ()), unsafe_string (LLVM. API. LLVMGetHostCPUFeatures ()))
29
- StaticTarget (platform:: Platform ) = StaticTarget (platform, LLVM. TargetMachine (LLVM. Target (triple = clean_triple (platform)), clean_triple (platform)))
30
- StaticTarget (platform:: Platform , cpu:: String ) = StaticTarget (platform, LLVM. TargetMachine (LLVM. Target (triple = clean_triple (platform)), clean_triple (platform), cpu))
31
- 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))
36
+ StaticTarget (platform:: Platform ) = StaticTarget (platform, LLVM. TargetMachine (LLVM. Target (triple = clean_triple (platform)), clean_triple (platform)), nothing )
37
+ StaticTarget (platform:: Platform , cpu:: String ) = StaticTarget (platform, LLVM. TargetMachine (LLVM. Target (triple = clean_triple (platform)), clean_triple (platform), cpu), nothing )
38
+ StaticTarget (platform:: Platform , cpu:: String , features:: String ) = StaticTarget (platform, LLVM. TargetMachine (LLVM. Target (triple = clean_triple (platform)), clean_triple (platform), cpu, features), nothing )
39
+
40
+ function StaticTarget (triple:: String , cpu:: String , features:: String )
41
+ platform = tryparse (Platform, triple)
42
+ StaticTarget (platform, LLVM. TargetMachine (LLVM. Target (triple = triple), triple, cpu, features), nothing )
43
+ end
44
+
45
+ """
46
+ Set the compiler for cross compilation
47
+ ```julia
48
+ set_compiler!(StaticTarget(parse(Platform,"aarch64-gnu-linux")), "/opt/homebrew/bin/aarch64-elf-gcc")
49
+ ```
50
+ """
51
+ set_compiler! (target:: StaticTarget , compiler:: String ) = (target. compiler = compiler)
33
52
34
53
"""
35
54
```julia
0 commit comments