Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

macOS libc headers: add POSIX headers #7035

Merged
merged 12 commits into from
Nov 9, 2020
Merged

macOS libc headers: add POSIX headers #7035

merged 12 commits into from
Nov 9, 2020

Conversation

andrewrk
Copy link
Member

@andrewrk andrewrk commented Nov 9, 2020

@andrewrk
Copy link
Member Author

andrewrk commented Nov 9, 2020

Rebased on top of #7034: macOS: depend on bundled headers even for native

This is an alternate fix for #6773. Reverts 872bc78.

cc @prime31 - I'm interested in making sure this does not re-introduce the regression from #6773.

these new files are generated by recursively including:

sysexits.h
mach/mach.h
sys/attr.h
sys/mount.h
crt_externs.h
execinfo.h

all of which are depended on by LLVM libraries.
@prime31
Copy link
Contributor

prime31 commented Nov 9, 2020

cc @prime31 - I'm interested in making sure this does not re-introduce the regression from #6773.

I'll give this a test run in the morning.

Copy link
Member

@kubkon kubkon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! I'd suggest we wait with merging until @prime31 confirms it works for him :-)

@prime31
Copy link
Contributor

prime31 commented Nov 9, 2020

Looks great! I'd suggest we wait with merging until @prime31 confirms it works for him :-)

On it right now. Will report back shortly.

@prime31
Copy link
Contributor

prime31 commented Nov 9, 2020

Do I have to pass any new flags through to the LibExeObjStep? I tried just doing zig build on two medium sized projects with mixed zig + c + cpp and both failed.

lld: error: Unable to find framework for -framework Foundation
attempt to unwrap error: LLDReportedFailure
/Users/mikedesaro/Desktop/zig/src/main.zig:0:23: 0x104e78139 in main.mainArgs (zig1)
/Users/mikedesaro/Desktop/zig/lib/std/heap.zig:78:41: 0x104e74389 in std.heap.cResize (zig1)
        const full_len = malloc_size(buf.ptr);
                                        ^
/Users/mikedesaro/Desktop/zig/lib/std/heap.zig:78:41: 0x104e74389 in std.heap.cResize (zig1)
        const full_len = malloc_size(buf.ptr);
                                        ^
/Users/mikedesaro/Desktop/zig/lib/std/heap.zig:78:41: 0x104e74389 in std.heap.cResize (zig1)
        const full_len = malloc_size(buf.ptr);
                                        ^
/Users/mikedesaro/Desktop/zig/lib/std/heap.zig:78:41: 0x104e74389 in std.heap.cResize (zig1)
        const full_len = malloc_size(buf.ptr);
                                        ^
/Users/mikedesaro/Desktop/zig/lib/std/heap.zig:78:41: 0x104e74389 in std.heap.cResize (zig1)
        const full_len = malloc_size(buf.ptr);
                                        ^
/Users/mikedesaro/Desktop/zig/lib/std/heap.zig:78:41: 0x104e74389 in std.heap.cResize (zig1)
        const full_len = malloc_size(buf.ptr);
                                        ^
/Users/mikedesaro/Desktop/zig/lib/std/heap.zig:78:41: 0x104e74389 in std.heap.cResize (zig1)
        const full_len = malloc_size(buf.ptr);
                                        ^
/Users/mikedesaro/Desktop/zig/lib/std/heap.zig:78:41: 0x104e74389 in std.heap.cResize (zig1)
        const full_len = malloc_size(buf.ptr);
                                        ^
/Users/mikedesaro/Desktop/zig/lib/std/heap.zig:78:41: 0x104e74389 in std.heap.cResize (zig1)
        const full_len = malloc_size(buf.ptr);
                                        ^
/Users/mikedesaro/Desktop/zig/lib/std/io/reader.zig:188:50: 0x10509eb82 in std.io.reader.Reader(*std.io.fixed_buffer_stream.FixedBufferStream([]const u8),std.io.fixed_buffer_stream.ReadError,std.io.fixed_buffer_stream.FixedBufferStream([]const u8).read).readByteSigned (zig1)
            return @bitCast(i8, try self.readByte());
                                                 ^
/Users/mikedesaro/Desktop/zig/lib/std/heap.zig:78:41: 0x104e74389 in std.heap.cResize (zig1)
        const full_len = malloc_size(buf.ptr);
                                        ^
/Users/mikedesaro/Desktop/zig/src/link/MachO.zig:56:56: 0x105017812 in link.MachO.LoadCommand.write (zig1)
            .DyldInfo => |cmd| writeGeneric(cmd, file, offset),
                                                       ^
/Users/mikedesaro/Desktop/zig/src/link/MachO.zig:52:44: 0x105017589 in link.MachO.LoadCommand.write (zig1)
            .Segment => |cmd| writeGeneric(cmd, file, offset),
                                           ^
/Users/mikedesaro/Desktop/zig/src/link/MachO.zig:51:16: 0x10501750b in link.MachO.LoadCommand.write (zig1)
        return switch (self) {
               ^
/Users/mikedesaro/Desktop/zig/lib/std/base64.zig:53:83: 0x104fe744f in std.base64.Base64Encoder.encode (zig1)
            dest[out_index] = encoder.alphabet_chars[((source[i + 1] & 0xf) << 2) | ((source[i + 2] & 0xc0) >> 6)];
                                                                                  ^
/Users/mikedesaro/Desktop/zig/lib/std/fmt.zig:0:21: 0x10518344c in std.fmt.format (zig1)
/Users/mikedesaro/Desktop/zig/lib/std/mem.zig:2196:40: 0x105017ba9 in std.mem.sliceAsBytes (zig1)
    return @ptrCast(cast_target, slice)[0 .. slice.len * @sizeOf(meta.Elem(Slice))];
                                       ^
/Users/mikedesaro/Desktop/zig/lib/std/fmt.zig:195:21: 0x104f97109 in std.fmt.format (zig1)
                    try formatType(
                    ^
/Users/mikedesaro/Desktop/zig/lib/std/heap.zig:78:41: 0x104e74389 in std.heap.cResize (zig1)
        const full_len = malloc_size(buf.ptr);
                                        ^
/Users/mikedesaro/Desktop/zig/lib/std/heap.zig:78:41: 0x104e74389 in std.heap.cResize (zig1)
        const full_len = malloc_size(buf.ptr);
                                        ^
/Users/mikedesaro/Desktop/zig/lib/std/heap.zig:78:41: 0x104e74389 in std.heap.cResize (zig1)
        const full_len = malloc_size(buf.ptr);
                                        ^
/Users/mikedesaro/Desktop/zig/lib/std/heap.zig:78:41: 0x104e74389 in std.heap.cResize (zig1)
        const full_len = malloc_size(buf.ptr);
                                        ^
/Users/mikedesaro/Desktop/zig/lib/std/io/reader.zig:188:50: 0x10509eb82 in std.io.reader.Reader(*std.io.fixed_buffer_stream.FixedBufferStream([]const u8),std.io.fixed_buffer_stream.ReadError,std.io.fixed_buffer_stream.FixedBufferStream([]const u8).read).readByteSigned (zig1)
            return @bitCast(i8, try self.readByte());
                                                 ^
/Users/mikedesaro/Desktop/zig/lib/std/heap.zig:78:41: 0x104e74389 in std.heap.cResize (zig1)
        const full_len = malloc_size(buf.ptr);
                                        ^
/Users/mikedesaro/Desktop/zig/lib/std/io/reader.zig:188:50: 0x10509eb82 in std.io.reader.Reader(*std.io.fixed_buffer_stream.FixedBufferStream([]const u8),std.io.fixed_buffer_stream.ReadError,std.io.fixed_buffer_stream.FixedBufferStream([]const u8).read).readByteSigned (zig1)
            return @bitCast(i8, try self.readByte());
                                                 ^
/Users/mikedesaro/Desktop/zig/src/link/MachO.zig:0:17: 0x104fff2e1 in link.MachO.linkWithLLD (zig1)
/Users/mikedesaro/Desktop/zig/lib/std/fs.zig:1832:24: 0x104fe43d6 in std.fs.Dir.copyFile (zig1)
            const st = try in_file.stat();
                       ^
/Users/mikedesaro/Desktop/zig/src/Compilation.zig:1286:29: 0x104f9f074 in Compilation.performAllTheWork (zig1)
                    decl.src(),
                            ^
/Users/mikedesaro/Desktop/zig/lib/std/fmt.zig:196:29: 0x104f97b42 in std.fmt.format (zig1)
                        args[arg_to_print],
                            ^
/Users/mikedesaro/Desktop/zig/src/main.zig:1888:39: 0x104f4ddf5 in main.cmdTranslateC (zig1)
    defer if (enable_cache) man.deinit();
                                      ^
/Users/mikedesaro/Desktop/zig/src/main.zig:1704:17: 0x104ea005c in main.buildOutputType (zig1)
                .print = comp.bin_file.options.emit.?.directory.path orelse ".",
                ^
???:?:?: 0x108bff418 in ___zig_fail_unwrap (???)
/Users/mikedesaro/Desktop/zig/src/stage1.zig:28:0: 0x104e77c80 in main (zig1)
pub export fn main(argc: c_int, argv: [*][*:0]u8) c_int {

???:?:?: 0x7fff6d838cc8 in ??? (???)
???:?:?: 0x76 in ??? (???)
tilemap...The following command terminated unexpectedly:
/Users/mikedesaro/Desktop/zig/build/zig build-exe /Users/mikedesaro/Desktop/zig-upaya/examples/tilemap/main.zig --library c --library c++ -cflags -std=c99 -ObjC -fobjc-arc -- /Users/mikedesaro/Desktop/zig-upaya/src/deps/sokol/compile_sokol.c -cflags -std=c99 -- /Users/mikedesaro/Desktop/zig-upaya/src/deps/stb/src/stb_impl.c --library c++ -cflags -Wno-return-type-c-linkage -- /Users/mikedesaro/Desktop/zig-upaya/src/deps/imgui/cimgui/imgui/imgui.cpp -cflags -Wno-return-type-c-linkage -- /Users/mikedesaro/Desktop/zig-upaya/src/deps/imgui/cimgui/imgui/imgui_demo.cpp -cflags -Wno-return-type-c-linkage -- /Users/mikedesaro/Desktop/zig-upaya/src/deps/imgui/cimgui/imgui/imgui_draw.cpp -cflags -Wno-return-type-c-linkage -- /Users/mikedesaro/Desktop/zig-upaya/src/deps/imgui/cimgui/imgui/imgui_widgets.cpp -cflags -Wno-return-type-c-linkage -- /Users/mikedesaro/Desktop/zig-upaya/src/deps/imgui/cimgui/cimgui.cpp -cflags -Wno-return-type-c-linkage -- /Users/mikedesaro/Desktop/zig-upaya/src/deps/imgui/temporary_hacks.cpp -cflags -D_CRT_SECURE_NO_WARNINGS -D_CRT_SECURE_NO_DEPRECATE -- /Users/mikedesaro/Desktop/zig-upaya/src/deps/filebrowser/src/tinyfiledialogs.c --cache-dir /Users/mikedesaro/Desktop/zig-upaya/zig-cache --name tilemap --pkg-begin upaya /Users/mikedesaro/Desktop/zig-upaya/src/upaya.zig --pkg-begin stb /Users/mikedesaro/Desktop/zig-upaya/src/deps/stb/stb.zig --pkg-end --pkg-begin filebrowser /Users/mikedesaro/Desktop/zig-upaya/src/deps/filebrowser/filebrowser.zig --pkg-end --pkg-begin sokol /Users/mikedesaro/Desktop/zig-upaya/src/deps/sokol/sokol.zig --pkg-end --pkg-begin imgui /Users/mikedesaro/Desktop/zig-upaya/src/deps/imgui/imgui.zig --pkg-end --pkg-end --pkg-begin sokol /Users/mikedesaro/Desktop/zig-upaya/src/deps/sokol/sokol.zig --pkg-end --pkg-begin stb /Users/mikedesaro/Desktop/zig-upaya/src/deps/stb/stb.zig --pkg-end --pkg-begin imgui /Users/mikedesaro/Desktop/zig-upaya/src/deps/imgui/imgui.zig --pkg-end --pkg-begin filebrowser /Users/mikedesaro/Desktop/zig-upaya/src/deps/filebrowser/filebrowser.zig --pkg-end -I /Users/mikedesaro/Desktop/zig-upaya/src/deps/sokol -I /Users/mikedesaro/Desktop/zig-upaya/src/deps/stb/src -I /Users/mikedesaro/Desktop/zig-upaya/src/deps/imgui -I /Users/mikedesaro/Desktop/zig-upaya/src/deps/imgui/cimgui -F /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks -F /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks -framework Foundation -framework QuartzCore -framework Metal -framework MetalKit -framework OpenGL -framework Cocoa -framework Quartz -framework Audiotoolbox -framework CoreAudio --enable-cache 
error: the following build command failed with exit code 6:
/Users/mikedesaro/Desktop/zig-upaya/zig-cache/o/bdb22acf36c14c874de860e923887515/build /Users/mikedesaro/Desktop/zig/build/zig /Users/mikedesaro/Desktop/zig-upaya /Users/mikedesaro/Desktop/zig-upaya/zig-cache

Second:

error(compilation): clang failed with stderr: In file included from /Users/mikedesaro/Desktop/zig-aya/aya/deps/fna/FNA3D/src/FNA3D_Driver_Metal.c:29:
/Users/mikedesaro/Desktop/zig-aya/aya/deps/fna/FNA3D/src/FNA3D_Driver_Metal.h:34:10: fatal error: 'objc/message.h' file not found

error(compilation): clang failed with stderr: /Users/mikedesaro/Desktop/zig-aya/aya/deps/fna/FNA3D/src/FNA3D_Image.c:89:1: error: static declaration of 'SDL_SIMDRealloc' follows non-static declaration
/usr/local/include/SDL2/SDL_cpuinfo.h:274:32: note: previous declaration is here

Compile C Objects [11/17] mojoshader_opengl.c... error(compilation): clang failed with stderr: /Users/mikedesaro/Desktop/zig-aya/aya/deps/fna/FNA3D/MojoShader/mojoshader_metal.c:13:10: fatal error: 'objc/message.h' file not found

/Users/mikedesaro/Desktop/zig-aya/aya/deps/fna/FNA3D/src/FNA3D_Driver_Metal.c:1:1: error: unable to build C object: clang exited with code 1
/Users/mikedesaro/Desktop/zig-aya/aya/deps/fna/FNA3D/src/FNA3D_Image.c:1:1: error: unable to build C object: clang exited with code 1
/Users/mikedesaro/Desktop/zig-aya/aya/deps/fna/FNA3D/MojoShader/mojoshader_metal.c:1:1: error: unable to build C object: clang exited with code 1
attempt to unwrap error: FileNotFound
/Users/mikedesaro/Desktop/zig/src/main.zig:1704:17: 0x109ee405c in main.buildOutputType (zig1)
                .print = comp.bin_file.options.emit.?.directory.path orelse ".",
                ^
/Users/mikedesaro/Desktop/zig/src/main.zig:0:23: 0x109ebc139 in main.mainArgs (zig1)
/Users/mikedesaro/Desktop/zig/lib/std/io/reader.zig:188:50: 0x10a0e2b82 in std.io.reader.Reader(*std.io.fixed_buffer_stream.FixedBufferStream([]const u8),std.io.fixed_buffer_stream.ReadError,std.io.fixed_buffer_stream.FixedBufferStream([]const u8).read).readByteSigned (zig1)
            return @bitCast(i8, try self.readByte());
                                                 ^
/Users/mikedesaro/Desktop/zig/lib/std/heap.zig:78:41: 0x109eb8389 in std.heap.cResize (zig1)
        const full_len = malloc_size(buf.ptr);
                                        ^
/Users/mikedesaro/Desktop/zig/lib/std/io/reader.zig:188:50: 0x10a0e2b82 in std.io.reader.Reader(*std.io.fixed_buffer_stream.FixedBufferStream([]const u8),std.io.fixed_buffer_stream.ReadError,std.io.fixed_buffer_stream.FixedBufferStream([]const u8).read).readByteSigned (zig1)
            return @bitCast(i8, try self.readByte());
                                                 ^
/Users/mikedesaro/Desktop/zig/lib/std/heap.zig:78:41: 0x109eb8389 in std.heap.cResize (zig1)
        const full_len = malloc_size(buf.ptr);
                                        ^
/Users/mikedesaro/Desktop/zig/lib/std/heap.zig:78:41: 0x109eb8389 in std.heap.cResize (zig1)
        const full_len = malloc_size(buf.ptr);
                                        ^
/Users/mikedesaro/Desktop/zig/lib/std/heap.zig:78:41: 0x109eb8389 in std.heap.cResize (zig1)
        const full_len = malloc_size(buf.ptr);
                                        ^
/Users/mikedesaro/Desktop/zig/lib/std/heap.zig:78:41: 0x109eb8389 in std.heap.cResize (zig1)
        const full_len = malloc_size(buf.ptr);
                                        ^
/Users/mikedesaro/Desktop/zig/lib/std/heap.zig:78:41: 0x109eb8389 in std.heap.cResize (zig1)
        const full_len = malloc_size(buf.ptr);
                                        ^
/Users/mikedesaro/Desktop/zig/lib/std/heap.zig:78:41: 0x109eb8389 in std.heap.cResize (zig1)
        const full_len = malloc_size(buf.ptr);
                                        ^
/Users/mikedesaro/Desktop/zig/lib/std/heap.zig:78:41: 0x109eb8389 in std.heap.cResize (zig1)
        const full_len = malloc_size(buf.ptr);
                                        ^
/Users/mikedesaro/Desktop/zig/lib/std/heap.zig:78:41: 0x109eb8389 in std.heap.cResize (zig1)
        const full_len = malloc_size(buf.ptr);
                                        ^
/Users/mikedesaro/Desktop/zig/lib/std/heap.zig:78:41: 0x109eb8389 in std.heap.cResize (zig1)
        const full_len = malloc_size(buf.ptr);
                                        ^
/Users/mikedesaro/Desktop/zig/lib/std/heap.zig:78:41: 0x109eb8389 in std.heap.cResize (zig1)
        const full_len = malloc_size(buf.ptr);
                                        ^
/Users/mikedesaro/Desktop/zig/lib/std/heap.zig:78:41: 0x109eb8389 in std.heap.cResize (zig1)
        const full_len = malloc_size(buf.ptr);
                                        ^
/Users/mikedesaro/Desktop/zig/lib/std/heap.zig:78:41: 0x109eb8389 in std.heap.cResize (zig1)
        const full_len = malloc_size(buf.ptr);
                                        ^
/Users/mikedesaro/Desktop/zig/lib/std/heap.zig:78:41: 0x109eb8389 in std.heap.cResize (zig1)
        const full_len = malloc_size(buf.ptr);
                                        ^
/Users/mikedesaro/Desktop/zig/lib/std/heap.zig:78:41: 0x109eb8389 in std.heap.cResize (zig1)
        const full_len = malloc_size(buf.ptr);
                                        ^
/Users/mikedesaro/Desktop/zig/lib/std/heap.zig:78:41: 0x109eb8389 in std.heap.cResize (zig1)
        const full_len = malloc_size(buf.ptr);
                                        ^
/Users/mikedesaro/Desktop/zig/lib/std/heap.zig:78:41: 0x109eb8389 in std.heap.cResize (zig1)
        const full_len = malloc_size(buf.ptr);
                                        ^
/Users/mikedesaro/Desktop/zig/lib/std/io/reader.zig:188:50: 0x10a0e2b82 in std.io.reader.Reader(*std.io.fixed_buffer_stream.FixedBufferStream([]const u8),std.io.fixed_buffer_stream.ReadError,std.io.fixed_buffer_stream.FixedBufferStream([]const u8).read).readByteSigned (zig1)
            return @bitCast(i8, try self.readByte());
                                                 ^
/Users/mikedesaro/Desktop/zig/lib/std/hash/wyhash.zig:126:52: 0x10a0a3b3e in std.hash.wyhash.WyhashStateless.hash (zig1)
        const aligned_len = input.len - (input.len % 32);
                                                   ^
/Users/mikedesaro/Desktop/zig/lib/std/fs.zig:867:35: 0x109f43fbe in std.fs.Dir.createFileZ (zig1)
            (if (flags.exclusive) @as(u32, os.O_EXCL) else 0);
                                  ^
/Users/mikedesaro/Desktop/zig/lib/std/crypto/siphash.zig:220:65: 0x109f3fd6b in std.crypto.siphash.SipHash(u128,1,3).final (zig1)
            mem.writeIntLittle(T, out, self.state.final(self.buf[0..self.buf_len]));
                                                                ^
/Users/mikedesaro/Desktop/zig/src/Cache.zig:632:21: 0x109f41c7a in Cache.isProblematicTimestamp (zig1)
    var wall_nsec = @intCast(i64, @mod(wall_clock, std.time.ns_per_s));
                    ^
/Users/mikedesaro/Desktop/zig/src/Cache.zig:334:17: 0x109f3a6e7 in Cache.Manifest.hit (zig1)
                if (isProblematicTimestamp(cache_hash_file.stat.mtime)) {
                ^
/Users/mikedesaro/Desktop/zig/src/link/Elf.zig:0:43: 0x10a03f188 in link.Elf.flushModule (zig1)
/Users/mikedesaro/Desktop/zig/lib/std/fs.zig:1832:24: 0x10a0283d6 in std.fs.Dir.copyFile (zig1)
            const st = try in_file.stat();
                       ^
/Users/mikedesaro/Desktop/zig/src/Compilation.zig:1286:29: 0x109fe3074 in Compilation.performAllTheWork (zig1)
                    decl.src(),
                            ^
/Users/mikedesaro/Desktop/zig/lib/std/fmt.zig:196:29: 0x109fdbb42 in std.fmt.format (zig1)
                        args[arg_to_print],
                            ^
/Users/mikedesaro/Desktop/zig/src/main.zig:1888:39: 0x109f91df5 in main.cmdTranslateC (zig1)
    defer if (enable_cache) man.deinit();
                                      ^
???:?:?: 0x10dc43418 in ___zig_fail_unwrap (???)
/Users/mikedesaro/Desktop/zig/src/stage1.zig:28:0: 0x109ebbc80 in main (zig1)
pub export fn main(argc: c_int, argv: [*][*:0]u8) c_int {

???:?:?: 0x7fff6d838cc8 in ??? (???)
???:?:?: 0x4e in ??? (???)
run...The following command terminated unexpectedly:
/Users/mikedesaro/Desktop/zig/build/zig build-exe /Users/mikedesaro/Desktop/zig-aya/examples/tilemap.zig /libFNA3D.a --library c --library SDL2 /Users/mikedesaro/Desktop/zig-aya/zig-cache/o/14350c2daa4f318ecb950fda7546dc45/libimgui.a --library c++ /Users/mikedesaro/Desktop/zig-aya/zig-cache/o/eaf3d6c990e9f2eea7f5716d20559821/libFontStash.a --pkg-begin build_options /Users/mikedesaro/Desktop/zig-aya/zig-cache/run_build_options.zig --pkg-end --cache-dir /Users/mikedesaro/Desktop/zig-aya/zig-cache --name run --pkg-begin aya /Users/mikedesaro/Desktop/zig-aya/aya/src/aya.zig --pkg-begin sdl /Users/mikedesaro/Desktop/zig-aya/aya/deps/sdl/sdl.zig --pkg-end --pkg-begin fna /Users/mikedesaro/Desktop/zig-aya/aya/deps/fna/fna.zig --pkg-begin sdl /Users/mikedesaro/Desktop/zig-aya/aya/deps/sdl/sdl.zig --pkg-end --pkg-end --pkg-begin imgui /Users/mikedesaro/Desktop/zig-aya/aya/deps/imgui/imgui.zig --pkg-end --pkg-begin fontstash /Users/mikedesaro/Desktop/zig-aya/aya/deps/fontstash/fontstash.zig --pkg-end --pkg-end --pkg-begin sdl /Users/mikedesaro/Desktop/zig-aya/aya/deps/sdl/sdl.zig --pkg-end --pkg-begin imgui /Users/mikedesaro/Desktop/zig-aya/aya/deps/imgui/imgui.zig --pkg-end -I /usr/local/include/SDL2 -L /usr/local/lib -D _THREAD_SAFE -framework Foundation -framework QuartzCore -framework OpenGL -framework Metal -framework MetalKit -framework Cocoa -framework Quartz -framework Carbon -framework Audiotoolbox -framework CoreAudio --enable-cache 
error: the following build command failed with exit code 6:
/Users/mikedesaro/Desktop/zig-aya/zig-cache/o/bdb22acf36c14c874de860e923887515/build /Users/mikedesaro/Desktop/zig/build/zig /Users/mikedesaro/Desktop/zig-aya /Users/mikedesaro/Desktop/zig-aya/zig-cache run

@andrewrk
Copy link
Member Author

andrewrk commented Nov 9, 2020

Do I have to pass any new flags through to the LibExeObjStep?

If you want the system linker hack it's now an environment variable export ZIG_SYSTEM_LINKER_HACK=1. I think that is relevant to the first error.

For the second one, looks like we need to add some more in https://github.com/ziglang/fetch-them-macos-headers

@kubkon
Copy link
Member

kubkon commented Nov 9, 2020

@prime31 @andrewrk I've now added the missing headers.

@andrewrk
Copy link
Member Author

andrewrk commented Nov 9, 2020

Just to give you some context here @prime31 the point of these changes is that you would be able to cross compile your project targeting macOS from any other OS using only Zig. This is 1/2 of the puzzle, the other half is the linker issue, but that is a separate issue which I believe we are also close to solving.

@prime31
Copy link
Contributor

prime31 commented Nov 9, 2020

Just to give you some context here @prime31 the point of these changes is that you would be able to cross compile your project targeting macOS from any other OS using only Zig

I figured as much for the headers. One issue I see with that though is that all the framework headers would all also need to be included.

Switching to the system linker hack results in a new error:

export ZIG_SYSTEM_LINKER_HACK=1 && ~/Desktop/zig/build/zig build
attempt to unwrap error: FileNotFound
/Users/mikedesaro/Desktop/zig/src/link/Elf.zig:0:43: 0x10b6d8188 in link.Elf.flushModule (zig1)
/Users/mikedesaro/Desktop/zig/lib/std/fs.zig:1832:24: 0x10b6c13d6 in std.fs.Dir.copyFile (zig1)
            const st = try in_file.stat();
                       ^
/Users/mikedesaro/Desktop/zig/src/Compilation.zig:1286:29: 0x10b67c074 in Compilation.performAllTheWork (zig1)
                    decl.src(),
                            ^
/Users/mikedesaro/Desktop/zig/lib/std/fmt.zig:196:29: 0x10b674b42 in std.fmt.format (zig1)
                        args[arg_to_print],
                            ^
/Users/mikedesaro/Desktop/zig/src/main.zig:1888:39: 0x10b62adf5 in main.cmdTranslateC (zig1)
    defer if (enable_cache) man.deinit();
                                      ^
/Users/mikedesaro/Desktop/zig/src/main.zig:1704:17: 0x10b57d05c in main.buildOutputType (zig1)
                .print = comp.bin_file.options.emit.?.directory.path orelse ".",
                ^
/Users/mikedesaro/Desktop/zig/src/main.zig:0:23: 0x10b555139 in main.mainArgs (zig1)
/Users/mikedesaro/Desktop/zig/lib/std/heap.zig:78:41: 0x10b551389 in std.heap.cResize (zig1)
        const full_len = malloc_size(buf.ptr);
                                        ^
/Users/mikedesaro/Desktop/zig/lib/std/heap.zig:78:41: 0x10b551389 in std.heap.cResize (zig1)
        const full_len = malloc_size(buf.ptr);
                                        ^
/Users/mikedesaro/Desktop/zig/lib/std/heap.zig:78:41: 0x10b551389 in std.heap.cResize (zig1)
        const full_len = malloc_size(buf.ptr);
                                        ^
/Users/mikedesaro/Desktop/zig/lib/std/heap.zig:78:41: 0x10b551389 in std.heap.cResize (zig1)
        const full_len = malloc_size(buf.ptr);
                                        ^
/Users/mikedesaro/Desktop/zig/lib/std/heap.zig:78:41: 0x10b551389 in std.heap.cResize (zig1)
        const full_len = malloc_size(buf.ptr);
                                        ^
/Users/mikedesaro/Desktop/zig/lib/std/heap.zig:78:41: 0x10b551389 in std.heap.cResize (zig1)
        const full_len = malloc_size(buf.ptr);
                                        ^
/Users/mikedesaro/Desktop/zig/lib/std/heap.zig:78:41: 0x10b551389 in std.heap.cResize (zig1)
        const full_len = malloc_size(buf.ptr);
                                        ^
/Users/mikedesaro/Desktop/zig/lib/std/heap.zig:78:41: 0x10b551389 in std.heap.cResize (zig1)
        const full_len = malloc_size(buf.ptr);
                                        ^
/Users/mikedesaro/Desktop/zig/lib/std/heap.zig:78:41: 0x10b551389 in std.heap.cResize (zig1)
        const full_len = malloc_size(buf.ptr);
                                        ^
/Users/mikedesaro/Desktop/zig/lib/std/heap.zig:78:41: 0x10b551389 in std.heap.cResize (zig1)
        const full_len = malloc_size(buf.ptr);
                                        ^
/Users/mikedesaro/Desktop/zig/lib/std/heap.zig:78:41: 0x10b551389 in std.heap.cResize (zig1)
        const full_len = malloc_size(buf.ptr);
                                        ^
/Users/mikedesaro/Desktop/zig/lib/std/heap.zig:78:41: 0x10b551389 in std.heap.cResize (zig1)
        const full_len = malloc_size(buf.ptr);
                                        ^
/Users/mikedesaro/Desktop/zig/lib/std/heap.zig:78:41: 0x10b551389 in std.heap.cResize (zig1)
        const full_len = malloc_size(buf.ptr);
                                        ^
/Users/mikedesaro/Desktop/zig/lib/std/heap.zig:78:41: 0x10b551389 in std.heap.cResize (zig1)
        const full_len = malloc_size(buf.ptr);
                                        ^
/Users/mikedesaro/Desktop/zig/lib/std/heap.zig:78:41: 0x10b551389 in std.heap.cResize (zig1)
        const full_len = malloc_size(buf.ptr);
                                        ^
/Users/mikedesaro/Desktop/zig/lib/std/heap.zig:78:41: 0x10b551389 in std.heap.cResize (zig1)
        const full_len = malloc_size(buf.ptr);
                                        ^
/Users/mikedesaro/Desktop/zig/lib/std/heap.zig:78:41: 0x10b551389 in std.heap.cResize (zig1)
        const full_len = malloc_size(buf.ptr);
                                        ^
/Users/mikedesaro/Desktop/zig/lib/std/heap.zig:78:41: 0x10b551389 in std.heap.cResize (zig1)
        const full_len = malloc_size(buf.ptr);
                                        ^
/Users/mikedesaro/Desktop/zig/lib/std/io/reader.zig:188:50: 0x10b77bb82 in std.io.reader.Reader(*std.io.fixed_buffer_stream.FixedBufferStream([]const u8),std.io.fixed_buffer_stream.ReadError,std.io.fixed_buffer_stream.FixedBufferStream([]const u8).read).readByteSigned (zig1)
            return @bitCast(i8, try self.readByte());
                                                 ^
/Users/mikedesaro/Desktop/zig/lib/std/heap.zig:78:41: 0x10b551389 in std.heap.cResize (zig1)
        const full_len = malloc_size(buf.ptr);
                                        ^
/Users/mikedesaro/Desktop/zig/lib/std/hash/wyhash.zig:126:52: 0x10b73cb3e in std.hash.wyhash.WyhashStateless.hash (zig1)
        const aligned_len = input.len - (input.len % 32);
                                                   ^
/Users/mikedesaro/Desktop/zig/lib/std/fs.zig:867:35: 0x10b5dcfbe in std.fs.Dir.createFileZ (zig1)
            (if (flags.exclusive) @as(u32, os.O_EXCL) else 0);
                                  ^
/Users/mikedesaro/Desktop/zig/lib/std/crypto/siphash.zig:220:65: 0x10b5d8d6b in std.crypto.siphash.SipHash(u128,1,3).final (zig1)
            mem.writeIntLittle(T, out, self.state.final(self.buf[0..self.buf_len]));
                                                                ^
/Users/mikedesaro/Desktop/zig/src/Cache.zig:632:21: 0x10b5dac7a in Cache.isProblematicTimestamp (zig1)
    var wall_nsec = @intCast(i64, @mod(wall_clock, std.time.ns_per_s));
                    ^
/Users/mikedesaro/Desktop/zig/src/Cache.zig:334:17: 0x10b5d36e7 in Cache.Manifest.hit (zig1)
                if (isProblematicTimestamp(cache_hash_file.stat.mtime)) {
                ^
???:?:?: 0x10f2dc418 in ___zig_fail_unwrap (???)
/Users/mikedesaro/Desktop/zig/src/stage1.zig:28:0: 0x10b554c80 in main (zig1)
pub export fn main(argc: c_int, argv: [*][*:0]u8) c_int {

???:?:?: 0x7fff6d838cc8 in ??? (???)
???:?:?: 0x76 in ??? (???)
run...The following command terminated unexpectedly:
/Users/mikedesaro/Desktop/zig/build/zig build-exe /Users/mikedesaro/Desktop/zig-upaya/examples/tilemap/main.zig --library c --library c++ -cflags -std=c99 -ObjC -fobjc-arc -- /Users/mikedesaro/Desktop/zig-upaya/src/deps/sokol/compile_sokol.c -cflags -std=c99 -- /Users/mikedesaro/Desktop/zig-upaya/src/deps/stb/src/stb_impl.c --library c++ -cflags -Wno-return-type-c-linkage -- /Users/mikedesaro/Desktop/zig-upaya/src/deps/imgui/cimgui/imgui/imgui.cpp -cflags -Wno-return-type-c-linkage -- /Users/mikedesaro/Desktop/zig-upaya/src/deps/imgui/cimgui/imgui/imgui_demo.cpp -cflags -Wno-return-type-c-linkage -- /Users/mikedesaro/Desktop/zig-upaya/src/deps/imgui/cimgui/imgui/imgui_draw.cpp -cflags -Wno-return-type-c-linkage -- /Users/mikedesaro/Desktop/zig-upaya/src/deps/imgui/cimgui/imgui/imgui_widgets.cpp -cflags -Wno-return-type-c-linkage -- /Users/mikedesaro/Desktop/zig-upaya/src/deps/imgui/cimgui/cimgui.cpp -cflags -Wno-return-type-c-linkage -- /Users/mikedesaro/Desktop/zig-upaya/src/deps/imgui/temporary_hacks.cpp -cflags -D_CRT_SECURE_NO_WARNINGS -D_CRT_SECURE_NO_DEPRECATE -- /Users/mikedesaro/Desktop/zig-upaya/src/deps/filebrowser/src/tinyfiledialogs.c --cache-dir /Users/mikedesaro/Desktop/zig-upaya/zig-cache --name run --pkg-begin upaya /Users/mikedesaro/Desktop/zig-upaya/src/upaya.zig --pkg-begin stb /Users/mikedesaro/Desktop/zig-upaya/src/deps/stb/stb.zig --pkg-end --pkg-begin filebrowser /Users/mikedesaro/Desktop/zig-upaya/src/deps/filebrowser/filebrowser.zig --pkg-end --pkg-begin sokol /Users/mikedesaro/Desktop/zig-upaya/src/deps/sokol/sokol.zig --pkg-end --pkg-begin imgui /Users/mikedesaro/Desktop/zig-upaya/src/deps/imgui/imgui.zig --pkg-end --pkg-end --pkg-begin sokol /Users/mikedesaro/Desktop/zig-upaya/src/deps/sokol/sokol.zig --pkg-end --pkg-begin stb /Users/mikedesaro/Desktop/zig-upaya/src/deps/stb/stb.zig --pkg-end --pkg-begin imgui /Users/mikedesaro/Desktop/zig-upaya/src/deps/imgui/imgui.zig --pkg-end --pkg-begin filebrowser /Users/mikedesaro/Desktop/zig-upaya/src/deps/filebrowser/filebrowser.zig --pkg-end -I /Users/mikedesaro/Desktop/zig-upaya/src/deps/sokol -I /Users/mikedesaro/Desktop/zig-upaya/src/deps/stb/src -I /Users/mikedesaro/Desktop/zig-upaya/src/deps/imgui -I /Users/mikedesaro/Desktop/zig-upaya/src/deps/imgui/cimgui -F /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks -F /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks -framework Foundation -framework QuartzCore -framework Metal -framework MetalKit -framework OpenGL -framework Cocoa -framework Quartz -framework Audiotoolbox -framework CoreAudio --enable-cache 
error: the following build command failed with exit code 6:

@kubkon
Copy link
Member

kubkon commented Nov 9, 2020

Just to give you some context here @prime31 the point of these changes is that you would be able to cross compile your project targeting macOS from any other OS using only Zig

I figured as much for the headers. One issue I see with that though is that all the framework headers would all also need to be included.

Switching to the system linker hack results in a new error:

export ZIG_SYSTEM_LINKER_HACK=1 && ~/Desktop/zig/build/zig build
attempt to unwrap error: FileNotFound
/Users/mikedesaro/Desktop/zig/src/link/Elf.zig:0:43: 0x10b6d8188 in link.Elf.flushModule (zig1)
/Users/mikedesaro/Desktop/zig/lib/std/fs.zig:1832:24: 0x10b6c13d6 in std.fs.Dir.copyFile (zig1)
            const st = try in_file.stat();
                       ^
/Users/mikedesaro/Desktop/zig/src/Compilation.zig:1286:29: 0x10b67c074 in Compilation.performAllTheWork (zig1)
                    decl.src(),
                            ^
/Users/mikedesaro/Desktop/zig/lib/std/fmt.zig:196:29: 0x10b674b42 in std.fmt.format (zig1)
                        args[arg_to_print],
                            ^
/Users/mikedesaro/Desktop/zig/src/main.zig:1888:39: 0x10b62adf5 in main.cmdTranslateC (zig1)
    defer if (enable_cache) man.deinit();
                                      ^
/Users/mikedesaro/Desktop/zig/src/main.zig:1704:17: 0x10b57d05c in main.buildOutputType (zig1)
                .print = comp.bin_file.options.emit.?.directory.path orelse ".",
                ^
/Users/mikedesaro/Desktop/zig/src/main.zig:0:23: 0x10b555139 in main.mainArgs (zig1)
/Users/mikedesaro/Desktop/zig/lib/std/heap.zig:78:41: 0x10b551389 in std.heap.cResize (zig1)
        const full_len = malloc_size(buf.ptr);
                                        ^
/Users/mikedesaro/Desktop/zig/lib/std/heap.zig:78:41: 0x10b551389 in std.heap.cResize (zig1)
        const full_len = malloc_size(buf.ptr);
                                        ^
/Users/mikedesaro/Desktop/zig/lib/std/heap.zig:78:41: 0x10b551389 in std.heap.cResize (zig1)
        const full_len = malloc_size(buf.ptr);
                                        ^
/Users/mikedesaro/Desktop/zig/lib/std/heap.zig:78:41: 0x10b551389 in std.heap.cResize (zig1)
        const full_len = malloc_size(buf.ptr);
                                        ^
/Users/mikedesaro/Desktop/zig/lib/std/heap.zig:78:41: 0x10b551389 in std.heap.cResize (zig1)
        const full_len = malloc_size(buf.ptr);
                                        ^
/Users/mikedesaro/Desktop/zig/lib/std/heap.zig:78:41: 0x10b551389 in std.heap.cResize (zig1)
        const full_len = malloc_size(buf.ptr);
                                        ^
/Users/mikedesaro/Desktop/zig/lib/std/heap.zig:78:41: 0x10b551389 in std.heap.cResize (zig1)
        const full_len = malloc_size(buf.ptr);
                                        ^
/Users/mikedesaro/Desktop/zig/lib/std/heap.zig:78:41: 0x10b551389 in std.heap.cResize (zig1)
        const full_len = malloc_size(buf.ptr);
                                        ^
/Users/mikedesaro/Desktop/zig/lib/std/heap.zig:78:41: 0x10b551389 in std.heap.cResize (zig1)
        const full_len = malloc_size(buf.ptr);
                                        ^
/Users/mikedesaro/Desktop/zig/lib/std/heap.zig:78:41: 0x10b551389 in std.heap.cResize (zig1)
        const full_len = malloc_size(buf.ptr);
                                        ^
/Users/mikedesaro/Desktop/zig/lib/std/heap.zig:78:41: 0x10b551389 in std.heap.cResize (zig1)
        const full_len = malloc_size(buf.ptr);
                                        ^
/Users/mikedesaro/Desktop/zig/lib/std/heap.zig:78:41: 0x10b551389 in std.heap.cResize (zig1)
        const full_len = malloc_size(buf.ptr);
                                        ^
/Users/mikedesaro/Desktop/zig/lib/std/heap.zig:78:41: 0x10b551389 in std.heap.cResize (zig1)
        const full_len = malloc_size(buf.ptr);
                                        ^
/Users/mikedesaro/Desktop/zig/lib/std/heap.zig:78:41: 0x10b551389 in std.heap.cResize (zig1)
        const full_len = malloc_size(buf.ptr);
                                        ^
/Users/mikedesaro/Desktop/zig/lib/std/heap.zig:78:41: 0x10b551389 in std.heap.cResize (zig1)
        const full_len = malloc_size(buf.ptr);
                                        ^
/Users/mikedesaro/Desktop/zig/lib/std/heap.zig:78:41: 0x10b551389 in std.heap.cResize (zig1)
        const full_len = malloc_size(buf.ptr);
                                        ^
/Users/mikedesaro/Desktop/zig/lib/std/heap.zig:78:41: 0x10b551389 in std.heap.cResize (zig1)
        const full_len = malloc_size(buf.ptr);
                                        ^
/Users/mikedesaro/Desktop/zig/lib/std/heap.zig:78:41: 0x10b551389 in std.heap.cResize (zig1)
        const full_len = malloc_size(buf.ptr);
                                        ^
/Users/mikedesaro/Desktop/zig/lib/std/io/reader.zig:188:50: 0x10b77bb82 in std.io.reader.Reader(*std.io.fixed_buffer_stream.FixedBufferStream([]const u8),std.io.fixed_buffer_stream.ReadError,std.io.fixed_buffer_stream.FixedBufferStream([]const u8).read).readByteSigned (zig1)
            return @bitCast(i8, try self.readByte());
                                                 ^
/Users/mikedesaro/Desktop/zig/lib/std/heap.zig:78:41: 0x10b551389 in std.heap.cResize (zig1)
        const full_len = malloc_size(buf.ptr);
                                        ^
/Users/mikedesaro/Desktop/zig/lib/std/hash/wyhash.zig:126:52: 0x10b73cb3e in std.hash.wyhash.WyhashStateless.hash (zig1)
        const aligned_len = input.len - (input.len % 32);
                                                   ^
/Users/mikedesaro/Desktop/zig/lib/std/fs.zig:867:35: 0x10b5dcfbe in std.fs.Dir.createFileZ (zig1)
            (if (flags.exclusive) @as(u32, os.O_EXCL) else 0);
                                  ^
/Users/mikedesaro/Desktop/zig/lib/std/crypto/siphash.zig:220:65: 0x10b5d8d6b in std.crypto.siphash.SipHash(u128,1,3).final (zig1)
            mem.writeIntLittle(T, out, self.state.final(self.buf[0..self.buf_len]));
                                                                ^
/Users/mikedesaro/Desktop/zig/src/Cache.zig:632:21: 0x10b5dac7a in Cache.isProblematicTimestamp (zig1)
    var wall_nsec = @intCast(i64, @mod(wall_clock, std.time.ns_per_s));
                    ^
/Users/mikedesaro/Desktop/zig/src/Cache.zig:334:17: 0x10b5d36e7 in Cache.Manifest.hit (zig1)
                if (isProblematicTimestamp(cache_hash_file.stat.mtime)) {
                ^
???:?:?: 0x10f2dc418 in ___zig_fail_unwrap (???)
/Users/mikedesaro/Desktop/zig/src/stage1.zig:28:0: 0x10b554c80 in main (zig1)
pub export fn main(argc: c_int, argv: [*][*:0]u8) c_int {

???:?:?: 0x7fff6d838cc8 in ??? (???)
???:?:?: 0x76 in ??? (???)
run...The following command terminated unexpectedly:
/Users/mikedesaro/Desktop/zig/build/zig build-exe /Users/mikedesaro/Desktop/zig-upaya/examples/tilemap/main.zig --library c --library c++ -cflags -std=c99 -ObjC -fobjc-arc -- /Users/mikedesaro/Desktop/zig-upaya/src/deps/sokol/compile_sokol.c -cflags -std=c99 -- /Users/mikedesaro/Desktop/zig-upaya/src/deps/stb/src/stb_impl.c --library c++ -cflags -Wno-return-type-c-linkage -- /Users/mikedesaro/Desktop/zig-upaya/src/deps/imgui/cimgui/imgui/imgui.cpp -cflags -Wno-return-type-c-linkage -- /Users/mikedesaro/Desktop/zig-upaya/src/deps/imgui/cimgui/imgui/imgui_demo.cpp -cflags -Wno-return-type-c-linkage -- /Users/mikedesaro/Desktop/zig-upaya/src/deps/imgui/cimgui/imgui/imgui_draw.cpp -cflags -Wno-return-type-c-linkage -- /Users/mikedesaro/Desktop/zig-upaya/src/deps/imgui/cimgui/imgui/imgui_widgets.cpp -cflags -Wno-return-type-c-linkage -- /Users/mikedesaro/Desktop/zig-upaya/src/deps/imgui/cimgui/cimgui.cpp -cflags -Wno-return-type-c-linkage -- /Users/mikedesaro/Desktop/zig-upaya/src/deps/imgui/temporary_hacks.cpp -cflags -D_CRT_SECURE_NO_WARNINGS -D_CRT_SECURE_NO_DEPRECATE -- /Users/mikedesaro/Desktop/zig-upaya/src/deps/filebrowser/src/tinyfiledialogs.c --cache-dir /Users/mikedesaro/Desktop/zig-upaya/zig-cache --name run --pkg-begin upaya /Users/mikedesaro/Desktop/zig-upaya/src/upaya.zig --pkg-begin stb /Users/mikedesaro/Desktop/zig-upaya/src/deps/stb/stb.zig --pkg-end --pkg-begin filebrowser /Users/mikedesaro/Desktop/zig-upaya/src/deps/filebrowser/filebrowser.zig --pkg-end --pkg-begin sokol /Users/mikedesaro/Desktop/zig-upaya/src/deps/sokol/sokol.zig --pkg-end --pkg-begin imgui /Users/mikedesaro/Desktop/zig-upaya/src/deps/imgui/imgui.zig --pkg-end --pkg-end --pkg-begin sokol /Users/mikedesaro/Desktop/zig-upaya/src/deps/sokol/sokol.zig --pkg-end --pkg-begin stb /Users/mikedesaro/Desktop/zig-upaya/src/deps/stb/stb.zig --pkg-end --pkg-begin imgui /Users/mikedesaro/Desktop/zig-upaya/src/deps/imgui/imgui.zig --pkg-end --pkg-begin filebrowser /Users/mikedesaro/Desktop/zig-upaya/src/deps/filebrowser/filebrowser.zig --pkg-end -I /Users/mikedesaro/Desktop/zig-upaya/src/deps/sokol -I /Users/mikedesaro/Desktop/zig-upaya/src/deps/stb/src -I /Users/mikedesaro/Desktop/zig-upaya/src/deps/imgui -I /Users/mikedesaro/Desktop/zig-upaya/src/deps/imgui/cimgui -F /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks -F /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks -framework Foundation -framework QuartzCore -framework Metal -framework MetalKit -framework OpenGL -framework Cocoa -framework Quartz -framework Audiotoolbox -framework CoreAudio --enable-cache 
error: the following build command failed with exit code 6:

Damn, that's what I was getting with zig-upaya as well and had no idea what the cause could have been...

@kubkon
Copy link
Member

kubkon commented Nov 9, 2020

I figured as much for the headers. One issue I see with that though is that all the framework headers would all also need to be included.

Indeed, but there doesn't seem to be any other way if we are to successfully cross-compile from any OS to macOS.

@kubkon
Copy link
Member

kubkon commented Nov 9, 2020

Not quite the same but a similar error with zig-upaya:

attempt to unwrap error: FileNotFound
/Users/kubkon/dev/zig/lib/std/heap.zig:78:41: 0x100b53439 in std.heap.cResize (zig1)
        const full_len = malloc_size(buf.ptr);
                                        ^
/Users/kubkon/dev/zig/lib/std/heap.zig:78:41: 0x100b53439 in std.heap.cResize (zig1)
        const full_len = malloc_size(buf.ptr);
                                        ^
/Users/kubkon/dev/zig/lib/std/heap.zig:78:41: 0x100b53439 in std.heap.cResize (zig1)
        const full_len = malloc_size(buf.ptr);
                                        ^
/Users/kubkon/dev/zig/lib/std/heap.zig:78:41: 0x100b53439 in std.heap.cResize (zig1)
        const full_len = malloc_size(buf.ptr);
                                        ^
/Users/kubkon/dev/zig/lib/std/heap.zig:78:41: 0x100b53439 in std.heap.cResize (zig1)
        const full_len = malloc_size(buf.ptr);
                                        ^
/Users/kubkon/dev/zig/lib/std/heap.zig:78:41: 0x100b53439 in std.heap.cResize (zig1)
        const full_len = malloc_size(buf.ptr);
                                        ^
/Users/kubkon/dev/zig/lib/std/io/reader.zig:188:50: 0x100d7dc32 in std.io.reader.Reader(*std.io.fixed_buffer_stream.FixedBufferStream([]const u8),std.io.fixed_buffer_stream.ReadError,std.io.fixed_buffer_stream.FixedBufferStream([]const u8).read).readByteSigned (zig1)
            return @bitCast(i8, try self.readByte());
                                                 ^
/Users/kubkon/dev/zig/lib/std/heap.zig:78:41: 0x100b53439 in std.heap.cResize (zig1)
        const full_len = malloc_size(buf.ptr);
                                        ^
/Users/kubkon/dev/zig/lib/std/hash/wyhash.zig:126:52: 0x100d3ebee in std.hash.wyhash.WyhashStateless.hash (zig1)
        const aligned_len = input.len - (input.len % 32);
                                                   ^
/Users/kubkon/dev/zig/lib/std/fs.zig:867:35: 0x100bdf06e in std.fs.Dir.createFileZ (zig1)
            (if (flags.exclusive) @as(u32, os.O_EXCL) else 0);
                                  ^
/Users/kubkon/dev/zig/lib/std/crypto/siphash.zig:220:65: 0x100bdae1b in std.crypto.siphash.SipHash(u128,1,3).final (zig1)
            mem.writeIntLittle(T, out, self.state.final(self.buf[0..self.buf_len]));
                                                                ^
/Users/kubkon/dev/zig/src/Cache.zig:632:21: 0x100bdcd2a in Cache.isProblematicTimestamp (zig1)
    var wall_nsec = @intCast(i64, @mod(wall_clock, std.time.ns_per_s));
                    ^
/Users/kubkon/dev/zig/src/Cache.zig:334:17: 0x100bd5797 in Cache.Manifest.hit (zig1)
                if (isProblematicTimestamp(cache_hash_file.stat.mtime)) {
                ^
/Users/kubkon/dev/zig/src/link/Elf.zig:0:43: 0x100cda238 in link.Elf.flushModule (zig1)
/Users/kubkon/dev/zig/lib/std/fs.zig:1832:24: 0x100cc3486 in std.fs.Dir.copyFile (zig1)
            const st = try in_file.stat();
                       ^
/Users/kubkon/dev/zig/src/Compilation.zig:1286:29: 0x100c7e124 in Compilation.performAllTheWork (zig1)
                    decl.src(),
                            ^
/Users/kubkon/dev/zig/lib/std/fmt.zig:196:29: 0x100c76bf2 in std.fmt.format (zig1)
                        args[arg_to_print],
                            ^
/Users/kubkon/dev/zig/src/main.zig:1888:39: 0x100c2cea5 in main.cmdTranslateC (zig1)
    defer if (enable_cache) man.deinit();
                                      ^
/Users/kubkon/dev/zig/src/main.zig:1704:17: 0x100b7f10c in main.buildOutputType (zig1)
                .print = comp.bin_file.options.emit.?.directory.path orelse ".",
                ^
/Users/kubkon/dev/zig/src/main.zig:0:23: 0x100b571e9 in main.mainArgs (zig1)
/Users/kubkon/dev/zig/lib/std/heap.zig:78:41: 0x100b53439 in std.heap.cResize (zig1)
        const full_len = malloc_size(buf.ptr);
                                        ^
/Users/kubkon/dev/zig/lib/std/heap.zig:78:41: 0x100b53439 in std.heap.cResize (zig1)
        const full_len = malloc_size(buf.ptr);
                                        ^
/Users/kubkon/dev/zig/lib/std/heap.zig:78:41: 0x100b53439 in std.heap.cResize (zig1)
        const full_len = malloc_size(buf.ptr);
                                        ^
/Users/kubkon/dev/zig/lib/std/heap.zig:78:41: 0x100b53439 in std.heap.cResize (zig1)
        const full_len = malloc_size(buf.ptr);
                                        ^
/Users/kubkon/dev/zig/lib/std/heap.zig:78:41: 0x100b53439 in std.heap.cResize (zig1)
        const full_len = malloc_size(buf.ptr);
                                        ^
/Users/kubkon/dev/zig/lib/std/heap.zig:78:41: 0x100b53439 in std.heap.cResize (zig1)
        const full_len = malloc_size(buf.ptr);
                                        ^
/Users/kubkon/dev/zig/lib/std/heap.zig:78:41: 0x100b53439 in std.heap.cResize (zig1)
        const full_len = malloc_size(buf.ptr);
                                        ^
/Users/kubkon/dev/zig/lib/std/heap.zig:78:41: 0x100b53439 in std.heap.cResize (zig1)
        const full_len = malloc_size(buf.ptr);
                                        ^
/Users/kubkon/dev/zig/lib/std/heap.zig:78:41: 0x100b53439 in std.heap.cResize (zig1)
        const full_len = malloc_size(buf.ptr);
                                        ^
/Users/kubkon/dev/zig/lib/std/heap.zig:78:41: 0x100b53439 in std.heap.cResize (zig1)
        const full_len = malloc_size(buf.ptr);
                                        ^
/Users/kubkon/dev/zig/lib/std/heap.zig:78:41: 0x100b53439 in std.heap.cResize (zig1)
        const full_len = malloc_size(buf.ptr);
                                        ^
/Users/kubkon/dev/zig/lib/std/heap.zig:78:41: 0x100b53439 in std.heap.cResize (zig1)
        const full_len = malloc_size(buf.ptr);
                                        ^
???:?:?: 0x1048de4c8 in ___zig_fail_unwrap (???)
/Users/kubkon/dev/zig/src/stage1.zig:28:0: 0x100b56d30 in main (zig1)
pub export fn main(argc: c_int, argv: [*][*:0]u8) c_int {

???:?:?: 0x7fff20335630 in ??? (???)
???:?:?: 0x76 in ??? (???)
run...The following command terminated unexpectedly:
/Users/kubkon/dev/zig/build/zig build-exe /Users/kubkon/dev/zig-upaya/examples/tilemap/main.zig --library c --library c++ -cflags -std=c99 -ObjC -fobjc-arc -- /Users/kubkon/dev/zig-upaya/src/deps/sokol/compile_sokol.c -cflags -std=c99 -- /Users/kubkon/dev/zig-upaya/src/deps/stb/src/stb_impl.c --library c++ -cflags -Wno-return-type-c-linkage -- /Users/kubkon/dev/zig-upaya/src/deps/imgui/cimgui/imgui/imgui.cpp -cflags -Wno-return-type-c-linkage -- /Users/kubkon/dev/zig-upaya/src/deps/imgui/cimgui/imgui/imgui_demo.cpp -cflags -Wno-return-type-c-linkage -- /Users/kubkon/dev/zig-upaya/src/deps/imgui/cimgui/imgui/imgui_draw.cpp -cflags -Wno-return-type-c-linkage -- /Users/kubkon/dev/zig-upaya/src/deps/imgui/cimgui/imgui/imgui_widgets.cpp -cflags -Wno-return-type-c-linkage -- /Users/kubkon/dev/zig-upaya/src/deps/imgui/cimgui/cimgui.cpp -cflags -Wno-return-type-c-linkage -- /Users/kubkon/dev/zig-upaya/src/deps/imgui/temporary_hacks.cpp -cflags -D_CRT_SECURE_NO_WARNINGS -D_CRT_SECURE_NO_DEPRECATE -- /Users/kubkon/dev/zig-upaya/src/deps/filebrowser/src/tinyfiledialogs.c --cache-dir /Users/kubkon/dev/zig-upaya/zig-cache --name run --pkg-begin upaya /Users/kubkon/dev/zig-upaya/src/upaya.zig --pkg-begin stb /Users/kubkon/dev/zig-upaya/src/deps/stb/stb.zig --pkg-end --pkg-begin filebrowser /Users/kubkon/dev/zig-upaya/src/deps/filebrowser/filebrowser.zig --pkg-end --pkg-begin sokol /Users/kubkon/dev/zig-upaya/src/deps/sokol/sokol.zig --pkg-end --pkg-begin imgui /Users/kubkon/dev/zig-upaya/src/deps/imgui/imgui.zig --pkg-end --pkg-end --pkg-begin sokol /Users/kubkon/dev/zig-upaya/src/deps/sokol/sokol.zig --pkg-end --pkg-begin stb /Users/kubkon/dev/zig-upaya/src/deps/stb/stb.zig --pkg-end --pkg-begin imgui /Users/kubkon/dev/zig-upaya/src/deps/imgui/imgui.zig --pkg-end --pkg-begin filebrowser /Users/kubkon/dev/zig-upaya/src/deps/filebrowser/filebrowser.zig --pkg-end -I /Users/kubkon/dev/zig-upaya/src/deps/sokol -I /Users/kubkon/dev/zig-upaya/src/deps/stb/src -I /Users/kubkon/dev/zig-upaya/src/deps/imgui -I /Users/kubkon/dev/zig-upaya/src/deps/imgui/cimgui -F /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks -F /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks -framework Foundation -framework QuartzCore -framework Metal -framework MetalKit -framework OpenGL -framework Cocoa -framework Quartz -framework Audiotoolbox -framework CoreAudio --enable-cache
error: the following build command failed with exit code 6:
/Users/kubkon/dev/zig-upaya/zig-cache/o/3d0265caeb17cebd50949b483e7b35ed/build /Users/kubkon/dev/zig/build/zig /Users/kubkon/dev/zig-upaya /Users/kubkon/dev/zig-upaya/zig-cache

@prime31
Copy link
Contributor

prime31 commented Nov 9, 2020

So, project 3 does build and run! And with the header update project 2 works as well. zig-upaya still does fail and I'll try project 4 next but I suspect it will fail because it needs Metal/MetalKit headers.

Indeed, but there doesn't seem to be any other way if we are to successfully cross-compile from any OS to macOS.
Agreed. No possible way around that one.

Is there a way to just force use the system headers or do we want to error out so that all the headers can be certain to be present?

@kubkon
Copy link
Member

kubkon commented Nov 9, 2020

So, project 3 does build and run! And with the header update project 2 works as well. zig-upaya still does fail and I'll try project 4 next but I suspect it will fail because it needs Metal/MetalKit headers.

Indeed, but there doesn't seem to be any other way if we are to successfully cross-compile from any OS to macOS.
Agreed. No possible way around that one.

Is there a way to just force use the system headers or do we want to error out so that all the headers can be certain to be present?

I think it's the latter. And then add more as we go (when we get more issues submitted).

@kubkon
Copy link
Member

kubkon commented Nov 9, 2020

Hmm, the FileNotFound unwrap error looks like caching issue.

@kubkon
Copy link
Member

kubkon commented Nov 9, 2020

Another worrying thing is why are getting Elf.zig in stack traces? Oh, this could be because of the system linker I think which orders symbols differently to LLD:

/Users/kubkon/dev/zig/src/link/Elf.zig:0:43: 0x100cda238 in link.Elf.flushModule (zig1)

@andrewrk
Copy link
Member Author

andrewrk commented Nov 9, 2020

I think we can at least include the libc headers, posix c headers, and darwin-specific system headers. Not all applications depend on frameworks. For example, the zig compiler itself does not need to link against any frameworks.

I think we should treat frameworks as a separate issue, evaluating them on a case-by-case basis, look at the license of the header files, and how much MiB of data it would take to ship the headers, and whether we can cross-link against them, and then do the due diligence to fully support the framework. #1349

As far as this pull request is concerned I want to proceed carefully. I don't want to haphazardly add framework includes to fetch-them-macos-headers, but I also want to prevent projects such as the 3 we are looking at here from breaking.

@prime31
Copy link
Contributor

prime31 commented Nov 9, 2020

Another worrying thing is why are getting Elf.zig in stack traces? Oh, this could be because of the system linker I think which orders symbols differently to LLD:

/Users/kubkon/dev/zig/src/link/Elf.zig:0:43: 0x100cda238 in link.Elf.flushModule (zig1)

Yeah, I learned to just ignore stack traces. If you can get a nice, proper crash and the OS crash reporter pops up the stack trace in there is perfect.

@andrewrk I just built and ran an app that access Metal/MetalKit successfully. Turns out all my projects add the framework include path returned by xcrun --show-sdk-path via addFrameworkDir so framework headers will be system based.

@prime31
Copy link
Contributor

prime31 commented Nov 9, 2020

Just to recap, 3 out of 4 mixed C/C++/Zig projects now functional on macOS. I'm seeing if I can figure out where the last one has gone wrong from the outside, in case its fixable via build.zig or some other mechanism (if its a cache FileNotFound thats another thing of course).

@kubkon
Copy link
Member

kubkon commented Nov 9, 2020

Yeah, I learned to just ignore stack traces. If you can get a nice, proper crash and the OS crash reporter pops up the stack trace in there is perfect.

👍

@andrewrk I just built and ran an app that access Metal/MetalKit successfully. Turns out all my projects add the framework include path returned by xcrun --show-sdk-path via addFrameworkDir so framework headers will be system based.

Actually, you don't need to add those anymore since we automatically include -syslibroot $(xcrun --show-sdk-path) within the linker invocation in Zig when compiling natively on macOS :-)

@kubkon
Copy link
Member

kubkon commented Nov 9, 2020

OK, I think I found the reason for the unwrap trap. It seems that the last object file run.o is not created in this block here: MachO.zig#L412.

@prime31
Copy link
Contributor

prime31 commented Nov 9, 2020

Actually, you don't need to add those anymore since we automatically include -syslibroot $(xcrun --show-sdk-path) within the linker invocation in Zig when compiling natively on macOS :-)

If I don't manually add them it seems I end up with fatal error: 'Carbon/Carbon.h' file not found

@kubkon
Copy link
Member

kubkon commented Nov 9, 2020

Actually, you don't need to add those anymore since we automatically include -syslibroot $(xcrun --show-sdk-path) within the linker invocation in Zig when compiling natively on macOS :-)

If I don't manually add them it seems I end up with fatal error: 'Carbon/Carbon.h' file not found

Oh right, I guess you still need to add the framework search path just without the root, so -F/System/Library/Frameworks but I might be wrong here. I'm still trying to get my head around all of this on macOS.

@kubkon
Copy link
Member

kubkon commented Nov 9, 2020

@prime31 huh, when I comment out this bit in build.zig in zig-upaya, the panic is gone: build.zig#L27. I think there might have been changes to the build system itself which result in Zig trying to create an object file from run.

EDIT: it seems that we can only have one-to-one mapping in Builder.addExecutable(self: *Builder, name: []const u8, source: ?[]const u8) between name and source. @andrewrk could comment on this as I'm not that literate when it comes to Builder yet.

@prime31
Copy link
Contributor

prime31 commented Nov 9, 2020

@kubkon confirmed that deleting the createExe(b, target, "run", example[1]) does work in zig-upaya. Oddly, in the other 3 projects it works fine when adding a "run" target.

@andrewrk what kubkon is referring to is the following:

builder.addExecutable("run", "file.zig");
builder.addExecutable("some_thing", "file.zig");

If always make the first executable in my projects duplicated as "run" so that zig build run will always run it. For some reason, only on this specific project that breaks with the FileNotFound error. Other projects work fine with that same pattern.

@kubkon
Copy link
Member

kubkon commented Nov 9, 2020

@prime31 given that the problem with zig-upaya doesn't seem to be related to the contents of this PR, do I have the green light to merge?

@prime31
Copy link
Contributor

prime31 commented Nov 9, 2020

@prime31 given that the problem with zig-upaya doesn't seem to be related to the contents of this PR, do I have the green light to merge?

I don't see why not. It seems like a totally separate issue. Green light!

@kubkon kubkon merged commit 0bc9fd5 into master Nov 9, 2020
@andrewrk andrewrk deleted the macos-posix-headers branch November 10, 2020 20:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants