@@ -1577,8 +1577,8 @@ final class BuildPlanTests: XCTestCase {
1577
1577
func testWindowsTarget( ) throws {
1578
1578
let fs = InMemoryFileSystem ( emptyFiles:
1579
1579
" /Pkg/Sources/exe/main.swift " ,
1580
- " /Pkg/Sources/lib/lib.c " ,
1581
- " /Pkg/Sources/lib/include/lib.h "
1580
+ " /Pkg/Sources/lib/lib.c " ,
1581
+ " /Pkg/Sources/lib/include/lib.h "
1582
1582
)
1583
1583
1584
1584
let diagnostics = DiagnosticsEngine ( )
@@ -1603,8 +1603,10 @@ final class BuildPlanTests: XCTestCase {
1603
1603
result. checkTargetsCount ( 2 )
1604
1604
1605
1605
let lib = try result. target ( for: " lib " ) . clangTarget ( )
1606
- var args = [ " -target " , " x86_64-unknown-windows-msvc " , " -g " , " -gcodeview " , " -O0 " , " -DSWIFT_PACKAGE=1 " , " -DDEBUG=1 " ]
1607
- args += [ " -fblocks " , " -I " , " /Pkg/Sources/lib/include " ]
1606
+ let args = [
1607
+ " -target " , " x86_64-unknown-windows-msvc " , " -g " , " -gcodeview " , " -O0 " ,
1608
+ " -DSWIFT_PACKAGE=1 " , " -DDEBUG=1 " , " -fblocks " , " -I " , " /Pkg/Sources/lib/include "
1609
+ ]
1608
1610
XCTAssertEqual ( lib. basicArguments ( ) , args)
1609
1611
XCTAssertEqual ( lib. objects, [ AbsolutePath ( " /path/to/build/debug/lib.build/lib.c.o " ) ] )
1610
1612
XCTAssertEqual ( lib. moduleMap, AbsolutePath ( " /path/to/build/debug/lib.build/module.modulemap " ) )
@@ -1624,6 +1626,80 @@ final class BuildPlanTests: XCTestCase {
1624
1626
XCTAssertMatch ( executablePathExtension, " exe " )
1625
1627
}
1626
1628
1629
+ func testWASITarget( ) throws {
1630
+ let fs = InMemoryFileSystem ( emptyFiles:
1631
+ " /Pkg/Sources/app/main.swift " ,
1632
+ " /Pkg/Sources/lib/lib.c " ,
1633
+ " /Pkg/Sources/lib/include/lib.h "
1634
+ )
1635
+
1636
+ let diagnostics = DiagnosticsEngine ( )
1637
+ let graph = loadPackageGraph (
1638
+ fs: fs, diagnostics: diagnostics,
1639
+ manifests: [
1640
+ Manifest . createV4Manifest (
1641
+ name: " Pkg " ,
1642
+ path: " /Pkg " ,
1643
+ url: " /Pkg " ,
1644
+ packageKind: . root,
1645
+ targets: [
1646
+ TargetDescription ( name: " app " , dependencies: [ " lib " ] ) ,
1647
+ TargetDescription ( name: " lib " , dependencies: [ ] ) ,
1648
+ ] ) ,
1649
+ ]
1650
+ )
1651
+ XCTAssertNoDiagnostics ( diagnostics)
1652
+
1653
+ var parameters = mockBuildParameters ( destinationTriple: . wasi)
1654
+ parameters. shouldLinkStaticSwiftStdlib = true
1655
+ let result = BuildPlanResult (
1656
+ plan: try BuildPlan (
1657
+ buildParameters: parameters,
1658
+ graph: graph,
1659
+ diagnostics: diagnostics,
1660
+ fileSystem: fs
1661
+ )
1662
+ )
1663
+ result. checkProductsCount ( 1 )
1664
+ result. checkTargetsCount ( 2 )
1665
+
1666
+ let lib = try result. target ( for: " lib " ) . clangTarget ( )
1667
+ let args = [
1668
+ " -target " , " wasm32-unknown-wasi " , " -g " , " -O0 " , " -DSWIFT_PACKAGE=1 " , " -DDEBUG=1 " ,
1669
+ " -fblocks " , " -fmodules " , " -fmodule-name=lib " , " -I " , " /Pkg/Sources/lib/include " ,
1670
+ " -fmodules-cache-path=/path/to/build/debug/ModuleCache "
1671
+ ]
1672
+ XCTAssertEqual ( lib. basicArguments ( ) , args)
1673
+ XCTAssertEqual ( lib. objects, [ AbsolutePath ( " /path/to/build/debug/lib.build/lib.c.o " ) ] )
1674
+ XCTAssertEqual ( lib. moduleMap, AbsolutePath ( " /path/to/build/debug/lib.build/module.modulemap " ) )
1675
+
1676
+ let exe = try result. target ( for: " app " ) . swiftTarget ( ) . compileArguments ( )
1677
+ XCTAssertMatch (
1678
+ exe,
1679
+ [
1680
+ " -swift-version " , " 4 " , " -enable-batch-mode " , " -Onone " , " -enable-testing " , " -g " ,
1681
+ . equal( j) , " -DSWIFT_PACKAGE " , " -DDEBUG " , " -Xcc " ,
1682
+ " -fmodule-map-file=/path/to/build/debug/lib.build/module.modulemap " ,
1683
+ " -I " , " /Pkg/Sources/lib/include " ,
1684
+ " -module-cache-path " , " /path/to/build/debug/ModuleCache " , . anySequence
1685
+ ]
1686
+ )
1687
+
1688
+ XCTAssertEqual (
1689
+ try result. buildProduct ( for: " app " ) . linkArguments ( ) ,
1690
+ [
1691
+ " /fake/path/to/swiftc " , " -L " , " /path/to/build/debug " ,
1692
+ " -o " , " /path/to/build/debug/app.wasm " ,
1693
+ " -module-name " , " app " , " -static-stdlib " , " -emit-executable " ,
1694
+ " @/path/to/build/debug/app.product/Objects.LinkFileList " ,
1695
+ " -target " , " wasm32-unknown-wasi "
1696
+ ]
1697
+ )
1698
+
1699
+ let executablePathExtension = try result. buildProduct ( for: " app " ) . binary. extension
1700
+ XCTAssertEqual ( executablePathExtension, " wasm " )
1701
+ }
1702
+
1627
1703
func testIndexStore( ) throws {
1628
1704
let fs = InMemoryFileSystem ( emptyFiles:
1629
1705
" /Pkg/Sources/exe/main.swift " ,
@@ -2627,4 +2703,5 @@ fileprivate extension TSCUtility.Triple {
2627
2703
static let arm64Linux = try ! Triple ( " aarch64-unknown-linux-gnu " )
2628
2704
static let arm64Android = try ! Triple ( " aarch64-unknown-linux-android " )
2629
2705
static let windows = try ! Triple ( " x86_64-unknown-windows-msvc " )
2706
+ static let wasi = try ! Triple ( " wasm32-unknown-wasi " )
2630
2707
}
0 commit comments