skip icon indicating copy to clipboard operation
skip copied to clipboard

docs: Clarify conditional compilation restrictions with an example

Open dfabulich opened this issue 10 months ago • 0 comments

https://skip.tools/docs/platformcustomization/#compiler-directives includes this warning:

Because the Skip tooling does not know the value of any symbols other than os(Android) and !os(Android), we strongly recommend adding os(Android) or !os(Android) conditions to all #if blocks, so that it is clear whether Skip should include or exclude the code for Android.

That line made no sense at all to me when I read it.

What it means to say is that #if !os(macOS) won't work, which is filed as #342. You have to rewrite it as #if !os(macOS) || os(Android).

The documentation would be much clearer with an example of issue #342 and the recommended workaround.

For example, this won't work, because Skip doesn't understand the symbol os(macOS), or its negation !os(macOS).

Text("Hello World")
    #if !os(macOS)
    // BUG this won't run on Android
    .italic()
    #endif

Instead, use an "unnecessary" os(Android):

Text("Hello World")
    #if !os(macOS) || os(Android)
    .italic()
    #endif

We hope to address this issue in a future version of Skip.

dfabulich avatar Feb 17 '25 20:02 dfabulich