diff --git a/.github/workflows/lagom-template.yml b/.github/workflows/lagom-template.yml index fd6c41b4911..33962e9cc7a 100644 --- a/.github/workflows/lagom-template.yml +++ b/.github/workflows/lagom-template.yml @@ -149,7 +149,8 @@ jobs: - name: Enable the AppKit chrome with Swift files if: ${{ inputs.os_name == 'macOS' && inputs.fuzzer == 'NO_FUZZ' }} working-directory: ${{ github.workspace }} - run: cmake -B Build -DENABLE_QT=OFF -DENABLE_SWIFT=ON + # FIXME: Don't force release build after https://github.com/LadybirdBrowser/ladybird/issues/1101 is fixed + run: cmake -B Build -DENABLE_QT=OFF -DENABLE_SWIFT=ON -DCMAKE_BUILD_TYPE=RelWithDebInfo - name: Build the AppKit chrome with Swift files if: ${{ inputs.os_name == 'macOS' && inputs.fuzzer == 'NO_FUZZ' }} diff --git a/Tests/AK/CMakeLists.txt b/Tests/AK/CMakeLists.txt index ef7763e276e..4a4918b1669 100644 --- a/Tests/AK/CMakeLists.txt +++ b/Tests/AK/CMakeLists.txt @@ -91,3 +91,10 @@ foreach(source IN LISTS AK_TEST_SOURCES) endforeach() target_link_libraries(TestString PRIVATE LibUnicode) + +if (ENABLE_SWIFT) + add_executable(TestAKBindings TestAKBindings.swift) + target_link_libraries(TestAKBindings PRIVATE AK) + target_compile_options(TestAKBindings PRIVATE -parse-as-library) + add_test(NAME TestAKBindings COMMAND TestAKBindings) +endif() diff --git a/Tests/AK/TestAKBindings.swift b/Tests/AK/TestAKBindings.swift new file mode 100644 index 00000000000..37211c021d4 --- /dev/null +++ b/Tests/AK/TestAKBindings.swift @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2024, Andrew Kaster + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +import AK +import Foundation + +protocol ConformanceMarker {} +enum CxxSequenceMarker {} +extension CxxSequenceMarker: ConformanceMarker where T: CxxSequence {} +private func isCxxSequenceType(_ type: borrowing T.Type) -> Bool { + return CxxSequenceMarker.self is ConformanceMarker.Type +} + +class StandardError: TextOutputStream { + func write(_ string: Swift.String) { + try! FileHandle.standardError.write(contentsOf: Data(string.utf8)) + } +} + +@main +struct TestAKBindings { + static func testSequenceTypesAreBound() { + var standardError = StandardError() + print("Testing CxxSequence types...", to: &standardError) + + precondition(isCxxSequenceType(AK.StringView.self)) + precondition(isCxxSequenceType(AK.Bytes.self)) + precondition(isCxxSequenceType(AK.ReadonlyBytes.self)) + precondition(isCxxSequenceType(AK.Utf16Data.self)) + + precondition(!isCxxSequenceType(AK.Utf16View.self)) + precondition(!isCxxSequenceType(AK.String.self)) + + precondition(!isCxxSequenceType(AK.Error.self)) + + print("CxxSequence types pass", to: &standardError) + } + + static func main() { + var standardError = StandardError() + print("Starting test suite...", to: &standardError) + testSequenceTypesAreBound() + + print("All tests pass", to: &standardError) + } +}