diff options
author | Johannes Stoelp <johannes.stoelp@gmail.com> | 2024-07-05 00:20:22 +0200 |
---|---|---|
committer | Johannes Stoelp <johannes.stoelp@gmail.com> | 2024-07-05 00:20:22 +0200 |
commit | b07a942993efe44e5dbdff8088b0ed87c79fc433 (patch) | |
tree | d526b4fef64627162f75ef72677cac1987625fa1 /example-cross-compile | |
parent | 898b1c827293c8ae87642be75703c3a0eb99bf22 (diff) | |
download | zig-playground-b07a942993efe44e5dbdff8088b0ed87c79fc433.tar.gz zig-playground-b07a942993efe44e5dbdff8088b0ed87c79fc433.zip |
cross: mini zig cross compile
Diffstat (limited to 'example-cross-compile')
-rw-r--r-- | example-cross-compile/.gitignore | 5 | ||||
-rw-r--r-- | example-cross-compile/Makefile | 17 | ||||
-rw-r--r-- | example-cross-compile/lin.zig | 5 | ||||
-rw-r--r-- | example-cross-compile/win.zig | 8 |
4 files changed, 35 insertions, 0 deletions
diff --git a/example-cross-compile/.gitignore b/example-cross-compile/.gitignore new file mode 100644 index 0000000..3fd3ba4 --- /dev/null +++ b/example-cross-compile/.gitignore @@ -0,0 +1,5 @@ +*.exe +*.exe.obj +*.pdb +*.elf +*.elf.o diff --git a/example-cross-compile/Makefile b/example-cross-compile/Makefile new file mode 100644 index 0000000..72f611d --- /dev/null +++ b/example-cross-compile/Makefile @@ -0,0 +1,17 @@ +riscv64: lin-riscv64 +aarch64: lin-aarch64 +mips64el: lin-mips64el + +lin-%: + zig build-exe lin.zig -target $*-linux-musl --name $*.elf + file $*.elf + qemu-$* $*.elf + +win: + zig build-exe win.zig -target x86_64-windows -lc + file win.exe + wine win.exe + +clean: + git clean -fdx . + diff --git a/example-cross-compile/lin.zig b/example-cross-compile/lin.zig new file mode 100644 index 0000000..9eb2ee8 --- /dev/null +++ b/example-cross-compile/lin.zig @@ -0,0 +1,5 @@ +const print = @import("std").debug.print; + +pub fn main() void { + print("hello from zig main()\n", .{}); +} diff --git a/example-cross-compile/win.zig b/example-cross-compile/win.zig new file mode 100644 index 0000000..200fa34 --- /dev/null +++ b/example-cross-compile/win.zig @@ -0,0 +1,8 @@ +const winh = @cImport({ + @cInclude("windows.h"); + @cInclude("winuser.h"); +}); + +pub fn main() void { + _ = winh.MessageBoxA(null, "world", "hello", 0); +} |