@@ -18,18 +18,37 @@ Beware that currently the compilation assumes that the code is on the host so pl
1818```
1919does not behave as expected.
2020By 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+ ```
2127"""
22- struct StaticTarget
28+ mutable struct StaticTarget
2329 platform:: Union{Platform,Nothing}
2430 tm:: LLVM.TargetMachine
31+ compiler:: Union{String,Nothing}
2532end
2633
2734clean_triple (platform:: Platform ) = arch (platform) * os_str (platform) * libc_str (platform)
2835StaticTarget () = 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)
3352
3453"""
3554```julia
0 commit comments