mesonbuild / meson

The Meson Build System
http://mesonbuild.com
Apache License 2.0
5.51k stars 1.6k forks source link

More granularity in Darwin OS flavors #7944

Open ubitux opened 3 years ago

ubitux commented 3 years ago

Describe the bug

The darwin system identifier is shared between macOS and iOS (and other tvOS etc). Since frameworks typically differ between those, it is common to manually detect the OS with code such as:

host_system = host_machine.system()

iphone_check = '''#include <TargetConditionals.h>
#if !TARGET_OS_IPHONE
#error not iphone
#endif'''
if host_system == 'darwin' and cc.compiles(iphone_check, name: 'iPhone target')
  host_system = 'iphone'
endif

Details on the TARGET_OS_*:

    TARGET_OS_* 
    These conditionals specify in which Operating System the generated code will
    run.  Indention is used to show which conditionals are evolutionary subclasses.  

    The MAC/WIN32/UNIX conditionals are mutually exclusive.
    The IOS/TV/WATCH conditionals are mutually exclusive.

        TARGET_OS_WIN32           - Generated code will run under 32-bit Windows
        TARGET_OS_UNIX            - Generated code will run under some Unix (not OSX) 
        TARGET_OS_MAC             - Generated code will run under Mac OS X variant
           TARGET_OS_IPHONE          - Generated code for firmware, devices, or simulator 
              TARGET_OS_IOS             - Generated code will run under iOS 
              TARGET_OS_TV              - Generated code will run under Apple TV OS
              TARGET_OS_WATCH           - Generated code will run under Apple Watch OS
           TARGET_OS_SIMULATOR      - Generated code will run under a simulator
           TARGET_OS_EMBEDDED       - Generated code for firmware

        TARGET_IPHONE_SIMULATOR   - DEPRECATED: Same as TARGET_OS_SIMULATOR
        TARGET_OS_NANO            - DEPRECATED: Same as TARGET_OS_WATCH

Source: https://github.com/mstg/iOS-full-sdk/blob/master/iPhoneOS9.3.sdk/usr/include/TargetConditionals.h

Could we have a more specific value returned by host_machine.system()?

Or maybe some sort of flavor/distrib method? We would typically have system='darwin' and flavor={'ios','tv','watch',...}. On Linux it could be system='linux' and flavor={'debian','ubuntu','fedora','centos',...}

dcbaker commented 3 years ago

I think this is a specific case of: https://github.com/mesonbuild/meson/issues/6361

singalen commented 3 years ago

The new MacOS for arm64 is worth mentioning.

egirault commented 2 years ago

+1 on this. Right now, both M1-based macs (arm64) and iOS devices have:

[host_machine]
system = 'darwin'
cpu_family = 'aarch64'
cpu = 'aarch64'
endian = 'little'

This makes it unpractical to distinguish between them, and forces the user to rely on hacks like @ubitux described.

chrishecker commented 1 year ago

Any progress on this or #6361? Assuming not, what is the best practice way of specifying macos vs ios in your meson.build files? It looks like deep inside meson https://github.com/mesonbuild/meson/blob/4f4076bfc0dacbc5f804ad2d970054ab43d162b3/mesonbuild/envconfig.py#L309 there's a system check for 'darwin', 'ios', and 'tvos' but does that get out in the host_machine.system() call? I assume not since it's not in the reference table. It also looks like inside meson there's a lib check for UIKit as the ios vs macos test https://github.com/mesonbuild/meson/blob/59d4f771d280cbea0d0afc9579e127225751c028/test%20cases/osx/4%20framework/meson.build#L17 (edit: I didn't notice this was in a test script when I posted this, not meson main) which seems kinda hacky, but I guess works at least for tvos and ios. I guess for now I'll make a global darwin_type string at the top of the main meson file? Or go all the way to host_machine_system_flavor and have it deal with android abis and linux distros and stuff, under the assumption that host_machine.flavor() will happen at some point? What's the best practice here?

Thanks, Chris