Previously platform-specific types and members were decorated with [ExportCondition]
attributes for conditional usage by different build targets. Because attribues requires compilation before the information can be properly resolved, we’ve introduced a new extern(EXPRESSION)
modifier in order to cull these entities before anything is compiled. This reduces the work load for the compiler significantly.
In addition, if defined(EXPRESSION)
syntax is introduced for conditional compilation. If EXPRESSION
evaluates to false, code inside the block won’t be compiled because entities referred inside the block might have been culled (producing compile error). defined(EXPRESSION) ?:
expressions implements the same behaviour.
In order to stay backwards compatible in most cases, [ExportCondition("EXPRESSION")]
is automatically rewritten to extern(EXPRESSION)
by the parser. Code like if (defined(ANDROID) || defined(IOS))
is rewritten to if defined(ANDROID || IOS)
when possible. More advanced cases must be broken up by hand.
Any compile errors introduced by upgrading to this version can usually be fixed by adding if defined(...)
tests or extern(...)
modifiers. Otherwise help is available on slack.
Before:
[ExportCondition("ANDROID")]
class AndroidClass
{
}
After:
extern(ANDROID) class AndroidClass
{
}
This change in behaviour also happens to make things like this now possible:
class Foo
{
extern(ANDROID) void Bar()
{
// Android specific code
}
extern(IOS) void Bar()
{
// iOS specific code
}
void Method()
{
if defined(ANDROID || IOS)
Bar();
}
}