Skip to content

Commit 0a1f4fc

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 7bba6af commit 0a1f4fc

File tree

9 files changed

+152
-16
lines changed

9 files changed

+152
-16
lines changed

Diff for: .github/workflows/main.yml

+111
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"

Diff for: CMakeLists.txt

+5-3
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,6 @@ ENABLE_LANGUAGE(C)
3131
include(SwiftUtils)
3232
include(CheckSymbolExists)
3333

34-
# WebAssembly: hack: use llvm-ar for creating static libraries; Ubuntu's GNU ar doesn't work with wasm-ld
35-
set(CMAKE_AR "${SWIFT_WASM_WASI_SDK_PATH}/bin/llvm-ar")
36-
3734
#
3835
# User-configurable options that control the inclusion and default build
3936
# behavior for components which may not strictly be necessary (tools, examples,
@@ -832,6 +829,11 @@ if(swift_build_wasm AND NOT "${SWIFT_HOST_VARIANT_SDK}" STREQUAL "WASM")
832829
# message(FATAL_ERROR "A Darwin or Linux host is required to build the Swift runtime for Android")
833830
#endif()
834831

832+
if ("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Linux")
833+
# WebAssembly: hack: use llvm-ar for creating static libraries; Ubuntu's GNU ar doesn't work with wasm-ld
834+
set(CMAKE_AR "${SWIFT_WASM_WASI_SDK_PATH}/bin/llvm-ar")
835+
endif()
836+
835837
if("${SWIFT_SDK_WASM_ARCHITECTURES}" STREQUAL "")
836838
set(SWIFT_SDK_WASM_ARCHITECTURES wasm32)
837839
endif()

Diff for: cmake/modules/AddSwift.cmake

+2-1
Original file line numberDiff line numberDiff line change
@@ -1000,7 +1000,8 @@ function(_add_swift_library_single target name)
10001000
${INCORPORATED_OBJECT_LIBRARIES_EXPRESSIONS}
10011001
${SWIFTLIB_SINGLE_XCODE_WORKAROUND_SOURCES})
10021002
if(("${SWIFT_SDK_${SWIFTLIB_SINGLE_SDK}_OBJECT_FORMAT}" STREQUAL "ELF" OR
1003-
"${SWIFT_SDK_${SWIFTLIB_SINGLE_SDK}_OBJECT_FORMAT}" STREQUAL "COFF") AND
1003+
"${SWIFT_SDK_${SWIFTLIB_SINGLE_SDK}_OBJECT_FORMAT}" STREQUAL "COFF" OR
1004+
"${SWIFT_SDK_${SWIFTLIB_SINGLE_SDK}_OBJECT_FORMAT}" STREQUAL "WASM") AND
10041005
SWIFTLIB_SINGLE_TARGET_LIBRARY)
10051006
if("${libkind}" STREQUAL "SHARED" AND NOT SWIFTLIB_SINGLE_NOSWIFTRT)
10061007
# TODO(compnerd) switch to the generator expression when cmake is upgraded

Diff for: cmake/modules/SwiftConfigureSDK.cmake

+4-2
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,8 @@ macro(configure_sdk_unix name architectures)
203203
set(SWIFT_SDK_${prefix}_ARCHITECTURES "${architectures}")
204204
if("${prefix}" STREQUAL "CYGWIN")
205205
set(SWIFT_SDK_${prefix}_OBJECT_FORMAT "COFF")
206+
elseif("${prefix}" STREQUAL "WASM")
207+
set(SWIFT_SDK_${prefix}_OBJECT_FORMAT "WASM")
206208
else()
207209
set(SWIFT_SDK_${prefix}_OBJECT_FORMAT "ELF")
208210
endif()
@@ -326,8 +328,8 @@ macro(configure_sdk_unix name architectures)
326328
set(SWIFT_SDK_WASM_ARCH_wasm32_PATH "${SWIFT_WASM_WASI_SDK_PATH}/share/sysroot")
327329
# fixme: Wasi is wasm32-unknown-wasi-musl. This LLVM doesn't have it yet.
328330
set(SWIFT_SDK_WASM_ARCH_wasm32_TRIPLE "wasm32-unknown-unknown-wasm")
329-
set(SWIFT_SDK_WASM_ARCH_wasm32_LIBC_INCLUDE_DIRECTORY "${SWIFT_WASM_WASI_SDK_PATH}/share/sysroot/include" CACHE STRING "Path to C library headers")
330-
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")
331+
set(SWIFT_SDK_WASM_ARCH_wasm32_LIBC_INCLUDE_DIRECTORY "${SWIFT_WASM_WASI_SDK_PATH}/share/sysroot/include")
332+
set(SWIFT_SDK_WASM_ARCH_wasm32_LIBC_ARCHITECTURE_INCLUDE_DIRECTORY "${SWIFT_WASM_WASI_SDK_PATH}/share/sysroot/include")
331333
else()
332334
message(FATAL_ERROR "unknown Unix OS: ${prefix}")
333335
endif()

