Skip to content

Support building on macOS to develop this project #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
7b563cc
Add simple GitHub Actions config for macOS
MaxDesiatov Oct 28, 2019
544c068
Add brew install to the macOS GH action
MaxDesiatov Oct 28, 2019
1de0656
Add update-checkout call to macOS GH action
MaxDesiatov Oct 28, 2019
3998824
Export sourcedir shell variable in macOS GH action
MaxDesiatov Oct 28, 2019
f4c2205
[WASM] Use prebuilt llvm-ar only on Linux
kateinoigakukun Oct 19, 2019
1b3daf9
[WASM] Added new Object format WASM to distinguish from ELF
kateinoigakukun Oct 24, 2019
08549c7
[WASM] Separate SwiftRT from ELF
kateinoigakukun Oct 24, 2019
cad6531
[WASM] Add preprocessor condition for wasm32 to track latest upstream
kateinoigakukun Oct 24, 2019
19ca6b1
Add wasi-sdk and icu install steps to the script
MaxDesiatov Oct 30, 2019
eb76d92
Merge remote-tracking branch 'swiftwasm/gh-actions-macos' into katei/…
kateinoigakukun Oct 30, 2019
f09c370
[WASM] Set LIBC_INCLUDE_DIRECTORY without CACHE attribute to force ne…
kateinoigakukun Oct 30, 2019
258f25e
[WASM] Adding share path to point correct directory
kateinoigakukun Oct 30, 2019
8d90ac3
[WASM] Add Linux CI job
kateinoigakukun Oct 31, 2019
8c87d29
[WASM] Checkout branch after checking out Swift repos
kateinoigakukun Oct 31, 2019
72cd605
[WASM] Use release build to reduce artifact size
kateinoigakukun Oct 31, 2019
5e3916e
[WASM] Use SWIFT_PRIMARY_VARIANT_SDK instead of HOST_SDK
kateinoigakukun Nov 1, 2019
a089ff2
[WASM] Remove ICU_STATICLIB on Linux
kateinoigakukun Nov 2, 2019
a19bb18
[WASM] Output build log verbose
kateinoigakukun Nov 2, 2019
b320192
[WASM] Set ICU lib directory instead of archive
kateinoigakukun Nov 2, 2019
6e88e0a
[WASM] Sort build options
kateinoigakukun Nov 2, 2019
df43f21
Revert "[WASM] Use SWIFT_PRIMARY_VARIANT_SDK instead of HOST_SDK"
kateinoigakukun Nov 2, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 111 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
name: CI

on:
pull_request:
branches:
- swiftwasm

jobs:
linux_build:
timeout-minutes: 0
runs-on: ubuntu-18.04

