Skip to content

Commit e13f38d

Browse files
Re-enable tests (#24)
* [WASM] Re-enable test targets * [WASM] Support WASI OS target for lit.cfg * [WASM] Link wasm32-wasi-unknown to wasm32-wasi * [WASM] Add sysroot to clang_linker to find crt1.o * [WASM] Separate WebAssembly test from linux * [WASM] Add static-executable-args.lnk for wasm * [WASM] First support of wasm in autolink-extract * [WASM] Extract link flags from named data segment from wasm object file * [WASM] Fix stdlib build on Linux * [WASM] Fix ICU lib flag to specify lib file instead of dir * [WASM] wip * [WASM] Iterate all configured sdks * [WASM] Remove object format specific code from macro * [WASM] Copy libswiftImageInspection.a to lib/swift_static/wasi * Use brew installed clang because Xcode version is old * [WASM] Fix new wasm/wasi triple * [WASM] Run executable test on wasmtime * Fix typo * [WASM] Cut environment from triple * Move build script into wasm dir * Run test on CI * Cleanup unused scripts * [WASM] Use -static instead of -static-executable to work emit-library * Proxy arguments to build-script * Ignore test failure temporarily * Fix packing command * Add missing x * Use wasi-sdk's clang compiler * [WASM] Avoid to build BlocksRuntime temporary due to os toolchains's clang limitation * [WASM] Comment out utime.h from glibc * [WASM] Change sysroot dir as wasi-sysroot * [WASM] Avoid to build BlocksRuntime on linux * [WASM] Add mman flag for wasi This eliminate clang hack which defines _WASI_EMULATED_MMAN as a predefined macro in clang ref: swiftlang/llvm-project@swift/master...swiftwasm:swiftwasm#diff-773abe7c69fccf723aa2d75447faa136R63-R66 * [WASM] Use latest wasi-sdk * [WASM] Avoid to build swift-reflection-test temporarily * [WASM] Install wasmtime on CI * [WASM] Set wasm as primary target to avoid to build SwiftRuntimeTests * [WASM] Fix macro arguments validation * [WASM] Copy ICU libs into toolchain * [WASM] Fix to specify libicu on mac * Remove extra space from build scripts
1 parent 4a76eaf commit e13f38d

23 files changed

+427
-192
lines changed

.github/workflows/main.yml

+16-3
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,19 @@ jobs:
1616
steps:
1717
- uses: actions/checkout@v1
1818
- name: Build Linux installable archive
19-
run: ./ci-linux.sh
19+
run: ./utils/webassembly/ci-linux.sh
2020
- name: Upload Linux installable archive
2121
uses: actions/upload-artifact@v1
2222
with:
2323
name: linux-installable
2424
path: ../swiftwasm-linux.tar.gz
25+
- name: Pack test results
26+
run: tar cJf swift-test-results.tar.gz ../build/*/swift-linux-x86_64/swift-test-results
27+
- name: Upload test results
28+
uses: actions/upload-artifact@v1
29+
with:
30+
name: linux-test-results
31+
path: ./swift-test-results.tar.gz
2532

2633
macos_build:
2734
timeout-minutes: 0
@@ -30,7 +37,7 @@ jobs:
3037
steps:
3138
- uses: actions/checkout@v1
3239
- name: Build macOS installable archive
33-
run: ./ci-mac.sh
40+
run: ./utils/webassembly/ci-mac.sh
3441
- name: Upload macOS installable archive
3542
uses: actions/upload-artifact@v1
3643
with:
@@ -41,7 +48,13 @@ jobs:
4148
with:
4249
name: packaging-scripts
4350
path: utils/webassembly
44-
51+
- name: Pack test results
52+
run: tar cJf swift-test-results.tar.gz ../build/*/swift-macosx-x86_64/swift-test-results
53+
- name: Upload test results
54+
uses: actions/upload-artifact@v1
55+
with:
56+
name: macos-test-results
57+
path: ./swift-test-results.tar.gz
4558
package:
4659
name: Build SwiftWasm packages
4760
needs:

CMakeLists.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1117,8 +1117,8 @@ if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
11171117
endif()
11181118

11191119
if(SWIFT_INCLUDE_TESTS)
1120-
#add_subdirectory(test)
1121-
#add_subdirectory(unittests)
1120+
add_subdirectory(test)
1121+
add_subdirectory(unittests)
11221122
endif()
11231123
if(SWIFT_INCLUDE_DOCS)
11241124
add_subdirectory(docs)

build-linux.sh

-30
This file was deleted.

buildstartend.sh

-4
This file was deleted.

ci-linux.sh

-34
This file was deleted.

ci-mac.sh

-21
This file was deleted.

cmake/modules/AddSwift.cmake

+5-1
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,8 @@ function(_add_variant_c_compile_flags)
366366
list(APPEND result -isystem;${path})
367367
endforeach()
368368
list(APPEND result "-D__ANDROID_API__=${SWIFT_ANDROID_API_LEVEL}")
369+
elseif("${CFLAGS_SDK}" STREQUAL "WASI")
370+
list(APPEND result "-D_WASI_EMULATED_MMAN")
369371
elseif(CFLAGS_SDK STREQUAL WINDOWS)
370372
swift_windows_include_for_arch(${CFLAGS_ARCH} ${CFLAGS_ARCH}_INCLUDE)
371373
foreach(path ${${CFLAGS_ARCH}_INCLUDE})
@@ -439,6 +441,8 @@ function(_add_variant_swift_compile_flags
439441
foreach(path IN LISTS ${arch}_swift_include)
440442
list(APPEND result "\"${CMAKE_INCLUDE_FLAG_C}${path}\"")
441443
endforeach()
444+
elseif("${sdk}" STREQUAL "WASI")
445+
list(APPEND result "-Xcc" "-D_WASI_EMULATED_MMAN")
442446
endif()
443447

444448
if(NOT BUILD_STANDALONE)
@@ -552,7 +556,7 @@ function(_add_variant_link_flags)
552556
list(APPEND library_search_directories ${path})
553557
endforeach()
554558
elseif("${LFLAGS_SDK}" STREQUAL "WASI")
555-
# No extra libraries needed.
559+
list(APPEND result "-Wl,wasi-emulated-mman")
556560
else()
557561
# If lto is enabled, we need to add the object path flag so that the LTO code
558562
# generator leaves the intermediate object file in a place where it will not

cmake/modules/SwiftConfigureSDK.cmake

+4-5
Original file line numberDiff line numberDiff line change
@@ -339,11 +339,10 @@ macro(configure_sdk_unix name architectures)
339339
if(NOT arch STREQUAL wasm32)
340340
message(FATAL_ERROR "unsupported arch for WebAssembly: ${arch}")
341341
endif()
342-
set(SWIFT_SDK_WASI_ARCH_wasm32_PATH "${SWIFT_WASI_SDK_PATH}/share/sysroot")
343-
# fixme: Wasi is wasm32-unknown-wasi-musl. This LLVM doesn't have it yet.
344-
set(SWIFT_SDK_WASI_ARCH_wasm32_TRIPLE "wasm32-unknown-unknown-wasi")
345-
set(SWIFT_SDK_WASI_ARCH_wasm32_LIBC_INCLUDE_DIRECTORY "${SWIFT_WASI_SDK_PATH}/share/sysroot/include")
346-
set(SWIFT_SDK_WASI_ARCH_wasm32_LIBC_ARCHITECTURE_INCLUDE_DIRECTORY "${SWIFT_WASI_SDK_PATH}/share/sysroot/include")
342+
set(SWIFT_SDK_WASI_ARCH_wasm32_PATH "${SWIFT_WASI_SDK_PATH}/share/wasi-sysroot")
343+
set(SWIFT_SDK_WASI_ARCH_wasm32_TRIPLE "wasm32-unknown-wasi")
344+
set(SWIFT_SDK_WASI_ARCH_wasm32_LIBC_INCLUDE_DIRECTORY "${SWIFT_WASI_SDK_PATH}/share/wasi-sysroot/include")
345+
set(SWIFT_SDK_WASI_ARCH_wasm32_LIBC_ARCHITECTURE_INCLUDE_DIRECTORY "${SWIFT_WASI_SDK_PATH}/share/wasi-sysroot/include")
347346
else()
348347
message(FATAL_ERROR "unknown Unix OS: ${prefix}")
349348
endif()

lib/Driver/CMakeLists.txt

+40-3
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,8 @@ target_link_libraries(swiftDriver PRIVATE
3333
if(SWIFT_BUILD_STATIC_STDLIB)
3434
set(static_stdlib_lnk_file_list)
3535
foreach(sdk ${SWIFT_CONFIGURED_SDKS})
36-
if("${SWIFT_SDK_${sdk}_OBJECT_FORMAT}" STREQUAL "ELF" OR
37-
"${SWIFT_SDK_${sdk}_OBJECT_FORMAT}" STREQUAL "WASM")
38-
string(TOLOWER "${sdk}" lowercase_sdk)
36+
string(TOLOWER "${sdk}" lowercase_sdk)
37+
if("${SWIFT_SDK_${sdk}_OBJECT_FORMAT}" STREQUAL "ELF")
3938
if(SWIFT_${SWIFT_HOST_VARIANT_SDK}_${SWIFT_HOST_VARIANT_ARCH}_ICU_STATICLIB)
4039
set(ICU_STATICLIB "TRUE")
4140
else()
@@ -62,6 +61,44 @@ if(SWIFT_BUILD_STATIC_STDLIB)
6261
swift_install_in_component(FILES "${SWIFTSTATICLIB_DIR}/${linkfile}"
6362
DESTINATION "lib/swift_static/${lowercase_sdk}"
6463
COMPONENT stdlib)
64+
elseif("${sdk}" STREQUAL "WASI")
65+
set(linkfile_src "${SWIFT_SOURCE_DIR}/utils/webassembly/static-stdlib-args.lnk")
66+
set(linkfile "${lowercase_sdk}/static-stdlib-args.lnk")
67+
add_custom_command_target(swift_static_stdlib_${sdk}_args
68+
COMMAND
69+
"${CMAKE_COMMAND}" -E copy
70+
"${linkfile_src}"
71+
"${SWIFTSTATICLIB_DIR}/${linkfile}"
72+
OUTPUT
73+
"${SWIFTSTATICLIB_DIR}/${linkfile}"
74+
DEPENDS
75+
"${linkfile_src}")
76+
77+
list(APPEND static_stdlib_lnk_file_list ${swift_static_stdlib_${sdk}_args})
78+
swift_install_in_component(FILES "${SWIFTSTATICLIB_DIR}/${linkfile}"
79+
DESTINATION "lib/swift_static/${lowercase_sdk}"
80+
COMPONENT stdlib)
81+
set(swift_icu_libs_wasi_list)
82+
set(icu_modules UC I18N DATA)
83+
foreach(module IN LISTS icu_modules)
84+
set(module_lib "${SWIFT_WASI_wasm32_ICU_${module}}")
85+
get_filename_component(module_lib_name ${module_lib} NAME)
86+
add_custom_command_target(swift_icu_${module}_${sdk}
87+
COMMAND
88+
"${CMAKE_COMMAND}" -E copy
89+
"${module_lib}"
90+
"${SWIFTSTATICLIB_DIR}/${lowercase_sdk}/${module_lib_name}"
91+
OUTPUT
92+
"${SWIFTSTATICLIB_DIR}/${lowercase_sdk}/${module_lib_name}"
93+
DEPENDS
94+
"${module_lib}")
95+
list(APPEND swift_icu_libs_wasi_list ${swift_icu_${module}_${sdk}})
96+
swift_install_in_component(FILES "${SWIFTSTATICLIB_DIR}/${lowercase_sdk}/${module_lib_name}"
97+
DESTINATION "lib/swift_static/${lowercase_sdk}"
98+
COMPONENT stdlib)
99+
endforeach()
100+
add_custom_target(swift_icu_libs_wasi ALL DEPENDS ${swift_icu_libs_wasi_list})
101+
add_dependencies(stdlib swift_icu_libs_wasi)
65102
endif()
66103
endforeach()
67104
add_custom_target(swift_static_lnk_args ALL DEPENDS ${static_stdlib_lnk_file_list})

linkPlease.sh

-17
This file was deleted.

stdlib/public/Platform/glibc.modulemap.gyb

+2
Original file line numberDiff line numberDiff line change
@@ -529,10 +529,12 @@ module SwiftGlibc [system] {
529529
header "${GLIBC_INCLUDE_PATH}/unistd.h"
530530
export *
531531
}
532+
% if CMAKE_SDK != "WASI":
532533
module utime {
533534
header "${GLIBC_INCLUDE_PATH}/utime.h"
534535
export *
535536
}
537+
% end
536538
}
537539
}
538540

0 commit comments

Comments
 (0)