Skip to content

macos: add fallback version detection#5125

Merged
mikdusan merged 1 commit into
ziglang:masterfrom
mikdusan:kern.osproductversion
Apr 22, 2020
Merged

macos: add fallback version detection#5125
mikdusan merged 1 commit into
ziglang:masterfrom
mikdusan:kern.osproductversion

Conversation

@mikdusan
Copy link
Copy Markdown
Member

@mikdusan mikdusan commented Apr 21, 2020

Fallback to sysctl kern.osversion when kern.osproductversion is not
available (prior to 10.13.4) .

The mapping from sw_vers -buildVersion to -productVersion is
formulaic from 10.8 to 10.15 and older is handled with switch.

closes #5119

The reasoning behind using a table is we do not yet have std XML to parse /System/Library/CoreServices/SystemVersion.plist and writing a non-robust XML parser has unknown risks; old copies of SystemVersion.plist are hard to come by.

That said, at this time I expect this table fallback will suffice until we get XML. At that time I would recommend we switch methods because it's actually via that file at startup that the kernel gets its product version.

Also I'd like to add this table is based on mapping kern.osversion to kern.osproductversion. To use kern.osrelease (Darwin version) would be difficult -- either the Darwin version tables on wikipedia are incomplete or it does not bump when kern.osproductversion does. For example, Darwin 19.0.0 is inferred to be both macOS 10.15.0 and 10.15.1. source

@mikdusan mikdusan marked this pull request as draft April 21, 2020 19:40
@daurnimator
Copy link
Copy Markdown
Contributor

Got a reference link for the build number mapping?

@mikdusan
Copy link
Copy Markdown
Member Author

Got a reference link for the build number mapping?

yes added with last push

@mikdusan mikdusan added frontend Tokenization, parsing, AstGen, Sema, and Liveness. os-macos macOS labels Apr 21, 2020
@andrewrk
Copy link
Copy Markdown
Member

This looks useful, nice work.

Now that there is a macos-specific non-trivial data listing here, would you mind moving the macos implementation of this function into a macos-specific separate file? For example lib/std/zig/system/macos.zig

@mikdusan mikdusan force-pushed the kern.osproductversion branch from 722ede0 to 0b4a913 Compare April 21, 2020 22:29
Fallback to sysctl `kern.osversion` when `kern.osproductversion` is not
available (prior to 10.13.4) .

The mapping from `sw_vers -buildVersion` to `-productVersion` is
formulaic from 10.8 to 10.15 and older is handled with switch.

closes ziglang#5119
@mikdusan mikdusan force-pushed the kern.osproductversion branch from 0b4a913 to 3df0a3a Compare April 21, 2020 22:38
@mikdusan mikdusan marked this pull request as ready for review April 22, 2020 03:59
@mikdusan mikdusan merged commit 9a06f96 into ziglang:master Apr 22, 2020
@mikdusan mikdusan deleted the kern.osproductversion branch April 22, 2020 19:57
@mikdusan
Copy link
Copy Markdown
Member Author

mikdusan commented Dec 27, 2020

Dear Apple: just because you can, doesn't mean you should™️

Having finally upgraded to Big Sur and look at what happens to a file.. yes a file! This means we can no longer parse /System/Library/CoreServices/SystemVersion.plist as originally planned:

*take note same file being cat'd twice with different results just because of environment variable which does the same thing as if the binary (in this case cat) were built on an pre-Big Sur SDK.

Screen Shot 2020-12-26 at 10 39 27 PM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

frontend Tokenization, parsing, AstGen, Sema, and Liveness. os-macos macOS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Freshly compiled Zig crashes on macOS

3 participants