andreas-jonsson / virtualxt

Portable, lightweight PC/XT emulator written in C.
https://virtualxt.org
Other
72 stars 17 forks source link

building on Mac OSX 12.5.1 fails #17

Closed Waffle2 closed 2 years ago

Waffle2 commented 2 years ago

attempting to build on 12.5.1 fails.

I did

zig build -Dv20=true

and got:

error(compilation): clang failed with stderr: /Users/dlr/src/virtualxt/front/sdl/main.c:117:20: error: static declaration of 'getline' follows non-static declaration /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk/usr/include/stdio.h:348:9: note: previous declaration is here /Users/dlr/src/virtualxt/front/sdl/main.c:149:15: error: 'tmpnam' is deprecated: This function is provided for compatibility reasons only. Due to security concerns inherent in the design of tmpnam(3), it is highly recommended that you use mkstemp(3) instead. [-Werror,-Wdeprecated-declarations] /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk/usr/include/stdio.h:186:1: note: 'tmpnam' has been explicitly marked deprecated here /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk/usr/include/sys/cdefs.h:208:48: note: expanded from macro '__deprecated_msg' /Users/dlr/src/virtualxt/front/sdl/main.c:405:53: error: incompatible function pointer types initializing 'const char ()(void)' with an expression of type 'ssize_t (*)(char *restrict, size_t restrict, FILE restrict)' (aka 'long ()(char *restrict, unsigned long restrict, struct __sFILE *restrict)') [-Werror,-Wincompatible-function-pointer-types]

/Users/dlr/src/virtualxt/front/sdl/main.c:1:1: error: unable to build C object: clang exited with code 1 virtualxt...The following command exited with error code 1: /opt/local/bin/zig build-exe /Users/dlr/src/virtualxt/front/sdl/main.zig -lSDL2 build/lib/libvxt.macos.x86_64.a /Users/dlr/src/virtualxt/zig-cache/o/6480aeeaf7746a247900c6cbe3acff57/libvxtp.a /Users/dlr/src/virtualxt/zig-cache/o/3bb5aad573a602bbcd779148e5429ca7/libini.a /Users/dlr/src/virtualxt/zig-cache/o/933a8ee313200caf9db10cc21f94c5e4/libnuked-opl3.a -lc -cflags -Wall -Wextra -Werror -fno-sanitize=signed-integer-overflow -fno-sanitize=unsigned-integer-overflow -std=c11 -pedantic -- /Users/dlr/src/virtualxt/front/sdl/main.c -cflags -std=c11 -Wno-unused-variable -Wno-unused-parameter -- /Users/dlr/src/virtualxt/front/sdl/docopt.c --cache-dir /Users/dlr/src/virtualxt/zig-cache --global-cache-dir /Users/dlr/.cache/zig --name virtualxt -I /Users/dlr/src/virtualxt/front/sdl -I /opt/local/include -I /opt/local/include/SDL2 -I /Users/dlr/src/virtualxt/lib/vxt/include -I /Users/dlr/src/virtualxt/lib/vxtp -I /Users/dlr/src/virtualxt/lib/inih -L /opt/local/lib -D ENTRY=c_main -D PLATFORM=macos -D _THREAD_SAFE -D VXT_CPU_V20 --enable-cache error: the following build command failed with exit code 1: /Users/dlr/src/virtualxt/zig-cache/o/92cd66d1f14ea2e26afd9ae07bab6549/build /opt/local/bin/zig /Users/dlr/src/virtualxt /Users/dlr/src/virtualxt/zig-cache /Users/dlr/.cache/zig -Dv20=true

Waffle2 commented 2 years ago

my other note disappeared here... I was able to fix this by changing getline to a local function (mgetline), and re-doing the tmpnam code. It's not difficult to get it going.

andreas-jonsson commented 2 years ago

I don't have any modern OSX machines around at this point. If there was only a few lines that needed fixing could you share the patch with me and I can switch on the CI for OSX so we can catch these kinds of issues in the future. (Currently the 0.7 branch is not tested on OSX.)

Are you testing this a ARM or x86 Mac?

Waffle2 commented 2 years ago

Here's what I did:

diff --git a/front/sdl/main.c b/front/sdl/main.c
index ceb7175..d0d1171 100644
--- a/front/sdl/main.c
+++ b/front/sdl/main.c
@@ -114,7 +114,7 @@ static const char *sprint(const char *fmt, ...) {
    return str_buffer;
 }

-static const char *getline() {
+static const char *mgetline() {
    static char buffer[1024] = {0};
    char *str = fgets(buffer, sizeof(buffer), stdin);
    for (char *p = str; *p; p++) {
@@ -146,11 +146,13 @@ static int open_url(const char *url) {
 }

 static bool pdisasm(vxt_system *s, vxt_pointer start, int size, int lines) {
-   char *name = tmpnam(NULL);
-   if (!name)
+   char name[128];
+   int fh;
+   strncpy(name,"disasm.XXXXXX",sizeof(name)-1);
+   fh = mkstemp(name);
+   if (fh == -1)
        return false;
-   
-   FILE *tmpf = fopen(name, "wb");
+   FILE *tmpf = fdopen(fh, "wb");
    if (!tmpf)
        return false;

@@ -402,7 +404,7 @@ int ENTRY(int argc, char *argv[]) {

    struct vxt_pirepheral *dbg = NULL;
    if (args.debug) {
-       struct vxtu_debugger_interface dbgif = {&pdisasm, &getline, &printf};
+       struct vxtu_debugger_interface dbgif =  {&pdisasm, &mgetline, &printf}; 
        dbg = vxtu_debugger_create(&vxt_clib_malloc, &dbgif);
    }

I have both ARM and x86, so can test both ways. I do most of my development on Ubuntu and FreeBSD though.

andreas-jonsson commented 2 years ago

Fixed in develop. OSX CI is enabled.