Skip to content

Commit 2d8f6e8

Browse files
committed
android: start working on bionic wrapper module; pass Bsymbolic to stop linker from complaining
1 parent d56aaf8 commit 2d8f6e8

File tree

7 files changed

+498
-0
lines changed

7 files changed

+498
-0
lines changed

cmake/modules/AddSwift.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ function(_add_variant_link_flags
165165
list(APPEND result "-lpthread" "-ldl" "${BSD_LIBRARIES}")
166166
elseif("${sdk}" STREQUAL "ANDROID")
167167
list(APPEND result
168+
"-Wl,-Bsymbolic"
168169
"-ldl"
169170
"-L${SWIFT_ANDROID_NDK_PATH}/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/lib/gcc/arm-linux-androideabi/4.8"
170171
"${SWIFT_ANDROID_NDK_PATH}/sources/cxx-stl/llvm-libc++/libs/armeabi-v7a/libc++_shared.so"

stdlib/public/Bionic/CMakeLists.txt

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
set(sources
2+
module.map
3+
)
4+
set(output_dir "${SWIFTLIB_DIR}/bionic")
5+
6+
set(commands
7+
COMMAND ${CMAKE_COMMAND} "-E" "make_directory" "${output_dir}")
8+
set(outputs)
9+
foreach(input ${sources})
10+
#list(APPEND commands
11+
# COMMAND
12+
# "${CMAKE_COMMAND}" "-E" "copy_if_different"
13+
# "${CMAKE_CURRENT_SOURCE_DIR}/${input}"
14+
# "${output_dir}/${input}")
15+
list(APPEND commands
16+
COMMAND
17+
"sed" "-e" "s@SYSROOT@/home/zhuowei/ndk/platforms/android-16/arch-arm@g"
18+
"${CMAKE_CURRENT_SOURCE_DIR}/${input}"
19+
">"
20+
"${output_dir}/${input}")
21+
list(APPEND outputs "${output_dir}/${input}")
22+
endforeach()
23+
# Put the output dir itself last so that it isn't considered the primary output.
24+
list(APPEND outputs "${output_dir}")
25+
add_custom_command_target(unused_var
26+
${commands}
27+
CUSTOM_TARGET_NAME "copy_bionic_module"
28+
OUTPUT "${outputs}"
29+
DEPENDS "${sources}"
30+
COMMENT "Copying Bionic module to ${output_dir}")
31+
32+
swift_install_in_component(stdlib
33+
FILES ${sources}
34+
DESTINATION "lib/swift/bionic")
35+
36+
add_swift_library(swiftGlibc IS_SDK_OVERLAY
37+
Glibc.swift
38+
FILE_DEPENDS copy_bionic_module "${SWIFTLIB_DIR}/bionic"
39+
TARGET_SDKS ANDROID
40+
INSTALL_IN_COMPONENT stdlib-experimental)
41+

stdlib/public/Bionic/Glibc.swift

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See http://swift.org/LICENSE.txt for license information
9+
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
@_exported import SwiftBionic // Clang module
14+
15+
//===----------------------------------------------------------------------===//
16+
// sys/errno.h
17+
//===----------------------------------------------------------------------===//
18+
19+
public var errno: Int32 {
20+
get {
21+
return __errno_location().memory
22+
}
23+
set(val) {
24+
return __errno_location().memory = val
25+
}
26+
}
27+
28+
//===----------------------------------------------------------------------===//
29+
// fcntl.h
30+
//===----------------------------------------------------------------------===//
31+
32+
public var S_IFMT: mode_t { return mode_t(0o170000) }
33+
public var S_IFIFO: mode_t { return mode_t(0o010000) }
34+
public var S_IFCHR: mode_t { return mode_t(0o020000) }
35+
public var S_IFDIR: mode_t { return mode_t(0o040000) }
36+
public var S_IFBLK: mode_t { return mode_t(0o060000) }
37+
public var S_IFREG: mode_t { return mode_t(0o100000) }
38+
public var S_IFLNK: mode_t { return mode_t(0o120000) }
39+
public var S_IFSOCK: mode_t { return mode_t(0o140000) }
40+
41+
public var S_IRWXU: mode_t { return mode_t(0o000700) }
42+
public var S_IRUSR: mode_t { return mode_t(0o000400) }
43+
public var S_IWUSR: mode_t { return mode_t(0o000200) }
44+
public var S_IXUSR: mode_t { return mode_t(0o000100) }
45+
46+
public var S_IRWXG: mode_t { return mode_t(0o000070) }
47+
public var S_IRGRP: mode_t { return mode_t(0o000040) }
48+
public var S_IWGRP: mode_t { return mode_t(0o000020) }
49+
public var S_IXGRP: mode_t { return mode_t(0o000010) }
50+
51+
public var S_IRWXO: mode_t { return mode_t(0o000007) }
52+
public var S_IROTH: mode_t { return mode_t(0o000004) }
53+
public var S_IWOTH: mode_t { return mode_t(0o000002) }
54+
public var S_IXOTH: mode_t { return mode_t(0o000001) }
55+
56+
public var S_ISUID: mode_t { return mode_t(0o004000) }
57+
public var S_ISGID: mode_t { return mode_t(0o002000) }
58+
public var S_ISVTX: mode_t { return mode_t(0o001000) }
59+
60+
//===----------------------------------------------------------------------===//
61+
// signal.h
62+
//===----------------------------------------------------------------------===//
63+
64+
#if os(Linux)
65+
public var SIG_DFL: __sighandler_t? { return nil }
66+
public var SIG_IGN: __sighandler_t {
67+
return unsafeBitCast(1, __sighandler_t.self)
68+
}
69+
public var SIG_ERR: __sighandler_t {
70+
return unsafeBitCast(-1, __sighandler_t.self)
71+
}
72+
public var SIG_HOLD: __sighandler_t {
73+
return unsafeBitCast(2, __sighandler_t.self)
74+
}
75+
#endif
76+

stdlib/public/Bionic/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
This directory holds the Swift Standard Library's Glibc Module, comprised of
2+
- The *overlay* library, which amends some APIs imported from Glibc, and
3+
- The clang [module map](http://clang.llvm.org/docs/Modules.html) which
4+
specifies which headers need to be imported from Glibc for bare minimum
5+
functionality.

0 commit comments

Comments
 (0)