Repository navigation
WIP: OpenBSD port - #1921
WIP: OpenBSD port#1921tleguern wants to merge 2 commits into
Conversation
|
This needs an OpenBSD 6.4-current as the work on llvm 7 landed in ports recently. |
Hmm I don't really see this as a problem. Of all the places in the codebase, the operating system ifdefs have been one of the least buggy. Of course, feel free to suggest any improvements. |
|
This pull request says WIP, but it looks good to merge as is. Would you like me to wait? |
|
If expanding the list of defines with ZIG_OS_NETBSD and ZIG_OS_DRAGONFLY in the future is not a problem for you then it is absolutely fine for me too. I marked this pull request as WIP as the port of stage 1 is definitely not finished but if you prefer smaller patches then tell me and merge this. |
There was a problem hiding this comment.
Just to double check- what methodology are you using to get these definitions?
There was a problem hiding this comment.
I checked in /usr/include/errno.h which define errno this way:
#ifndef errno
int *__errno(void);
#define errno (*__errno())
#endif /* errno */
There was a problem hiding this comment.
OK great, that's perfect. Note that you can use zig translate-c /usr/include/errno.h (or any .h file, or an .h file that includes a bunch of .h files) to spit out Zig declarations. It will figure out some macros too, although I'm not sure it's sophisticated enough (yet) to figure out that errno one.
The auto translated declarations often still require "cleanup" - e.g. if it's a pointer sometimes it should be changed be non-null, or single-item.
There was a problem hiding this comment.
Great ! It is capable of finding this prototype:
pub extern fn __errno() ?[*]c_int;
There was a problem hiding this comment.
Great indeed - and that's exactly the cleanup I mentioned above - which you already did, changing ?[*]c_int to *c_int. Also adding "c" as you did 👍 that will help at least with #1698
There was a problem hiding this comment.
what you have here is fine, but if you do it like this, you can keep flags as a comptime-known value (and avoid var in favor of const):
const largefile = if (builtin.os == builtin.Os.linux) posix.O_LARGEFILE else 0;
const flags = posix.O_WRONLY | posix.O_CREAT | posix.O_CLOEXEC | posix.O_TRUNC | largefile;There was a problem hiding this comment.
why is this one unreachable? is it documented to happen only when you give bad inputs to dup2?
There was a problem hiding this comment.
This is an error on my part. EIO is documented in case of filesystem errors, although I am not sure in which conditions it can be triggered.
There was a problem hiding this comment.
In this case I think it should be exposed as a possible error. If dup2 can cause a file system error, then zig code should be able to handle that error.
There was a problem hiding this comment.
I believe this zig code is correct, but, imagine asking the kernel for the current working directory, and the response is "sorry, I can't tell you, I'm out of memory". Seems like an unfortunate limitation in the kernel design to me :-(
There was a problem hiding this comment.
This behaviour is shared by NetBSD and FreeBSD, according to their man pages.
|
Can we get an official statement from an OpenBSD developer or from the official documentation that says that the stable syscall ABI is libc, unlike in Linux where application code can directly invoke the syscall interrupt instruction? |
|
I am not an OpenBSD developer but as far as I know the kernel ABI is not stable but libc is. |
|
By the way @Aversiste, I'm not sure what your relative interest in OpenBSD and NetBSD is, but according to What's cooking on SourceHut February 2019 they're going to have NetBSD builds available soon, but OpenBSD still not announced yet. We can for sure merge a pull request that improves Zig's OpenBSD support, but to achieve Tier 1, we will have to get CI going. |
|
I reached Drew by email before the rebranding and he said OpenBSD support was planned. He needs the time to become more knowledgeable in automating OpenBSD builds, which is understandable. For my part this is the system I use everyday on my servers as well as on my primary laptop. |
|
Rebased after merge of #1972. |
|
Looks like your rebase accidentally modified the commits from master branch. I recommend to forget about your git commit history in this branch and just fix it so that this PR only has 1 commit on top of master (you can do this without messing with git too much) |
796e8f6 to
03ae6a7
Compare
|
The first-stage compiler is now capable of building executables : I need to finish the libc wrappers, almost there :) |
|
Rebased against master. |
|
Is this still being worked on? |
|
@HarrisDakota I'm sure @Aversiste wouldn't mind if you forked from their branch and continued working on this in a new pull request. Next time I would recommend merging earlier, to prevent conflicts against master branch. |
|
@andrewrk oh I'm not skilled enough to help port this kind of project, sorry. But the language is interesting, |
|
@HarrisDakota currently not as good old friend anxiety came back knocking at my door. @andrewrk effectively merging earlier might have helped as other people could jump. I will try to rebase again to leave something usable. |
|
I linked to this work-in-progress code in #2016 (comment) so that folks can find it. Until it's ready for review I'm going to close this. |
This a work in progress port to OpenBSD. Not much to see for now but at least the first stage build until
bin/zig build --build-file ../build.zig test.I will probably implement the same first part on NetBSD — unless someone is working on it — in order to look for a cleaner alternative to all these
defined(ZIG_OS_FREEBSD) || defined(ZIG_OS_OPENBSD) || ...that are going to expand forever.