Skip to content

[RFC] Steps toward OpenBSD support #1945

@CodeTriangle

Description

@CodeTriangle

Hey all. Experienced Python programmer and beginner Rustacean here. Never heard that one before, right. Anyway, I'm super glad this project exists!

Summary

I'm on OpenBSD and am having trouble building the RustPython Virtual Machine due to (completely reasonable) assumptions about the universal nature of *nix system flags that OpenBSD does not implement or implements differently.

Detailed Explanation

The following are the variables I found that were undefined:

Errors

  • ENODATA: Used once in Lib/shutil.py in a conditional statement that is never reached because OpenBSD does not support extended attributes.
  • EMULTIHOP ENOLINK ENOSTR ENOSR ETIME: Unused in RustPython and CPython.

These errors are all defined in errno.rs. This file includes a lot of provisions about operating systems but assumes that all the error codes it imports from libc and then looks for are defined. CPython's implementation of the same idea has a much more exhaustive list of error codes, but each is surrounded by #ifdef/#endif preprocessor tags, avoiding lots of errors. Unfortunately, I do not believe there's an equivalent in Rust for this, but there's gotta be a fairly painless solution out there.

Socket constants

  • AI_ALL: The compiler expects libc to define this, but OpenBSD doesn't implement it.
  • AI_PASSIVE: OpenBSD does implement this one, but libc does not define it.

As far as I can tell, in fact, none of the constants for addrinfo's ai_flags are defined by libc for OpenBSD. This might be a problem with libc, but I'm not well-versed enough in the way that repository works to come to any conclusion without conjecture.

Functions

  • getgroups: Required once in os.rs. I found that nix::unistd defined this function, just like on linux and android, so I added a target_os = "openbsd" and that seemed to fix it. Perhaps other *nixes also have this problem? Might be worth looking into.
  • os_umask: Also required once by os.rs. Fixed in a similar fashion to getgroups.

Miscellaneous system stuff

  • getresuid getresgid: Yet more things that it appears libc should be providing for us but aren't. setresuid and setresgid are indeed provided by libc, but not the gets for some reason.
  • getregid: It doesn't seem like libc provides this one either.
  • SIGPWR SIGSTKFLT: Signals for power cut and stack fault, respectively. Both unused by OpenBSD. I added another target_os = "openbsd" to the cfg surrounding their occurrences. Other operating systems might have similar problems and may need to be added to this cfg.

MetadataExt

  • A lot of functions were missing from os.rs due to its inability to find the MetadataExt trait. I just found the appropriate line and added the relevant OpenBSD use.
    • Fixing this caused another issue: ModeT was not defined. I added a definition here

Conclusion

I added whatever support I could. I'm not that great at Rust; neither am I that great at *nix. But I did manage to cull down the errors from 24 to 5 in a couple of hours. I'm definitely willing to contribute to OpenBSD support in the future, assuming you folks are willing to help me out wherever my knowledge is lacking.

My personal branch for those who want to see the end results of my finagling. This should get you far less errors compiling for OpenBSD.

Metadata

Metadata

Assignees

No one assigned

    Labels

    RFCRequest for comments

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions