Fails to build on NetBSD.
- NetBSD supports POSIX API and so this change skips the pragma warning.
elf$ git diff
diff --git a/dependencies/miniz/miniz.c b/dependencies/miniz/miniz.c
index e6501010..a60ca1af 100644
--- a/dependencies/miniz/miniz.c
+++ b/dependencies/miniz/miniz.c
@@ -3165,7 +3165,7 @@ static int mz_stat64(const char *path, struct __stat64 *buffer)
#define MZ_FREOPEN(p, m, s) freopen64(p, m, s)
#define MZ_DELETE_FILE remove
-#elif defined(__APPLE__) || defined(__FreeBSD__)
+#elif defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__)
#ifndef MINIZ_NO_TIME
#include <utime.h>
#endif
elf$
- With the above change this error occurs. I have not looked into at this time.
[ 71%] Building C object CMakeFiles/c3c.dir/src/utils/whereami.c.o
/usr/local/src/c3c/src/utils/whereami.c: In function 'get_executable_path_raw':
/usr/local/src/c3c/src/utils/whereami.c:404:17: error: 'free' called on unallocated object 'buffer1' [-Werror=free-nonheap-object]
404 | free(path);
| ^~~~~~~~~~
/usr/local/src/c3c/src/utils/whereami.c:353:14: note: declared here
353 | char buffer1[PATH_MAX];
| ^~~~~~~
cc1: all warnings being treated as errors
In get_executable_path_raw() both buffer1 and buffer2 are local variables, so impossible to free via path. See patch.
diff --git a/dependencies/miniz/miniz.c b/dependencies/miniz/miniz.c
index e6501010..a60ca1af 100644
--- a/dependencies/miniz/miniz.c
+++ b/dependencies/miniz/miniz.c
@@ -3165,7 +3165,7 @@ static int mz_stat64(const char *path, struct __stat64 *buffer)
#define MZ_FREOPEN(p, m, s) freopen64(p, m, s)
#define MZ_DELETE_FILE remove
-#elif defined(__APPLE__) || defined(__FreeBSD__)
+#elif defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__)
#ifndef MINIZ_NO_TIME
#include <utime.h>
#endif
diff --git a/src/utils/whereami.c b/src/utils/whereami.c
index ada53124..bc3c6d2b 100644
--- a/src/utils/whereami.c
+++ b/src/utils/whereami.c
@@ -399,11 +399,6 @@ static int get_executable_path_raw(char *out, int capacity, int *dirname_length)
break;
}
- if (path != buffer1)
- {
- free(path);
- }
-
return length;
}
I've updated whereami.c now, does it work better?
What is the state of this now?
After pulling and rebuilding on NetBSD, part 1 of the OP...
diff --git a/dependencies/miniz/miniz.c b/dependencies/miniz/miniz.c
index e6501010..a60ca1af 100644
--- a/dependencies/miniz/miniz.c
+++ b/dependencies/miniz/miniz.c
@@ -3165,7 +3165,7 @@ static int mz_stat64(const char *path, struct __stat64 *buffer)
#define MZ_FREOPEN(p, m, s) freopen64(p, m, s)
#define MZ_DELETE_FILE remove
-#elif defined(__APPLE__) || defined(__FreeBSD__)
+#elif defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__)
#ifndef MINIZ_NO_TIME
#include <utime.h>
#endif
Was missing from the updated pulled source.
Applying the above change, c3c builds clean. I could not find mention of running a test suite other than this ./c3c compile ../resources/examples/hash.c3 (which does not compile clean).
elf$ ./c3c compile ../resources/examples/hash.c3
1: module std::io::os;
2: import libc, std::os, std::io;
3:
4: fn void? native_stat(Stat* stat, String path) @if(env::DARWIN || env::LINUX || env::ANDROID || env::BSD_FAMILY) => |
^^^^^
(/usr/local/src/c3c/lib/std/io/os/fileinfo.c3:4:22) Error: 'Stat' could not be found, did you spell it right?
6:
7: struct Posix_dirent
8: {
9: Ino_t d_fileno;
^^^^^
(/usr/local/src/c3c/lib/std/os/posix/files.c3:9:2) Error: 'Ino_t' could not be found, did you spell it right?
elf$
Is it still not working?
The suggested test example:
./c3c compile-run ../resources/testfragments/helloworld.c3
Continues to generate errors.
What's necessary is to create a netbsd.c3 file next to these: https://github.com/c3lang/c3c/blob/master/lib/std/libc/os/freebsd.c3 https://github.com/c3lang/c3c/blob/master/lib/std/libc/os/openbsd.c3
With the correct sizes. It ought to compile then. Are you able to check the layouts?
What's necessary is to create a netbsd.c3 file next to these: https://github.com/c3lang/c3c/blob/master/lib/std/libc/os/freebsd.c3 https://github.com/c3lang/c3c/blob/master/lib/std/libc/os/openbsd.c3
With the correct sizes. It ought to compile then. Are you able to check the layouts?
Oh. I'll have a stickybeak.
Any progress?
I started on it, but was distracted before I could verify I had it correct. I'll build/test over the weekend and answer.
Great!
Ping
Sorry. Resuming work on it today.
So I've synced my repo tried to build only to find now that you need -Wno-char-subscripts; I've added to CMakeLists.txt, but I'm no CMake boffin (prefer classic make(1)). With that it builds.
Next I try this...
elf$ ./c3c compile ../resources/examples/hash.c3
9: alias Blkcnt_t = long;
10: alias Blksize_t = int;
11: alias Fflags_t = uint;
12: alias Off_t = long;
^^^^^^^^^^^^
(/home/achowe/git/c3c/lib/std/libc/os/netbsd.c3:12:7) Error: 'Off_t' would shadow a previous declaration.
80: const bool BSD_FLAVOR_SIG @local = env::DARWIN || env::BSD_FAMILY;
81:
82: alias Time_t = $typefrom(env::WIN32 ? long.typeid : CLong.typeid);
83: alias Off_t = $typefrom(env::WIN32 ? int.typeid : usz.typeid);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
(/home/achowe/git/c3c/lib/std/libc/libc.c3:83:7) Note: The previous use of 'Off_t' was here.
Which I half expected to fail.
-
First
Off_tshould be a signed type if it matchesoff_tas used bylseek,fseeko,ftellosince it possible to seek relative the current file positionSEEK_CUR(see SUS). So making it anusz.typeidmight be wrong idea. -
I do not know
c3cyet (thus reason I want to build it to try). Is there some way tounaliasor override an alias (suppose I need learn$typefromsyntax)? I suppose I could create a (temporary)posix_off_tfor the purpose of testing stuff.
So that's where I'm at for the moment.
Hey folks. I've made some progress on this. I've got c3c building and seemingly working at least for basic stuff on NetBSD aarch64. I chose aarch64 because that's what I have, and also the NetBSD community spends a lot of time developing on arm machines.
I replicated the changes discussed above and added a lib/std/libc/os/netbsd.c3. I based the type sizes and the layout of the Stat struct on the NetBSD man pages along with what was actually in the <sys/stat.h> header on NetBSD, so I think it's basically right, but I haven't tested extensively yet. At the very least, it's a start, I think.
To get the compiler working on NetBSD aarch64 I also had to add some stuff so that the proper setjmp size gets set and so that llvm compiles and links properly.
In line with the discussion above, I also changed the default for Off_t to isz, since it should be signed on POSIX platforms. isz isn't quite correct, since I believe there are OSes where off_t is always 64 bits (even on 32-bit platforms), but I think it's a better default than usz.
I haven't added any tests yet as I was just trying to see if I could get it to build and run, and these changes are just kind of the minimum necessary to get something working, but here's what I've got so far https://github.com/c3lang/c3c/compare/master...limit-ordinal:c3c:netbsd-aarch64-compile
With the compiler building and running on NetBSD, I'm now trying to get things to the point where tests are all passing and the main compiler features work.
EDIT: All unit tests are now passing, as is the compiler test suite! Getting pretty close to done with this. I still need to manually check some things and add CI.
The diff for your convenience: https://github.com/c3lang/c3c/compare/master...limit-ordinal:c3c:netbsd-aarch64-compile