Skip to content

WIP: OpenBSD port - #1921

Closed
tleguern wants to merge 2 commits into
ziglang:masterfrom
tleguern:openbsd
Closed

tleguern wants to merge 2 commits into
ziglang:masterfrom
tleguern:openbsd

Conversation

@tleguern

@tleguern tleguern commented Feb 6, 2019

Copy link
Copy Markdown

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.

@tleguern

tleguern commented Feb 6, 2019

Copy link
Copy Markdown
Author

This needs an OpenBSD 6.4-current as the work on llvm 7 landed in ports recently.

@andrewrk

andrewrk commented Feb 6, 2019

Copy link
Copy Markdown
Member

cleaner alternative to all these defined(ZIG_OS_FREEBSD) || defined(ZIG_OS_OPENBSD) || ... that are going to expand forever.

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.

@andrewrk

andrewrk commented Feb 6, 2019

Copy link
Copy Markdown
Member

This pull request says WIP, but it looks good to merge as is. Would you like me to wait?

@tleguern

tleguern commented Feb 6, 2019

Copy link
Copy Markdown
Author

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.

Comment thread std/c/openbsd.zig Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just to double check- what methodology are you using to get these definitions?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I checked in /usr/include/errno.h which define errno this way:

#ifndef errno
int *__errno(void);
#define errno (*__errno())
#endif /* errno */

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Great ! It is capable of finding this prototype:

pub extern fn __errno() ?[*]c_int;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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

Comment thread std/os/file.zig Outdated

@andrewrk andrewrk Feb 8, 2019 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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;

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Good point, thanks.

Comment thread std/os/index.zig Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

why is this one unreachable? is it documented to happen only when you give bad inputs to dup2?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Comment thread std/os/index.zig Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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 :-(

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

This behaviour is shared by NetBSD and FreeBSD, according to their man pages.

@andrewrk

andrewrk commented Feb 8, 2019

Copy link
Copy Markdown
Member

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?

@tleguern

tleguern commented Feb 8, 2019

Copy link
Copy Markdown
Author

I am not an OpenBSD developer but as far as I know the kernel ABI is not stable but libc is.

@andrewrk

andrewrk commented Feb 16, 2019 •

Copy link
Copy Markdown
Member

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.

@tleguern

Copy link
Copy Markdown
Author

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.

@tleguern

Copy link
Copy Markdown
Author

Rebased after merge of #1972.

@andrewrk

Copy link
Copy Markdown
Member

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)

@tleguern
tleguern force-pushed the openbsd branch 2 times, most recently from 796e8f6 to 03ae6a7 Compare February 18, 2019 16:59
Comment thread std/os/openbsd/index.zig Resolved
@tleguern

Copy link
Copy Markdown
Author

The first-stage compiler is now capable of building executables :

$ ./zig build-exe hello.zig
$ ./hello                  
Hello, world!
reached unreachable codeAbort trap (core dumped) 

I need to finish the libc wrappers, almost there :)

Comment thread std/os/openbsd/index.zig Resolved
@tleguern

Copy link
Copy Markdown
Author

Rebased against master.

@ghost

ghost commented Mar 25, 2019

Copy link
Copy Markdown

Is this still being worked on?

@andrewrk

Copy link
Copy Markdown
Member

@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.

@ghost

ghost commented Mar 25, 2019

Copy link
Copy Markdown

@andrewrk oh I'm not skilled enough to help port this kind of project, sorry. But the language is interesting,

@tleguern

Copy link
Copy Markdown
Author

@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.

@andrewrk

Copy link
Copy Markdown
Member

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.

@andrewrk andrewrk closed this Apr 29, 2019
@abdelq abdelq mentioned this pull request May 12, 2020
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.

2 participants