Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Absorb platform detection hacks from jnr projects #260

Closed
headius opened this issue Aug 16, 2021 · 4 comments · Fixed by #271 or #272
Closed

Absorb platform detection hacks from jnr projects #260

headius opened this issue Aug 16, 2021 · 4 comments · Fixed by #271 or #272
Milestone

Comments

@headius
Copy link
Member

headius commented Aug 16, 2021

In jnr/jnr-enxio#39 we see the latest hack to detect platform, in this case detecting FreeBSD 12. A similar hack was done to jnr-posix, which contains many other such hacks to detect libc version on Linux and specific levels of *BSD. These platform-detection tricks are needed by nearly all consumers of jnr-ffi, so we should combine them and formalize the Platform API to be uniform for all jnr-ffi consumers.

@basshelal
Copy link
Contributor

I can add the code from jnr/jnr-enxio#39 myself in some neat way it's just the code that checks if FreeBSD is version > 12 right?
Could add a new Platform instance to Platform.java called FreeBSD with a getVersion() method using the same hack logic, that way back in jnr/jnr-enxio#39 it would be as simple as:

if (Platform.getNativePlatform().getOS() == Platform.OS.FREEBSD) {
    FreeBSD freeBSD = (Platform.FreeBSD) Platform.getNativePlatform();
    int version = freeBSD.getVersion();
    if (version >= 12) {
        // do FreeBSD 12+ stuff
    } else {
       // do legacy stuff
    }
}

@headius Point me to the other hacks you're mentioning and I'll see if I can incorporate them in an elegant way as well. I won't be able to test any BSD code myself (never had any experience using a BSD) so I will have to assume the code I will bring in is correct.

@headius
Copy link
Member Author

headius commented Sep 9, 2021

I poked around jnr-posix and found the following:

Additionally, jnr-constants has some suspiciously similar macros and platform lookup logic here: https://github.com/jnr/jnr-constants/blob/1d006ac75cdbab78491f22796f3e84e5be918b71/src/main/java/jnr/constants/PlatformConstants.java

I looked over jnr-unixsocket and did not see anything that looked like platform detection.

@headius
Copy link
Member Author

headius commented Sep 9, 2021

I should mention that some of the Linux platform detection logic is to differentiate glibc from e.g. musl, which I think is appropriate to leave in jnr-posix.

@basshelal
Copy link
Contributor

Ok the version numbering hack has been added in #270

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants