Files
swift-mirror/test/Interpreter/cdecl_official_run.swift
2025-10-29 17:31:20 -07:00

77 lines
1.9 KiB
Swift

// RUN: %empty-directory(%t)
// RUN: split-file %s %t --leading-lines
/// Generate an internal cdecl.h
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) \
// RUN: %t/Lib.swift -emit-module -verify -o %t -emit-module-doc \
// RUN: -emit-clang-header-path %t/cdecl.h \
// RUN: -disable-implicit-string-processing-module-import \
// RUN: -disable-implicit-concurrency-module-import
/// Build and run a binary from Swift and C code.
// RUN: %clang-no-modules -c %t/Client.c -o %t/Client.o -target %target-triple \
// RUN: %target-pic-opt -I %t -I %clang-include-dir -Werror -isysroot %sdk
// RUN: %target-build-swift %t/Lib.swift %t/Client.o -O -o %t/a.out \
// RUN: -Xfrontend -disable-implicit-string-processing-module-import \
// RUN: -Xfrontend -disable-implicit-concurrency-module-import \
// RUN: -parse-as-library
// RUN: %target-codesign %t/a.out
// RUN: %target-run %t/a.out > %t/run.log
// RUN: %FileCheck %s --input-file %t/run.log
// REQUIRES: executable_test
//--- Lib.swift
/// My documentation
@c(simple) public func simpleNameSwiftSide(x: CInt, bar y: CInt) -> CInt {
print(x, y)
return x
}
@c func defaultName(x: Int) {
print(x)
}
@c public func primitiveTypes(i: Int, ci: CInt, l: CLong, c: CChar, f: Float, d: Double, b: Bool) {
print(i, ci, l, c, f, d, b)
}
@c enum CEnum: CInt { case A, B }
@c func useEnum(e: CEnum) -> CEnum {
print(e)
print(e.rawValue)
return e
}
//--- Client.c
#include <stdio.h>
#include "cdecl.h"
int main() {
int x = simple(42, 43);
// CHECK: 42 43
printf("%d\n", x);
// CHECK-NEXT: 42
defaultName(121);
// CHECK-NEXT: 121
primitiveTypes(1, 2, 3, 'a', 1.0f, 2.0, true);
// CHECK-NEXT: 1 2 3 97 1.0 2.0 true
CEnum a = useEnum(CEnumA);
// CHECK-NEXT: CEnum
// CHECK-NEXT: 0
printf("%d\n", a);
// CHECK-NEXT: 0
CEnum b = useEnum(CEnumB);
// CHECK-NEXT: CEnum
// CHECK-NEXT: 1
printf("%d\n", b);
// CHECK-NEXT: 1
}