Compile Swift 4.0-dev on CentOS7.2

环境:

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

相关文章

软件简介:蓝湖辅助工具,减少移动端开发中控件属性的复制和粘...
现实生活中,我们听到的声音都是时间连续的,我们称为这种信...
前言最近在B站上看到一个漂亮的仙女姐姐跳舞视频,循环看了亿...
【Android App】实战项目之仿抖音的短视频分享App(附源码和...
前言这一篇博客应该是我花时间最多的一次了,从2022年1月底至...
因为我既对接过session、cookie,也对接过JWT,今年因为工作...