Diff for: lib/Driver/CMakeLists.txt

+2-1
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")

Diff for: stdlib/public/core/StringStorage.swift

+1-1
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

Diff for: stdlib/public/runtime/CMakeLists.txt

+16-1
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})
@@ -174,11 +175,14 @@ add_swift_target_library(swiftRuntime OBJECT_LIBRARY
174175

175176
set(ELFISH_SDKS)
176177
set(COFF_SDKS)
178+
set(WASM_SDKS)
177179
foreach(sdk ${SWIFT_CONFIGURED_SDKS})
178180
if("${SWIFT_SDK_${sdk}_OBJECT_FORMAT}" STREQUAL "ELF")
179181
list(APPEND ELFISH_SDKS ${sdk})
180182
elseif("${SWIFT_SDK_${sdk}_OBJECT_FORMAT}" STREQUAL "COFF")
181183
list(APPEND COFF_SDKS ${sdk})
184+
elseif("${SWIFT_SDK_${sdk}_OBJECT_FORMAT}" STREQUAL "WASM")
185+
list(APPEND WASM_SDKS ${sdk})
182186
endif()
183187
endforeach()
184188

@@ -190,6 +194,16 @@ add_swift_target_library(swiftImageRegistrationObjectELF
190194
TARGET_SDKS ${ELFISH_SDKS}
191195
SWIFT_COMPILE_FLAGS ${SWIFT_STANDARD_LIBRARY_SWIFT_FLAGS}
192196
INSTALL_IN_COMPONENT none)
197+
198+
add_swift_target_library(swiftImageRegistrationObjectWASM
199+
OBJECT_LIBRARY IS_STDLIB IS_STDLIB_CORE
200+
SwiftRT-WASM.cpp
201+
C_COMPILE_FLAGS ${SWIFT_RUNTIME_CORE_CXX_FLAGS}
202+
LINK_FLAGS ${SWIFT_RUNTIME_CORE_LINK_FLAGS}
203+
TARGET_SDKS ${WASM_SDKS}
204+
SWIFT_COMPILE_FLAGS ${SWIFT_STANDARD_LIBRARY_SWIFT_FLAGS}
205+
INSTALL_IN_COMPONENT none)
206+
193207
# FIXME(compnerd) this should be compiled twice, once for static and once for
194208
# shared. The static version should be used for building the standard library.
195209
add_swift_target_library(swiftImageRegistrationObjectCOFF
@@ -207,7 +221,8 @@ foreach(sdk ${SWIFT_CONFIGURED_SDKS})
207221
set(arch_suffix "${SWIFT_SDK_${sdk}_LIB_SUBDIR}-${arch}")
208222

209223
if("${SWIFT_SDK_${sdk}_OBJECT_FORMAT}" STREQUAL "ELF" OR
210-
"${SWIFT_SDK_${sdk}_OBJECT_FORMAT}" STREQUAL "COFF")
224+
"${SWIFT_SDK_${sdk}_OBJECT_FORMAT}" STREQUAL "COFF" OR
225+
"${SWIFT_SDK_${sdk}_OBJECT_FORMAT}" STREQUAL "WASM")
211226
# TODO(compnerd) switch to the generator expression when cmake is upgraded
212227
# to a version which supports it.
213228
# set(swiftrtObject "$<TARGET_OBJECTS:swiftImageRegistrationObject${SWIFT_SDK_${sdk}_OBJECT_FORMAT}-${arch_suffix}>")

Diff for: stdlib/public/runtime/SwiftRT-ELF.cpp

-7
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,

Diff for: stdlib/public/runtime/SwiftRT-WASM.cpp

+11
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)