kassane / zig-mos-bootstrap

zig with llvm-mos backend
2 stars 0 forks source link

build `chr-rom.s`: wrong target detected #6

Closed kassane closed 4 months ago

kassane commented 4 months ago

src: https://github.com/mysterymath/nesdoug-llvm/tree/main/01_Hello Files: chr-rom.s + Alpha.chr

build.zig ```zig const std = @import("std"); pub fn build(b: *std.Build) void { const optimize = b.standardOptimizeOption(.{ .preferred_optimize_mode = .ReleaseSmall, }); const target = b.standardTargetOptions(.{ .default_target = .{ .cpu_arch = .mos, .os_tag = .freestanding, .abi = .none, }, }); const examples = &.{ "hello1", }; inline for (examples) |example| { buildExamples(b, .{ .name = example, .target = target, .optimize = optimize, .src = &.{ "nesdoug/" ++ example ++ "/" ++ example ++ ".zig", "nesdoug/" ++ example ++ "/chr-rom.s", // ERROR }, }); } } fn buildExamples(b: *std.Build, options: struct { name: []const u8, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode, src: []const []const u8, }) void { const lib = b.addStaticLibrary(.{ .name = options.name, .target = options.target, .optimize = options.optimize, }); for (options.src) |src_file| { if (std.mem.endsWith(u8, src_file, ".s")) lib.addAssemblyFile(b.path(src_file)) else if (std.mem.endsWith(u8, src_file, ".c")) lib.addCSourceFiles(.{ .files = &.{src_file}, .flags = &.{}, }) else lib.root_module.root_source_file = b.path(src_file); } const neslib = b.addModule("neslib", .{ .root_source_file = b.path("bindings/neslib.zig"), }); lib.root_module.addImport("neslib", neslib); b.installArtifact(lib); } ```
zig build --verbose-cc
install
└─ install hello1
   └─ zig build-lib hello1 Debug mos-freestanding-none 3 errors
:1:1: error: argument unused during compilation: '-fno-caret-diagnostics'
:1:1: error: argument unused during compilation: '-ffreestanding'
:1:1: error: argument unused during compilation: '--serialize-diagnostics /home/kassane/zig-bootstrap/zig-mos-examples/zig-cache/tmp/5fc5508018ec51ce-chr-rom.o.diag'
error: /home/kassane/zig-bootstrap/out/zig-mos-x86_64-linux-musl-baseline/zig clang /home/kassane/zig-bootstrap/zig-mos-examples/nesdoug/hello1/chr-rom.s --no-default-config -fno-caret-diagnostics -target mos-unknown-unknown-unknown -gdwarf-4 -gdwarf32 -ffreestanding -c -o /home/kassane/zig-bootstrap/zig-mos-examples/zig-cache/tmp/5fc5508018ec51ce-chr-rom.o --serialize-diagnostics /home/kassane/zig-bootstrap/zig-mos-examples/zig-cache/tmp/5fc5508018ec51ce-chr-rom.o.diag

error: the following command failed with 3 compilation errors:
/home/kassane/zig-bootstrap/out/zig-mos-x86_64-linux-musl-baseline/zig build-lib /home/kassane/zig-bootstrap/zig-mos-examples/nesdoug/hello1/chr-rom.s -ODebug -target mos-freestanding-none -mcpu baseline --dep neslib -Mroot=/home/kassane/zig-bootstrap/zig-mos-examples/nesdoug/hello1/hello1.zig -Mneslib=/home/kassane/zig-bootstrap/zig-mos-examples/bindings/neslib.zig --verbose-cc --cache-dir /home/kassane/zig-bootstrap/zig-mos-examples/zig-cache --global-cache-dir /home/kassane/.cache/zig --name hello1 -static --listen=-

Notes: zig not use -target mos-unknown-unknown-unknown, but use -target mos-freestanding

https://github.com/kassane/zig-mos-bootstrap/blob/50f98afe00814c2a7ca9326bb4d47ddb45800a0f/clang/cmake/caches/MOS.cmake#L22

kassane commented 4 months ago

Needs revising: https://github.com/kassane/zig-mos-bootstrap/blob/main/zig/tools/update_clang_options.zig to generate new https://github.com/kassane/zig-mos-bootstrap/blob/main/zig/src/clang_options_data.zig

kassane commented 4 months ago

zig not use -target mos-unknown-unknown-unknown, but use -target mos-freestanding

manual intervention with target flag fixed

$ /home/kassane/zig-bootstrap/out/zig-mos-x86_64-linux
-musl-baseline/zig cc /home/kassane/zig-bootstrap/zig-mos-examples/nesdoug/hello1/chr-rom.s --no-default-config -fno-caret-diagnostics -target mos-freestanding -gdwarf-4 -gdwarf32 -ffreestanding -c -o /home/kassane/zig-bootstrap/zig-mos-examples/zig-cache/tmp/d2df920ce3c8d58-chr-rom.o --serialize-diagnostics /home/kassane/zig-bootstrap/zig-mos-examples/zig-cache/tmp/d2df920ce3c8d58-chr-rom.o.diag
zig: warning: argument unused during compilation: '-ffreestanding' [-Wunused-command-line-argument]
zig: warning: argument unused during compilation: '-ffreestanding' [-Wunused-command-line-argument]
zig: warning: argument unused during compilation: '--serialize-diagnostics /home/kassane/zig-bootstrap/zig-mos-examples/zig-cache/tmp/d2df920ce3c8d58-chr-rom.o.diag' [-Wunused-command-line-argument]

$ ls /home/kassane/zig-bootstrap/zig-mos-examples/zig-cache/tmp/
total 16
drwxr-xr-x 1 kassane kassane    0 2024-05-05 16:14 117719f1fa3090a3
-rw-r--r-- 1 kassane kassane 8732 2024-05-05 16:14 d2df920ce3c8d58-chr-rom.o
-rw-r--r-- 1 kassane kassane  628 2024-05-05 16:14 d2df920ce3c8d58-chr-rom.o.diag