Skip to content

Commit 14e332e

Browse files
Support building on macOS to develop this project (#8)
* Add simple GitHub Actions config for macOS * Add brew install to the macOS GH action * Add update-checkout call to macOS GH action * Export sourcedir shell variable in macOS GH action * [WASM] Use prebuilt llvm-ar only on Linux * [WASM] Added new Object format WASM to distinguish from ELF * [WASM] Separate SwiftRT from ELF * [WASM] Add preprocessor condition for wasm32 to track latest upstream * Add wasi-sdk and icu install steps to the script * [WASM] Set LIBC_INCLUDE_DIRECTORY without CACHE attribute to force new value * [WASM] Adding share path to point correct directory * [WASM] Add Linux CI job * [WASM] Checkout branch after checking out Swift repos * [WASM] Use release build to reduce artifact size * [WASM] Use SWIFT_PRIMARY_VARIANT_SDK instead of HOST_SDK In this case, SWIFT_PRIMARY_VARIANT_ARCH is used but host SDK was not PRIMARY_SDK. * [WASM] Remove ICU_STATICLIB on Linux * [WASM] Output build log verbose * [WASM] Set ICU lib directory instead of archive * [WASM] Sort build options * Revert "[WASM] Use SWIFT_PRIMARY_VARIANT_SDK instead of HOST_SDK"
1 parent d62abee commit 14e332e

File tree

9 files changed

+152
-16
lines changed

9 files changed

+152
-16
lines changed

.github/workflows/main.yml

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
name: CI
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- swiftwasm
7+
8+
jobs:
9+
linux_build:
10+
timeout-minutes: 0
11+
runs-on: ubuntu-18.04
12+
13+
steps:
14+
- uses: actions/checkout@v1
15+
- name: Run a multi-line script
16+
run: |
17+
sudo apt update
18+
sudo apt install \
19+
git ninja-build clang python \
20+
uuid-dev libicu-dev icu-devtools libbsd-dev \
21+
libedit-dev libxml2-dev libsqlite3-dev swig \
22+
libpython-dev libncurses5-dev pkg-config \
23+
libblocksruntime-dev libcurl4-openssl-dev \
24+
systemtap-sdt-dev tzdata rsync
25+
26+
./utils/update-checkout --clone --scheme wasm
27+
git checkout $GITHUB_SHA
28+
export sourcedir=$PWD/..
29+
cd $sourcedir
30+
31+
wget -O install_cmake.sh "https://github.com/Kitware/CMake/releases/download/v3.15.3/cmake-3.15.3-Linux-x86_64.sh"
32+
chmod +x install_cmake.sh
33+
sudo mkdir -p /opt/cmake
34+
sudo ./install_cmake.sh --skip-license --prefix=/opt/cmake
35+
sudo ln -sf /opt/cmake/bin/* /usr/local/bin
36+
cmake --version
37+
38+
wget -O wasi-sdk.tar.gz https://github.com/swiftwasm/wasi-sdk/releases/download/20190421.6/wasi-sdk-3.19gefb17cb478f9.m-linux.tar.gz
39+
tar xfz wasi-sdk.tar.gz
40+
mv wasi-sdk-3.19gefb17cb478f9+m/opt/wasi-sdk ./wasi-sdk
41+
42+
wget -O icu.tar.xz "https://github.com/swiftwasm/icu4c-wasi/releases/download/20190421.3/icu4c-wasi.tar.xz"
43+
tar xf icu.tar.xz
44+
45+
cd swift
46+
utils/build-script --release --wasm --verbose \
47+
--skip-build-benchmarks \
48+
--extra-cmake-options=" \
49+
-DSWIFT_SDKS='WASM;LINUX' \
50+
-DSWIFT_BUILD_SOURCEKIT=FALSE \
51+
-DSWIFT_ENABLE_SOURCEKIT_TESTS=FALSE \
52+
" \
53+
--build-stdlib-deployment-targets "wasm-wasm32" \
54+
--build-swift-static-stdlib \
55+
--install-destdir="$sourcedir/install" \
56+
--install-prefix="/opt/swiftwasm-sdk" \
57+
--install-swift \
58+
--installable-package="$sourcedir/swiftwasm.tar.gz" \
59+
--llvm-targets-to-build "X86;WebAssembly" \
60+
--stdlib-deployment-targets "wasm-wasm32" \
61+
--wasm-icu-data "todo-icu-data" \
62+
--wasm-icu-i18n "$sourcedir/icu_out/lib" \
63+
--wasm-icu-i18n-include "$sourcedir/icu_out/include" \
64+
--wasm-icu-uc "$sourcedir/icu_out/lib" \
65+
--wasm-icu-uc-include "$sourcedir/icu_out/include" \
66+
--wasm-wasi-sdk "$sourcedir/wasi-sdk"
67+
68+
macos_build:
69+
timeout-minutes: 0
70+
runs-on: macOS-10.14
71+
72+
steps:
73+
- uses: actions/checkout@v1
74+
- name: Run a multi-line script
75+
run: |
76+
brew install cmake ninja
77+
./utils/update-checkout --clone --scheme wasm
78+
git checkout $GITHUB_SHA
79+
export sourcedir=$PWD/..
80+
cd $sourcedir
81+
wget -O wasi-sdk.tar.gz https://github.com/swiftwasm/wasi-sdk/releases/download/20190421.6/wasi-sdk-3.19gefb17cb478f9.m-linux.tar.gz
82+
tar xfz wasi-sdk.tar.gz
83+
mv wasi-sdk-3.19gefb17cb478f9+m/opt/wasi-sdk ./wasi-sdk
84+
# Link sysroot/usr/include to sysroot/include because Darwin sysroot doesn't
85+
# find header files in sysroot/include but sysroot/usr/include
86+
mkdir wasi-sdk/share/sysroot/usr/
87+
ln -s ../include wasi-sdk/share/sysroot/usr/include
88+
wget -O icu.tar.xz "https://github.com/swiftwasm/icu4c-wasi/releases/download/20190421.3/icu4c-wasi.tar.xz"
89+
tar xf icu.tar.xz
90+
cd swift
91+
./utils/build-script --release --wasm --verbose \
92+
--skip-build-benchmarks \
93+
--extra-cmake-options=" \
94+
-DSWIFT_PRIMARY_VARIANT_SDK:STRING=WASM \
95+
-DSWIFT_PRIMARY_VARIANT_ARCH:STRING=wasm32 \
96+
-DSWIFT_OSX_x86_64_ICU_STATICLIB=TRUE \
97+
-DSWIFT_BUILD_SOURCEKIT=FALSE \
98+
-DSWIFT_ENABLE_SOURCEKIT_TESTS=FALSE \
99+
" \
100+
--build-stdlib-deployment-targets "wasm-wasm32" \
101+
--build-swift-dynamic-sdk-overlay false \
102+
--build-swift-static-sdk-overlay false \
103+
--build-swift-static-stdlib \
104+
--llvm-targets-to-build "X86;WebAssembly" \
105+
--stdlib-deployment-targets "wasm-wasm32" \
106+
--wasm-icu-data "todo-icu-data" \
107+
--wasm-icu-i18n "$sourcedir/icu_out/lib" \
108+
--wasm-icu-i18n-include "$sourcedir/icu_out/include" \
109+
--wasm-icu-uc "$sourcedir/icu_out/lib" \
110+
--wasm-icu-uc-include "$sourcedir/icu_out/include" \
111+
--wasm-wasi-sdk "$sourcedir/wasi-sdk"

CMakeLists.txt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@ ENABLE_LANGUAGE(C)
3636
include(SwiftUtils)
3737
include(CheckSymbolExists)
3838

39-
# WebAssembly: hack: use llvm-ar for creating static libraries; Ubuntu's GNU ar doesn't work with wasm-ld
40-
set(CMAKE_AR "${SWIFT_WASM_WASI_SDK_PATH}/bin/llvm-ar")
41-
4239
#
4340
# User-configurable options that control the inclusion and default build
4441
# behavior for components which may not strictly be necessary (tools, examples,
@@ -794,6 +791,11 @@ if(swift_build_wasm AND NOT "${SWIFT_HOST_VARIANT_SDK}" STREQUAL "WASM")
794791
# message(FATAL_ERROR "A Darwin or Linux host is required to build the Swift runtime for Android")
795792
#endif()
796793

794+
if ("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Linux")
795+
# WebAssembly: hack: use llvm-ar for creating static libraries; Ubuntu's GNU ar doesn't work with wasm-ld
796+
set(CMAKE_AR "${SWIFT_WASM_WASI_SDK_PATH}/bin/llvm-ar")
797+
endif()
798+
797799
if("${SWIFT_SDK_WASM_ARCHITECTURES}" STREQUAL "")
798800
set(SWIFT_SDK_WASM_ARCHITECTURES wasm32)
799801
endif()

cmake/modules/AddSwift.cmake

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1076,7 +1076,8 @@ function(_add_swift_library_single target name)
10761076
${INCORPORATED_OBJECT_LIBRARIES_EXPRESSIONS}
10771077
${SWIFTLIB_SINGLE_XCODE_WORKAROUND_SOURCES})
10781078
if(("${SWIFT_SDK_${SWIFTLIB_SINGLE_SDK}_OBJECT_FORMAT}" STREQUAL "ELF" OR
1079-
"${SWIFT_SDK_${SWIFTLIB_SINGLE_SDK}_OBJECT_FORMAT}" STREQUAL "COFF") AND
1079+
"${SWIFT_SDK_${SWIFTLIB_SINGLE_SDK}_OBJECT_FORMAT}" STREQUAL "COFF" OR
1080+
"${SWIFT_SDK_${SWIFTLIB_SINGLE_SDK}_OBJECT_FORMAT}" STREQUAL "WASM") AND
10801081
SWIFTLIB_SINGLE_TARGET_LIBRARY)
10811082
if("${libkind}" STREQUAL "SHARED" AND NOT SWIFTLIB_SINGLE_NOSWIFTRT)
10821083
# TODO(compnerd) switch to the generator expression when cmake is upgraded

cmake/modules/SwiftConfigureSDK.cmake

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,8 @@ macro(configure_sdk_unix name architectures)
217217
set(SWIFT_SDK_${prefix}_ARCHITECTURES "${architectures}")
218218
if("${prefix}" STREQUAL "CYGWIN")
219219
set(SWIFT_SDK_${prefix}_OBJECT_FORMAT "COFF")
220+
elseif("${prefix}" STREQUAL "WASM")
221+
set(SWIFT_SDK_${prefix}_OBJECT_FORMAT "WASM")
220222
else()
221223
set(SWIFT_SDK_${prefix}_OBJECT_FORMAT "ELF")
222224
endif()
@@ -340,8 +342,8 @@ macro(configure_sdk_unix name architectures)
340342
set(SWIFT_SDK_WASM_ARCH_wasm32_PATH "${SWIFT_WASM_WASI_SDK_PATH}/share/sysroot")
341343
# fixme: Wasi is wasm32-unknown-wasi-musl. This LLVM doesn't have it yet.
342344
set(SWIFT_SDK_WASM_ARCH_wasm32_TRIPLE "wasm32-unknown-unknown-wasm")
343-
set(SWIFT_SDK_WASM_ARCH_wasm32_LIBC_INCLUDE_DIRECTORY "${SWIFT_WASM_WASI_SDK_PATH}/share/sysroot/include" CACHE STRING "Path to C library headers")
344-
set(SWIFT_SDK_WASM_ARCH_wasm32_LIBC_ARCHITECTURE_INCLUDE_DIRECTORY "${SWIFT_WASM_WASI_SDK_PATH}/sysroot/include" CACHE STRING "Path to C library architecture headers")
345+
set(SWIFT_SDK_WASM_ARCH_wasm32_LIBC_INCLUDE_DIRECTORY "${SWIFT_WASM_WASI_SDK_PATH}/share/sysroot/include")
346+
set(SWIFT_SDK_WASM_ARCH_wasm32_LIBC_ARCHITECTURE_INCLUDE_DIRECTORY "${SWIFT_WASM_WASI_SDK_PATH}/share/sysroot/include")
345347
else()
346348
message(FATAL_ERROR "unknown Unix OS: ${prefix}")
347349
endif()

lib/Driver/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +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")
36+
if("${SWIFT_SDK_${sdk}_OBJECT_FORMAT}" STREQUAL "ELF" OR
37+
"${SWIFT_SDK_${sdk}_OBJECT_FORMAT}" STREQUAL "WASM")
3738
string(TOLOWER "${sdk}" lowercase_sdk)
3839
if(SWIFT_${SWIFT_HOST_VARIANT_SDK}_${SWIFT_HOST_VARIANT_ARCH}_ICU_STATICLIB)
3940
set(ICU_STATICLIB "TRUE")

stdlib/public/core/StringStorage.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ extension __StringStorage {
186186
let count = try initializer(buffer)
187187

188188
let countAndFlags = CountAndFlags(mortalCount: count, isASCII: false)
189-
#if arch(i386) || arch(arm)
189+
#if arch(i386) || arch(arm) || arch(wasm32)
190190
storage._count = countAndFlags.count
191191
storage._flags = countAndFlags.flags
192192
#else

stdlib/public/runtime/CMakeLists.txt

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ endif(LLVM_ENABLE_ASSERTIONS)
8080
set(LLVM_OPTIONAL_SOURCES
8181
SwiftRT-COFF.cpp
8282
SwiftRT-ELF.cpp
83+
SwiftRT-WASM.cpp
8384
${swift_runtime_sources}
8485
${swift_runtime_objc_sources}
8586
${swift_runtime_leaks_sources})
@@ -179,11 +180,14 @@ add_swift_target_library(swiftRuntime OBJECT_LIBRARY
179180

180181
set(ELFISH_SDKS)
181182
set(COFF_SDKS)
183+
set(WASM_SDKS)
182184
foreach(sdk ${SWIFT_CONFIGURED_SDKS})
183185
if("${SWIFT_SDK_${sdk}_OBJECT_FORMAT}" STREQUAL "ELF")
184186
list(APPEND ELFISH_SDKS ${sdk})
185187
elseif("${SWIFT_SDK_${sdk}_OBJECT_FORMAT}" STREQUAL "COFF")
186188
list(APPEND COFF_SDKS ${sdk})
189+
elseif("${SWIFT_SDK_${sdk}_OBJECT_FORMAT}" STREQUAL "WASM")
190+
list(APPEND WASM_SDKS ${sdk})
187191
endif()
188192
endforeach()
189193

@@ -196,6 +200,16 @@ add_swift_target_library(swiftImageRegistrationObjectELF
196200
TARGET_SDKS ${ELFISH_SDKS}
197201
SWIFT_COMPILE_FLAGS ${SWIFT_STANDARD_LIBRARY_SWIFT_FLAGS}
198202
INSTALL_IN_COMPONENT none)
203+
204+
add_swift_target_library(swiftImageRegistrationObjectWASM
205+
OBJECT_LIBRARY IS_STDLIB IS_STDLIB_CORE
206+
SwiftRT-WASM.cpp
207+
C_COMPILE_FLAGS ${SWIFT_RUNTIME_CORE_CXX_FLAGS}
208+
LINK_FLAGS ${SWIFT_RUNTIME_CORE_LINK_FLAGS}
209+
TARGET_SDKS ${WASM_SDKS}
210+
SWIFT_COMPILE_FLAGS ${SWIFT_STANDARD_LIBRARY_SWIFT_FLAGS}
211+
INSTALL_IN_COMPONENT none)
212+
199213
# FIXME(compnerd) this should be compiled twice, once for static and once for
200214
# shared. The static version should be used for building the standard library.
201215
add_swift_target_library(swiftImageRegistrationObjectCOFF
@@ -213,7 +227,8 @@ foreach(sdk ${SWIFT_CONFIGURED_SDKS})
213227
set(arch_suffix "${SWIFT_SDK_${sdk}_LIB_SUBDIR}-${arch}")
214228

215229
if("${SWIFT_SDK_${sdk}_OBJECT_FORMAT}" STREQUAL "ELF" OR
216-
"${SWIFT_SDK_${sdk}_OBJECT_FORMAT}" STREQUAL "COFF")
230+
"${SWIFT_SDK_${sdk}_OBJECT_FORMAT}" STREQUAL "COFF" OR
231+
"${SWIFT_SDK_${sdk}_OBJECT_FORMAT}" STREQUAL "WASM")
217232
# TODO(compnerd) switch to the generator expression when cmake is upgraded
218233
# to a version which supports it.
219234
# set(swiftrtObject "$<TARGET_OBJECTS:swiftImageRegistrationObject${SWIFT_SDK_${sdk}_OBJECT_FORMAT}-${arch_suffix}>")

stdlib/public/runtime/SwiftRT-ELF.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,9 @@ static swift::MetadataSections sections{};
4646

4747
__attribute__((__constructor__))
4848
static void swift_image_constructor() {
49-
#ifndef __wasm__
5049
#define SWIFT_SECTION_RANGE(name) \
5150
{ reinterpret_cast<uintptr_t>(&__start_##name), \
5251
static_cast<uintptr_t>(&__stop_##name - &__start_##name) }
53-
#else
54-
// WebAssembly hack: ok this should really go in its own file
55-
#define SWIFT_SECTION_RANGE(name) \
56-
{ reinterpret_cast<uintptr_t>(&__start_##name) + sizeof(void*), \
57-
static_cast<uintptr_t>(&__stop_##name - &__start_##name - sizeof(void*)) }
58-
#endif
5952

6053
sections = {
6154
swift::CurrentSectionMetadataVersion,
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//===--- SwiftRT-WASM.cpp --------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)