Add Builtin.ifdef_<FLAGNAME> as a facility to peek at -D flag that client code is building with (#39797)

This commit is contained in:
Kuba (Brecka) Mracek
2021-10-21 15:36:47 -07:00
committed by GitHub
parent 223dbd445b
commit b413a0f4dd
13 changed files with 112 additions and 13 deletions

View File

@@ -0,0 +1,34 @@
// RUN: %empty-directory(%t)
// RUN: %target-build-swift %s -parse-stdlib -whole-module-optimization -D LIBRARY -emit-module -o %t/Library.swiftmodule
// RUN: %target-build-swift %s -parse-stdlib -whole-module-optimization -D LIBRARY -emit-bc -o %t/Library.bc
// RUN: %target-build-swift %s -parse-as-library -D CLIENT -I %t -o %t/R1 -O && %target-run %t/R1 | %FileCheck %s
// RUN: %target-build-swift %s -parse-as-library -D CLIENT -I %t -o %t/R2 -O -D FOO_BAR && %target-run %t/R2 | %FileCheck %s --check-prefix CHECK-FOO-BAR
// REQUIRES: executable_test
#if LIBRARY
@_alwaysEmitIntoClient
public func ifdefFooBar() -> Builtin.Int1 {
return Builtin.ifdef_FOO_BAR()
}
#endif
#if CLIENT
import Library
@_cdecl("main")
func main() -> Int32 {
print("Hello")
print(Bool(_builtinBooleanLiteral: ifdefFooBar()))
// CHECK: Hello
// CHECK: false
// CHECK-FOO-BAR: Hello
// CHECK-FOO-BAR: true
return 0
}
#endif