未整理
swift REPL :target modules list :help
curl
, autoconf
, automake
, libtool
, git
確認以上工具
下載 git clone https://github.com/SwiftAndroid/libiconv-libicu-android.git
確認 NDK 在 PATH 內, which ndk-build
cd libiconv-libicu-android
, run build.sh
確認 armeabi-v7a/icu/source/i18n
& libiconv-libicu-android
這兩個產生出來
Building the Swift stdlib for Android 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 git clone https://github.com/apple/swift LIBICU=/Users/yume/git/libiconv-libicu-android NDK=/Users/yume/Android_SDK/ndk-bundle utils/update-checkout --clone utils/build-script \ -R \ --android \ --android-ndk $NDK \ --android-api-level 21 \ --android-icu-uc $LIBICU /armeabi-v7a \ --android-icu-uc-include $LIBICU /armeabi-v7a/icu/source /common \ --android-icu-i18n $LIBICU /armeabi-v7a \ --android-icu-i18n-include $LIBICU /armeabi-v7a/icu/source /i18n/ utils/build-script -R --android --android-ndk $NDK --android-api-level 21 --android-icu-uc $LIBICU /armeabi-v7a --android-icu-uc-include $LIBICU /armeabi-v7a/icu/source /common --android-icu-i18n $LIBICU /armeabi-v7a --android-ic utils/build-script -R --android true --android-ndk $NDK --android-api-level 21 --android-icu-uc $LIBICU /armeabi-v7a --android-icu-uc-include $LIBICU /armeabi-v7a/icu/source /common --android-icu-i18n $LIBICU /armeabi-v7a --android-icu-i18n-include $LIBICU /armeabi-v7a/icu/source /i18n --skip-ios --skip-tvos --skip-watchos swift/utils/build-script -x build/Xcode-DebugAssert/swift-macosx-x86_64/Swfit.xproj
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 $SDK /usr/bin/swiftc -parse-as-library -target armv7-apple-ios9.0 -emit-ir add.swift | grep -v "^\!" > add.ll$SDK /usr/bin/swiftc -parse-as-library -target armv7-apple-ios9.0 -emit-ir add.swift -o add.ll/Users/yume/Downloads/android-ndk-r13b/toolchains/llvm/prebuilt/darwin-x86_64/bin/llvm-as add.ll /Users/yume/Downloads/android-ndk-r10e/toolchains/llvm-3.6/prebuilt/darwin-x86_64/bin/llc -mtriple=armv7-none-linux-androideabi -filetype=obj add.ll /Users/yume/Downloads/android-ndk-r10e/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-ld add.o -shared -L/Users/yume/Downloads/android-ndk-r10e/platforms/android-21/arch-arm/usr/lib -mtriple=armv7-none-linux-androideabi -filetype=obj add.ll clang -target <target_from_list_above> clang -target armv7-none-linux-androideabi -o add add.bc $NDK /toolchains/llvm-3.5/prebuilt/darwin-x86_64/bin/llc -mtriple=armv7-none-linux-androideabi -filetype=obj add.ll clang -o add add.bc
clang -emit-llvm -o foo.bc -c foo.c clang -o foo foo.bc
swiftc -parse-as-library -target x86_64-apple-macosx10.12 -emit-ir hello.swift > hello.ll swiftc -parse-as-library -target x86_64-apple-macosx10.12 -emit-bc hello.swift > hello.bc
https://www.accelebrate.com/blog/thinking-swift-part-ii/
1 2 3 4 let a = 3 let b = 4 let c = a + b println(c)
swift llvm link 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 swiftc -dump-ast hello.swift swiftc -emit-silgen hello.swift > hello.sil swiftc -parse-sil hello.sil ./hello swiftc -emit-ir hello.swift > hello.ll swiftc -emit-bc hello.swift > hello.bc llvm-as hello.ll lli hello.bc
http://pllab.cs.nthu.edu.tw/cs340402/lectures/lectures_2013/LLVM%20Bitcode%20Introduction.pdf 1 2 3 4 5 6 7 8 9 10 LLVM tools • llvm-as: assemble a human-readable .ll file into bitcode • llvm-dis: disassemble a bitcode file into a human-readable .ll file • opt: run a series of LLVM-to-LLVM optimizations on a bitcode file • llc: generate native machine code for a bitcode file • lli: directly run a program compiled to bitcode using a JIT compiler or interpreter • llvm-link: link several bitcode files into one • clang: C, C++, Object C front-end for LLVM • llvm-gcc: GCC-based C front-end for LLVM • llvm-g++: GCC-based C++ front-end for LLVM
待看
帶看 swift on android
compile 相關
symbol 1 2 3 4 5 nm -D /lib/mylib.so.1 readelf -s /usr/lib/lib<example>.so.XX.x | grep <OBJECT_abc> objdump -Dslx /lib/libcap.so.2 | more objdump -x /path/to/file/filename | head -50
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 MODULE_NAME = tool SDK = macosx ARCH = x86_64 CONFIG ?= debug ROOT_DIR = $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))) OUTPUT_DIR = $(ROOT_DIR)/bin TARGET_DIR = $(OUTPUT_DIR)/$(SDK)/$(CONFIG) SRC_DIR = $(ROOT_DIR)/src ifeq ($(CONFIG), debug) CFLAGS=-Onone -g else CFLAGS=-O3 endif $(SWIFTC) $(SWIFT_FILES) -emit-executable -sdk $(SDK_PATH) -module-name $(MODULE_NAME) -emit-module -emit-module-path $(TARGET_DIR)/$(MODULE_NAME).swiftmodule -o $(TARGET_DIR)/$(MODULE_NAME) -sdk macosx \ swiftc \ swift_add.swift \ -emit-library \ -target x86_64-apple-macosx10.12 \ -module-name tool \ -emit-module \ -emit-module-path module/tool.swiftmodule \ -o module/tool swiftc -target x86_64-apple-macosx10.12 -emit-library -parse-as-library swift_add.swift -o swift_add.o CompileSwift normal x86_64 /Users/yume/Desktop/cswift/cswift/add.swift cd /Users/yume/Desktop/cswift /Applications/Xcode8_2_1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c -primary-file /Users/yume/Desktop/cswift/cswift/add.swift -target x86_64-apple-macosx10.12 -enable-objc-interop -sdk /Applications/Xcode8_2_1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk -I /Users/yume/Library/Developer/Xcode/DerivedData/cswift-fjyhynvvlsnuujdxujqngcntiouz/Build/Products/Debug -F /Users/yume/Library/Developer/Xcode/DerivedData/cswift-fjyhynvvlsnuujdxujqngcntiouz/Build/Products/Debug -enable-testing -g -module-cache-path /Users/yume/Library/Developer/Xcode/DerivedData/ModuleCache -serialize-debugging-options -Xcc -I/Users/yume/Library/Developer/Xcode/DerivedData/cswift-fjyhynvvlsnuujdxujqngcntiouz/Build/Intermediates/cswift.build/Debug/cswift.build/swift-overrides.hmap -Xcc -iquote -Xcc /Users/yume/Library/Developer/Xcode/DerivedData/cswift-fjyhynvvlsnuujdxujqngcntiouz/Build/Intermediates/cswift.build/Debug/cswift.build/cswift-generated-files.hmap -Xcc -I/Users/yume/Library/Developer/Xcode/DerivedData/cswift-fjyhynvvlsnuujdxujqngcntiouz/Build/Intermediates/cswift.build/Debug/cswift.build/cswift-own-target-headers.hmap -Xcc -I/Users/yume/Library/Developer/Xcode/DerivedData/cswift-fjyhynvvlsnuujdxujqngcntiouz/Build/Intermediates/cswift.build/Debug/cswift.build/cswift-all-target-headers.hmap -Xcc -iquote -Xcc /Users/yume/Library/Developer/Xcode/DerivedData/cswift-fjyhynvvlsnuujdxujqngcntiouz/Build/Intermediates/cswift.build/Debug/cswift.build/cswift-project-headers.hmap -Xcc -I/Users/yume/Library/Developer/Xcode/DerivedData/cswift-fjyhynvvlsnuujdxujqngcntiouz/Build/Products/Debug/include -Xcc -I/Users/yume/Library/Developer/Xcode/DerivedData/cswift-fjyhynvvlsnuujdxujqngcntiouz/Build/Intermediates/cswift.build/Debug/cswift.build/DerivedSources/x86_64 -Xcc -I/Users/yume/Library/Developer/Xcode/DerivedData/cswift-fjyhynvvlsnuujdxujqngcntiouz/Build/Intermediates/cswift.build/Debug/cswift.build/DerivedSources -Xcc -DDEBUG=1 -Xcc -working-directory/Users/yume/Desktop/cswift -emit-module-doc-path /Users/yume/Library/Developer/Xcode/DerivedData/cswift-fjyhynvvlsnuujdxujqngcntiouz/Build/Intermediates/cswift.build/Debug/cswift.build/Objects-normal/x86_64/add~partial.swiftdoc -Onone -parse-as-library -module-name cswift -emit-module-path /Users/yume/Library/Developer/Xcode/DerivedData/cswift-fjyhynvvlsnuujdxujqngcntiouz/Build/Intermediates/cswift.build/Debug/cswift.build/Objects-normal/x86_64/add~partial.swiftmodule -serialize-diagnostics-path /Users/yume/Library/Developer/Xcode/DerivedData/cswift-fjyhynvvlsnuujdxujqngcntiouz/Build/Intermediates/cswift.build/Debug/cswift.build/Objects-normal/x86_64/add.dia -emit-dependencies-path /Users/yume/Library/Developer/Xcode/DerivedData/cswift-fjyhynvvlsnuujdxujqngcntiouz/Build/Intermediates/cswift.build/Debug/cswift.build/Objects-normal/x86_64/add.d -emit-reference-dependencies-path /Users/yume/Library/Developer/Xcode/DerivedData/cswift-fjyhynvvlsnuujdxujqngcntiouz/Build/Intermediates/cswift.build/Debug/cswift.build/Objects-normal/x86_64/add.swiftdeps -o /Users/yume/Library/Developer/Xcode/DerivedData/cswift-fjyhynvvlsnuujdxujqngcntiouz/Build/Intermediates/cswift.build/Debug/cswift.build/Objects-normal/x86_64/add.o MergeSwiftModule normal x86_64 /Users/yume/Library/Developer/Xcode/DerivedData/cswift-fjyhynvvlsnuujdxujqngcntiouz/Build/Intermediates/cswift.build/Debug/cswift.build/Objects-normal/x86_64/cswift.swiftmodule cd /Users/yume/Desktop/cswift /Applications/Xcode8_2_1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -emit-module /Users/yume/Library/Developer/Xcode/DerivedData/cswift-fjyhynvvlsnuujdxujqngcntiouz/Build/Intermediates/cswift.build/Debug/cswift.build/Objects-normal/x86_64/add~partial.swiftmodule -parse-as-library -target x86_64-apple-macosx10.12 -enable-objc-interop -sdk /Applications/Xcode8_2_1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk -I /Users/yume/Library/Developer/Xcode/DerivedData/cswift-fjyhynvvlsnuujdxujqngcntiouz/Build/Products/Debug -F /Users/yume/Library/Developer/Xcode/DerivedData/cswift-fjyhynvvlsnuujdxujqngcntiouz/Build/Products/Debug -enable-testing -g -module-cache-path /Users/yume/Library/Developer/Xcode/DerivedData/ModuleCache -serialize-debugging-options -Xcc -I/Users/yume/Library/Developer/Xcode/DerivedData/cswift-fjyhynvvlsnuujdxujqngcntiouz/Build/Intermediates/cswift.build/Debug/cswift.build/swift-overrides.hmap -Xcc -iquote -Xcc /Users/yume/Library/Developer/Xcode/DerivedData/cswift-fjyhynvvlsnuujdxujqngcntiouz/Build/Intermediates/cswift.build/Debug/cswift.build/cswift-generated-files.hmap -Xcc -I/Users/yume/Library/Developer/Xcode/DerivedData/cswift-fjyhynvvlsnuujdxujqngcntiouz/Build/Intermediates/cswift.build/Debug/cswift.build/cswift-own-target-headers.hmap -Xcc -I/Users/yume/Library/Developer/Xcode/DerivedData/cswift-fjyhynvvlsnuujdxujqngcntiouz/Build/Intermediates/cswift.build/Debug/cswift.build/cswift-all-target-headers.hmap -Xcc -iquote -Xcc /Users/yume/Library/Developer/Xcode/DerivedData/cswift-fjyhynvvlsnuujdxujqngcntiouz/Build/Intermediates/cswift.build/Debug/cswift.build/cswift-project-headers.hmap -Xcc -I/Users/yume/Library/Developer/Xcode/DerivedData/cswift-fjyhynvvlsnuujdxujqngcntiouz/Build/Products/Debug/include -Xcc -I/Users/yume/Library/Developer/Xcode/DerivedData/cswift-fjyhynvvlsnuujdxujqngcntiouz/Build/Intermediates/cswift.build/Debug/cswift.build/DerivedSources/x86_64 -Xcc -I/Users/yume/Library/Developer/Xcode/DerivedData/cswift-fjyhynvvlsnuujdxujqngcntiouz/Build/Intermediates/cswift.build/Debug/cswift.build/DerivedSources -Xcc -DDEBUG=1 -Xcc -working-directory/Users/yume/Desktop/cswift -emit-module-doc-path /Users/yume/Library/Developer/Xcode/DerivedData/cswift-fjyhynvvlsnuujdxujqngcntiouz/Build/Intermediates/cswift.build/Debug/cswift.build/Objects-normal/x86_64/cswift.swiftdoc -module-name cswift -emit-objc-header-path /Users/yume/Library/Developer/Xcode/DerivedData/cswift-fjyhynvvlsnuujdxujqngcntiouz/Build/Intermediates/cswift.build/Debug/cswift.build/Objects-normal/x86_64/cswift-Swift.h -o /Users/yume/Library/Developer/Xcode/DerivedData/cswift-fjyhynvvlsnuujdxujqngcntiouz/Build/Intermediates/cswift.build/Debug/cswift.build/Objects-normal/x86_64/cswift.swiftmodule Ditto /Users/yume/Library/Developer/Xcode/DerivedData/cswift-fjyhynvvlsnuujdxujqngcntiouz/Build/Intermediates/cswift.build/Debug/cswift.build/DerivedSources/cswift-Swift.h /Users/yume/Library/Developer/Xcode/DerivedData/cswift-fjyhynvvlsnuujdxujqngcntiouz/Build/Intermediates/cswift.build/Debug/cswift.build/Objects-normal/x86_64/cswift-Swift.h cd /Users/yume/Desktop/cswift /usr/bin/ditto -rsrc /Users/yume/Library/Developer/Xcode/DerivedData/cswift-fjyhynvvlsnuujdxujqngcntiouz/Build/Intermediates/cswift.build/Debug/cswift.build/Objects-normal/x86_64/cswift-Swift.h /Users/yume/Library/Developer/Xcode/DerivedData/cswift-fjyhynvvlsnuujdxujqngcntiouz/Build/Intermediates/cswift.build/Debug/cswift.build/DerivedSources/cswift-Swift.h Ditto /Users/yume/Library/Developer/Xcode/DerivedData/cswift-fjyhynvvlsnuujdxujqngcntiouz/Build/Products/Debug/cswift.swiftmodule/x86_64.swiftmodule /Users/yume/Library/Developer/Xcode/DerivedData/cswift-fjyhynvvlsnuujdxujqngcntiouz/Build/Intermediates/cswift.build/Debug/cswift.build/Objects-normal/x86_64/cswift.swiftmodule cd /Users/yume/Desktop/cswift /usr/bin/ditto -rsrc /Users/yume/Library/Developer/Xcode/DerivedData/cswift-fjyhynvvlsnuujdxujqngcntiouz/Build/Intermediates/cswift.build/Debug/cswift.build/Objects-normal/x86_64/cswift.swiftmodule /Users/yume/Library/Developer/Xcode/DerivedData/cswift-fjyhynvvlsnuujdxujqngcntiouz/Build/Products/Debug/cswift.swiftmodule/x86_64.swiftmodule Ditto /Users/yume/Library/Developer/Xcode/DerivedData/cswift-fjyhynvvlsnuujdxujqngcntiouz/Build/Products/Debug/cswift.swiftmodule/x86_64.swiftdoc /Users/yume/Library/Developer/Xcode/DerivedData/cswift-fjyhynvvlsnuujdxujqngcntiouz/Build/Intermediates/cswift.build/Debug/cswift.build/Objects-normal/x86_64/cswift.swiftdoc cd /Users/yume/Desktop/cswift /usr/bin/ditto -rsrc /Users/yume/Library/Developer/Xcode/DerivedData/cswift-fjyhynvvlsnuujdxujqngcntiouz/Build/Intermediates/cswift.build/Debug/cswift.build/Objects-normal/x86_64/cswift.swiftdoc /Users/yume/Library/Developer/Xcode/DerivedData/cswift-fjyhynvvlsnuujdxujqngcntiouz/Build/Products/Debug/cswift.swiftmodule/x86_64.swiftdoc CompileC /Users/yume/Library/Developer/Xcode/DerivedData/cswift-fjyhynvvlsnuujdxujqngcntiouz/Build/Intermediates/cswift.build/Debug/cswift.build/Objects-normal/x86_64/main.o cswift/main.c normal x86_64 c com.apple.compilers.llvm.clang.1_0.compiler cd /Users/yume/Desktop/cswift export LANG=en_US.US-ASCII /Applications/Xcode8_2_1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -x c -arch x86_64 -fmessage-length=0 -fdiagnostics-show-note-include-stack -fmacro-backtrace-limit=0 -std=gnu99 -fmodules -gmodules -fmodules-cache-path=/Users/yume/Library/Developer/Xcode/DerivedData/ModuleCache -fmodules-prune-interval=86400 -fmodules-prune-after=345600 -fbuild-session-file=/Users/yume/Library/Developer/Xcode/DerivedData/ModuleCache/Session.modulevalidation -fmodules-validate-once-per-build-session -Wnon-modular-include-in-framework-module -Werror=non-modular-include-in-framework-module -Wno-trigraphs -fpascal-strings -O0 -fno-common -Wno-missing-field-initializers -Wno-missing-prototypes -Werror=return-type -Wdocumentation -Wunreachable-code -Werror=deprecated-objc-isa-usage -Werror=objc-root-class -Wno-missing-braces -Wparentheses -Wswitch -Wunused-function -Wno-unused-label -Wno-unused-parameter -Wunused-variable -Wunused-value -Wempty-body -Wconditional-uninitialized -Wno-unknown-pragmas -Wno-shadow -Wno-four-char-constants -Wno-conversion -Wconstant-conversion -Wint-conversion -Wbool-conversion -Wenum-conversion -Wshorten-64-to-32 -Wpointer-sign -Wno-newline-eof -DDEBUG=1 -isysroot /Applications/Xcode8_2_1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk -fasm-blocks -fstrict-aliasing -Wdeprecated-declarations -mmacosx-version-min=10.12 -g -Wno-sign-conversion -Winfinite-recursion -iquote /Users/yume/Library/Developer/Xcode/DerivedData/cswift-fjyhynvvlsnuujdxujqngcntiouz/Build/Intermediates/cswift.build/Debug/cswift.build/cswift-generated-files.hmap -I/Users/yume/Library/Developer/Xcode/DerivedData/cswift-fjyhynvvlsnuujdxujqngcntiouz/Build/Intermediates/cswift.build/Debug/cswift.build/cswift-own-target-headers.hmap -I/Users/yume/Library/Developer/Xcode/DerivedData/cswift-fjyhynvvlsnuujdxujqngcntiouz/Build/Intermediates/cswift.build/Debug/cswift.build/cswift-all-target-headers.hmap -iquote /Users/yume/Library/Developer/Xcode/DerivedData/cswift-fjyhynvvlsnuujdxujqngcntiouz/Build/Intermediates/cswift.build/Debug/cswift.build/cswift-project-headers.hmap -I/Users/yume/Library/Developer/Xcode/DerivedData/cswift-fjyhynvvlsnuujdxujqngcntiouz/Build/Products/Debug/include -I/Users/yume/Library/Developer/Xcode/DerivedData/cswift-fjyhynvvlsnuujdxujqngcntiouz/Build/Intermediates/cswift.build/Debug/cswift.build/DerivedSources/x86_64 -I/Users/yume/Library/Developer/Xcode/DerivedData/cswift-fjyhynvvlsnuujdxujqngcntiouz/Build/Intermediates/cswift.build/Debug/cswift.build/DerivedSources -F/Users/yume/Library/Developer/Xcode/DerivedData/cswift-fjyhynvvlsnuujdxujqngcntiouz/Build/Products/Debug -MMD -MT dependencies -MF /Users/yume/Library/Developer/Xcode/DerivedData/cswift-fjyhynvvlsnuujdxujqngcntiouz/Build/Intermediates/cswift.build/Debug/cswift.build/Objects-normal/x86_64/main.d --serialize-diagnostics /Users/yume/Library/Developer/Xcode/DerivedData/cswift-fjyhynvvlsnuujdxujqngcntiouz/Build/Intermediates/cswift.build/Debug/cswift.build/Objects-normal/x86_64/main.dia -c /Users/yume/Desktop/cswift/cswift/main.c -o /Users/yume/Library/Developer/Xcode/DerivedData/cswift-fjyhynvvlsnuujdxujqngcntiouz/Build/Intermediates/cswift.build/Debug/cswift.build/Objects-normal/x86_64/main.o
import Glibc
let path = “./sample.txt” let BUFSIZE = 1024
let fp = fopen(path, “r”) if fp != nil { var buf = CChar ) while fgets(&buf, Int32(BUFSIZE), fp) != nil { print(String.fromCString(buf)!, terminator:””) } }
./swift/utils/build-script –build-subdir mybuild_linux
-R --lldb --llbuild --xctest --foundation --libdispatch
--
--install-libdispatch
--install-foundation
--install-swift
--install-lldb
--install-llbuild
--install-xctest
--install-prefix=/usr '--swift-install-components=autolink-driver;compiler;clang-builtin-headers;stdlib;swift-remote-mirror;sdk-overlay;dev' --build-swift-static-stdlib --build-swift-static-sdk-overlay --install-destdir=${INSTALL_DIR} --installable-package=${PACKAGE} --verbose-build