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

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值