环境:
CentOS7.2 x64,Python 3.6,GCC 4.8.5
一. 先按 swift官网的linux安装方法来,出了问题,再参考这里:
https://github.com/apple/swift
二. 我在CentOS 7.2上遇到的问题及解决方案:
1. sudo yum install clang gcc-c++ uuid-devel libicu-devel icu libedit-devel
libxml2-devel sqlite-devel swig python-devel ncurses-libs ncurses-devel
pkgconfig libuuid-devel epel-release libbsd-devel ninja-build libatomic
libblocksruntime-devel libcurl4-openssl-devel autoconf libtool systemtap-sdt-devel tzdata
2. clang(++) reserves the word __block when you enable -fblocks support. Alas,
unistd.h has (for a VERY long time) used this as the name of a variable,which
causes clang to throw a fit:
/usr/include/unistd.h:1147:35: error: __block attribute not allowed,only
allowed on local variables
extern void encrypt (char *__block,int __edflag) __THROW __nonnull ((1));
You can fix the file by:
sed -i -e 's/\*__block/\*__libc_block/g' /usr/include/unistd.h
(做个backup,后面记得改回来)
3. cd swift/utils/gyb_Syntax_support
change the package import mechanism for all *.py files (if you use python3)
这几个都是local import方式,python3 要这种格式: from .Nodes import xxxx
不然提示找不到package,因为没有前面的".",python3就去sites-package里去找了。
这个目录下所有py文件都要改。
4. change branch
./swift/utils/update-checkout --scheme swift-3.1-branch
这个我没有用,直接就是最新的swift-4.0-dev
5. runtime block
git clone https://github.com/mackyle/blocksruntime.git
CFLAGS=' -fPIC ' ./buildlib
./installlib
找一个blocksruntime库先装上,Ubuntu上有现成的libblocksruntime-dev,CentOS要自己编译
6. vi /home/media/code/swift_src/swift/stdlib/public/core/Tuple.swift.gyb
line 108: range(1,arity - 1) + [arity])) --> list(range(1,arity - 1)) + [arity])))
这个默认是 range + list,会有类型操作不支持的错误,将range转换为list再相加
7. vi /home/media/code/swift_src/swift/stdlib/public/core/Integers.swift.gyb
comment the import code:
#from string import maketrans,capitalize
and change the maketrans to str.maketrans,capitalize to str.capitalize
Python3将这2个函数内置了,所以导入string会报错
我的环境上基本就遇到这些错误,到此可以编译成功。
Update:
如果遇到CoreFoundation/URL.subproj中缺少定义的错误, 例如:
CoreFundation/URL.subproj/CFURLSessionInterface.c:228:76 error: use of undeclared identifier 'CURLE_NO_CONNECTION_AVAILABLE'
请确认libcurl 的版本, 有些是 curl 7.30后加入的, 在https://curl.haxx.se/docs/install.html 下载最新稳定版编译安装就可以解决。
我的build-script参数:
--libdisptach --install-swiftpm --release --llbuild --swiftpm --foundation --swift-enable-ast-verifier=0 --build-swift-static-stdlib=1 --skip-test-lldb=1
--xctest --lldb --build-args=-j8 --reconfigure
原文链接:https://www.f2er.com/swift/321209.html