Skip to content

Commit 08a31af

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 85c5a6e commit 08a31af

23 files changed

+429
-193
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
@@ -1136,8 +1136,8 @@ if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
11361136
endif()
11371137

11381138
if(SWIFT_INCLUDE_TESTS)
1139-
#add_subdirectory(test)
1140-
#add_subdirectory(unittests)
1139+
add_subdirectory(test)
1140+
add_subdirectory(unittests)
11411141
endif()
11421142
if(SWIFT_INCLUDE_DOCS)
11431143
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
@@ -332,6 +332,8 @@ function(_add_variant_c_compile_flags)
332332
list(APPEND result -isystem;${path})
333333
endforeach()
334334
list(APPEND result "-D__ANDROID_API__=${SWIFT_ANDROID_API_LEVEL}")
335+
elseif("${CFLAGS_SDK}" STREQUAL "WASI")
336+
list(APPEND result "-D_WASI_EMULATED_MMAN")
335337
elseif(CFLAGS_SDK STREQUAL WINDOWS)
336338
swift_windows_include_for_arch(${CFLAGS_ARCH} ${CFLAGS_ARCH}_INCLUDE)
337339
foreach(path ${${CFLAGS_ARCH}_INCLUDE})
@@ -391,6 +393,8 @@ function(_add_variant_swift_compile_flags
391393
foreach(path IN LISTS ${arch}_swift_include)
392394
list(APPEND result "\"${CMAKE_INCLUDE_FLAG_C}${path}\"")
393395
endforeach()
396+
elseif("${sdk}" STREQUAL "WASI")
397+
list(APPEND result "-Xcc" "-D_WASI_EMULATED_MMAN")
394398
endif()
395399

396400
if(NOT BUILD_STANDALONE)
@@ -501,7 +505,7 @@ function(_add_variant_link_flags)
501505
list(APPEND library_search_directories ${path})
502506
endforeach()
503507
elseif("${LFLAGS_SDK}" STREQUAL "WASI")
504-
# No extra libraries needed.
508+
list(APPEND result "-Wl,wasi-emulated-mman")
505509
else()
506510
# If lto is enabled, we need to add the object path flag so that the LTO code
507511
# 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
@@ -325,11 +325,10 @@ macro(configure_sdk_unix name architectures)
325325
if(NOT arch STREQUAL wasm32)
326326
message(FATAL_ERROR "unsupported arch for WebAssembly: ${arch}")
327327
endif()
328-
set(SWIFT_SDK_WASI_ARCH_wasm32_PATH "${SWIFT_WASI_SDK_PATH}/share/sysroot")
329-
# fixme: Wasi is wasm32-unknown-wasi-musl. This LLVM doesn't have it yet.
330-
set(SWIFT_SDK_WASI_ARCH_wasm32_TRIPLE "wasm32-unknown-unknown-wasi")
331-
set(SWIFT_SDK_WASI_ARCH_wasm32_LIBC_INCLUDE_DIRECTORY "${SWIFT_WASI_SDK_PATH}/share/sysroot/include")
332-
set(SWIFT_SDK_WASI_ARCH_wasm32_LIBC_ARCHITECTURE_INCLUDE_DIRECTORY "${SWIFT_WASI_SDK_PATH}/share/sysroot/include")
328+
set(SWIFT_SDK_WASI_ARCH_wasm32_PATH "${SWIFT_WASI_SDK_PATH}/share/wasi-sysroot")
329+
set(SWIFT_SDK_WASI_ARCH_wasm32_TRIPLE "wasm32-unknown-wasi")
330+
set(SWIFT_SDK_WASI_ARCH_wasm32_LIBC_INCLUDE_DIRECTORY "${SWIFT_WASI_SDK_PATH}/share/wasi-sysroot/include")
331+
set(SWIFT_SDK_WASI_ARCH_wasm32_LIBC_ARCHITECTURE_INCLUDE_DIRECTORY "${SWIFT_WASI_SDK_PATH}/share/wasi-sysroot/include")
333332
else()
334333
message(FATAL_ERROR "unknown Unix OS: ${prefix}")
335334
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)