steps:
- uses: actions/checkout@v1
- name: Run a multi-line script
run: |
sudo apt update
sudo apt install \
git ninja-build clang python \
uuid-dev libicu-dev icu-devtools libbsd-dev \
libedit-dev libxml2-dev libsqlite3-dev swig \
libpython-dev libncurses5-dev pkg-config \
libblocksruntime-dev libcurl4-openssl-dev \
systemtap-sdt-dev tzdata rsync
./utils/update-checkout --clone --scheme wasm
git checkout $GITHUB_SHA
export sourcedir=$PWD/..
cd $sourcedir
wget -O install_cmake.sh "https://github.com/Kitware/CMake/releases/download/v3.15.3/cmake-3.15.3-Linux-x86_64.sh"
chmod +x install_cmake.sh
sudo mkdir -p /opt/cmake
sudo ./install_cmake.sh --skip-license --prefix=/opt/cmake
sudo ln -sf /opt/cmake/bin/* /usr/local/bin
cmake --version
wget -O wasi-sdk.tar.gz https://github.com/swiftwasm/wasi-sdk/releases/download/20190421.6/wasi-sdk-3.19gefb17cb478f9.m-linux.tar.gz
tar xfz wasi-sdk.tar.gz
mv wasi-sdk-3.19gefb17cb478f9+m/opt/wasi-sdk ./wasi-sdk
wget -O icu.tar.xz "https://github.com/swiftwasm/icu4c-wasi/releases/download/20190421.3/icu4c-wasi.tar.xz"
tar xf icu.tar.xz
cd swift
utils/build-script --release --wasm --verbose \
--skip-build-benchmarks \
--extra-cmake-options=" \
-DSWIFT_SDKS='WASM;LINUX' \
-DSWIFT_BUILD_SOURCEKIT=FALSE \
-DSWIFT_ENABLE_SOURCEKIT_TESTS=FALSE \
" \
--build-stdlib-deployment-targets "wasm-wasm32" \
--build-swift-static-stdlib \
--install-destdir="$sourcedir/install" \
--install-prefix="/opt/swiftwasm-sdk" \
--install-swift \
--installable-package="$sourcedir/swiftwasm.tar.gz" \
--llvm-targets-to-build "X86;WebAssembly" \
--stdlib-deployment-targets "wasm-wasm32" \
--wasm-icu-data "todo-icu-data" \
--wasm-icu-i18n "$sourcedir/icu_out/lib" \
--wasm-icu-i18n-include "$sourcedir/icu_out/include" \
--wasm-icu-uc "$sourcedir/icu_out/lib" \
--wasm-icu-uc-include "$sourcedir/icu_out/include" \
--wasm-wasi-sdk "$sourcedir/wasi-sdk"
macos_build:
timeout-minutes: 0
runs-on: macOS-10.14

steps:
- uses: actions/checkout@v1
- name: Run a multi-line script
run: |
brew install cmake ninja
./utils/update-checkout --clone --scheme wasm
git checkout $GITHUB_SHA
export sourcedir=$PWD/..
cd $sourcedir
wget -O wasi-sdk.tar.gz https://github.com/swiftwasm/wasi-sdk/releases/download/20190421.6/wasi-sdk-3.19gefb17cb478f9.m-linux.tar.gz
tar xfz wasi-sdk.tar.gz
mv wasi-sdk-3.19gefb17cb478f9+m/opt/wasi-sdk ./wasi-sdk
# Link sysroot/usr/include to sysroot/include because Darwin sysroot doesn't
# find header files in sysroot/include but sysroot/usr/include
mkdir wasi-sdk/share/sysroot/usr/
ln -s ../include wasi-sdk/share/sysroot/usr/include
wget -O icu.tar.xz "https://github.com/swiftwasm/icu4c-wasi/releases/download/20190421.3/icu4c-wasi.tar.xz"
tar xf icu.tar.xz
cd swift
./utils/build-script --release --wasm --verbose \
--skip-build-benchmarks \
--extra-cmake-options=" \
-DSWIFT_PRIMARY_VARIANT_SDK:STRING=WASM \
-DSWIFT_PRIMARY_VARIANT_ARCH:STRING=wasm32 \
-DSWIFT_OSX_x86_64_ICU_STATICLIB=TRUE \
-DSWIFT_BUILD_SOURCEKIT=FALSE \
-DSWIFT_ENABLE_SOURCEKIT_TESTS=FALSE \
" \
--build-stdlib-deployment-targets "wasm-wasm32" \
--build-swift-dynamic-sdk-overlay false \
--build-swift-static-sdk-overlay false \
--build-swift-static-stdlib \
--llvm-targets-to-build "X86;WebAssembly" \
--stdlib-deployment-targets "wasm-wasm32" \
--wasm-icu-data "todo-icu-data" \
--wasm-icu-i18n "$sourcedir/icu_out/lib" \
--wasm-icu-i18n-include "$sourcedir/icu_out/include" \
--wasm-icu-uc "$sourcedir/icu_out/lib" \
--wasm-icu-uc-include "$sourcedir/icu_out/include" \
--wasm-wasi-sdk "$sourcedir/wasi-sdk"
8 changes: 5 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ ENABLE_LANGUAGE(C)
include(SwiftUtils)
include(CheckSymbolExists)

# WebAssembly: hack: use llvm-ar for creating static libraries; Ubuntu's GNU ar doesn't work with wasm-ld
set(CMAKE_AR "${SWIFT_WASM_WASI_SDK_PATH}/bin/llvm-ar")

#
# User-configurable options that control the inclusion and default build
# behavior for components which may not strictly be necessary (tools, examples,
Expand Down Expand Up @@ -853,6 +850,11 @@ if(swift_build_wasm AND NOT "${SWIFT_HOST_VARIANT_SDK}" STREQUAL "WASM")
# message(FATAL_ERROR "A Darwin or Linux host is required to build the Swift runtime for Android")
#endif()

if ("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Linux")
# WebAssembly: hack: use llvm-ar for creating static libraries; Ubuntu's GNU ar doesn't work with wasm-ld
set(CMAKE_AR "${SWIFT_WASM_WASI_SDK_PATH}/bin/llvm-ar")
endif()

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved set(CMAKE_AR ...) line to use prebuilt llvm-ar only on Linux.
In macOS environment, this hack is unnecessary.

if("${SWIFT_SDK_WASM_ARCHITECTURES}" STREQUAL "")
set(SWIFT_SDK_WASM_ARCHITECTURES wasm32)
endif()
Expand Down
3 changes: 2 additions & 1 deletion cmake/modules/AddSwift.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -1000,7 +1000,8 @@ function(_add_swift_library_single target name)
${INCORPORATED_OBJECT_LIBRARIES_EXPRESSIONS}
${SWIFTLIB_SINGLE_XCODE_WORKAROUND_SOURCES})
if(("${SWIFT_SDK_${SWIFTLIB_SINGLE_SDK}_OBJECT_FORMAT}" STREQUAL "ELF" OR
"${SWIFT_SDK_${SWIFTLIB_SINGLE_SDK}_OBJECT_FORMAT}" STREQUAL "COFF") AND
"${SWIFT_SDK_${SWIFTLIB_SINGLE_SDK}_OBJECT_FORMAT}" STREQUAL "COFF" OR
"${SWIFT_SDK_${SWIFTLIB_SINGLE_SDK}_OBJECT_FORMAT}" STREQUAL "WASM") AND
SWIFTLIB_SINGLE_TARGET_LIBRARY)
if("${libkind}" STREQUAL "SHARED" AND NOT SWIFTLIB_SINGLE_NOSWIFTRT)
# TODO(compnerd) switch to the generator expression when cmake is upgraded
Expand Down
6 changes: 4 additions & 2 deletions cmake/modules/SwiftConfigureSDK.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@ macro(configure_sdk_unix name architectures)
set(SWIFT_SDK_${prefix}_ARCHITECTURES "${architectures}")
if("${prefix}" STREQUAL "CYGWIN")
set(SWIFT_SDK_${prefix}_OBJECT_FORMAT "COFF")
elseif("${prefix}" STREQUAL "WASM")
set(SWIFT_SDK_${prefix}_OBJECT_FORMAT "WASM")
else()
set(SWIFT_SDK_${prefix}_OBJECT_FORMAT "ELF")
endif()
Expand Down Expand Up @@ -324,8 +326,8 @@ macro(configure_sdk_unix name architectures)
set(SWIFT_SDK_WASM_ARCH_wasm32_PATH "${SWIFT_WASM_WASI_SDK_PATH}/share/sysroot")
# fixme: Wasi is wasm32-unknown-wasi-musl. This LLVM doesn't have it yet.
set(SWIFT_SDK_WASM_ARCH_wasm32_TRIPLE "wasm32-unknown-unknown-wasm")
set(SWIFT_SDK_WASM_ARCH_wasm32_LIBC_INCLUDE_DIRECTORY "${SWIFT_WASM_WASI_SDK_PATH}/share/sysroot/include" CACHE STRING "Path to C library headers")
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")
set(SWIFT_SDK_WASM_ARCH_wasm32_LIBC_INCLUDE_DIRECTORY "${SWIFT_WASM_WASI_SDK_PATH}/share/sysroot/include")
set(SWIFT_SDK_WASM_ARCH_wasm32_LIBC_ARCHITECTURE_INCLUDE_DIRECTORY "${SWIFT_WASM_WASI_SDK_PATH}/share/sysroot/include")
else()
message(FATAL_ERROR "unknown Unix OS: ${prefix}")
endif()
Expand Down
3 changes: 2 additions & 1 deletion lib/Driver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ target_link_libraries(swiftDriver PRIVATE
if(SWIFT_BUILD_STATIC_STDLIB)
set(static_stdlib_lnk_file_list)
foreach(sdk ${SWIFT_CONFIGURED_SDKS})
if("${SWIFT_SDK_${sdk}_OBJECT_FORMAT}" STREQUAL "ELF")
if("${SWIFT_SDK_${sdk}_OBJECT_FORMAT}" STREQUAL "ELF" OR
"${SWIFT_SDK_${sdk}_OBJECT_FORMAT}" STREQUAL "WASM")
string(TOLOWER "${sdk}" lowercase_sdk)
if(SWIFT_${SWIFT_HOST_VARIANT_SDK}_${SWIFT_HOST_VARIANT_ARCH}_ICU_STATICLIB)
set(ICU_STATICLIB "TRUE")
Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/core/StringStorage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ extension __StringStorage {
let count = try initializer(buffer)

let countAndFlags = CountAndFlags(mortalCount: count, isASCII: false)
#if arch(i386) || arch(arm)
#if arch(i386) || arch(arm) || arch(wasm32)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These lines are added by upstream Swift

storage._count = countAndFlags.count
storage._flags = countAndFlags.flags
#else
Expand Down
17 changes: 16 additions & 1 deletion stdlib/public/runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ endif(LLVM_ENABLE_ASSERTIONS)
set(LLVM_OPTIONAL_SOURCES
SwiftRT-COFF.cpp
SwiftRT-ELF.cpp
SwiftRT-WASM.cpp
${swift_runtime_sources}
${swift_runtime_objc_sources}
${swift_runtime_leaks_sources})
Expand Down Expand Up @@ -173,11 +174,14 @@ add_swift_target_library(swiftRuntime OBJECT_LIBRARY

set(ELFISH_SDKS)
set(COFF_SDKS)
set(WASM_SDKS)
foreach(sdk ${SWIFT_CONFIGURED_SDKS})
if("${SWIFT_SDK_${sdk}_OBJECT_FORMAT}" STREQUAL "ELF")
list(APPEND ELFISH_SDKS ${sdk})
elseif("${SWIFT_SDK_${sdk}_OBJECT_FORMAT}" STREQUAL "COFF")
list(APPEND COFF_SDKS ${sdk})
elseif("${SWIFT_SDK_${sdk}_OBJECT_FORMAT}" STREQUAL "WASM")
list(APPEND WASM_SDKS ${sdk})
endif()
endforeach()

Expand All @@ -189,6 +193,16 @@ add_swift_target_library(swiftImageRegistrationObjectELF
TARGET_SDKS ${ELFISH_SDKS}
SWIFT_COMPILE_FLAGS ${SWIFT_STANDARD_LIBRARY_SWIFT_FLAGS}
INSTALL_IN_COMPONENT none)

add_swift_target_library(swiftImageRegistrationObjectWASM
OBJECT_LIBRARY IS_STDLIB IS_STDLIB_CORE
SwiftRT-WASM.cpp
C_COMPILE_FLAGS ${SWIFT_RUNTIME_CORE_CXX_FLAGS}
LINK_FLAGS ${SWIFT_RUNTIME_CORE_LINK_FLAGS}
TARGET_SDKS ${WASM_SDKS}
SWIFT_COMPILE_FLAGS ${SWIFT_STANDARD_LIBRARY_SWIFT_FLAGS}
INSTALL_IN_COMPONENT none)

# FIXME(compnerd) this should be compiled twice, once for static and once for
# shared. The static version should be used for building the standard library.
add_swift_target_library(swiftImageRegistrationObjectCOFF
Expand All @@ -206,7 +220,8 @@ foreach(sdk ${SWIFT_CONFIGURED_SDKS})
set(arch_suffix "${SWIFT_SDK_${sdk}_LIB_SUBDIR}-${arch}")

if("${SWIFT_SDK_${sdk}_OBJECT_FORMAT}" STREQUAL "ELF" OR
"${SWIFT_SDK_${sdk}_OBJECT_FORMAT}" STREQUAL "COFF")
"${SWIFT_SDK_${sdk}_OBJECT_FORMAT}" STREQUAL "COFF" OR
"${SWIFT_SDK_${sdk}_OBJECT_FORMAT}" STREQUAL "WASM")
# TODO(compnerd) switch to the generator expression when cmake is upgraded
# to a version which supports it.
# set(swiftrtObject "$<TARGET_OBJECTS:swiftImageRegistrationObject${SWIFT_SDK_${sdk}_OBJECT_FORMAT}-${arch_suffix}>")
Expand Down
7 changes: 0 additions & 7 deletions stdlib/public/runtime/SwiftRT-ELF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,9 @@ static swift::MetadataSections sections{};

__attribute__((__constructor__))
static void swift_image_constructor() {
#ifndef __wasm__
#define SWIFT_SECTION_RANGE(name) \
{ reinterpret_cast<uintptr_t>(&__start_##name), \
static_cast<uintptr_t>(&__stop_##name - &__start_##name) }
#else
// WebAssembly hack: ok this should really go in its own file
#define SWIFT_SECTION_RANGE(name) \
{ reinterpret_cast<uintptr_t>(&__start_##name) + sizeof(void*), \
static_cast<uintptr_t>(&__stop_##name - &__start_##name - sizeof(void*)) }
#endif

sections = {
swift::CurrentSectionMetadataVersion,
Expand Down
11 changes: 11 additions & 0 deletions stdlib/public/runtime/SwiftRT-WASM.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//===--- SwiftRT-WASM.cpp --------------------------------------------------===//
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I separated SwiftRT file to distinguish ELF and WASM.
No need to emit __start and __stop symbol because the runtime system which uses custom sections are disabled now and the latest clang raised runtime error to interpret __asm__((__section__))

//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//