2016-08-05 30 views
2

我很努力地在Ubuntu 16.04上安裝Swift 3.0和GCD。這應該是現在可能的,對吧?在帶有Ansible的Linux上安裝Swift 3 + libdispatch

下面是從swift.org下載Swift 3,從GitHub克隆,構建和安裝swift-corelibs-libdispatch的Ansible任務。

儘管libdispatch的安裝完成沒有錯誤,但它不起作用。當我在Swift repl中嘗試import Dispatch時,它抱怨缺少特徵「塊」。檢查Makefiles確認,至少向編譯器提供了標誌-fblocks

下面是雨燕REPL輸出的例子:

[email protected]:/tmp/swift-3.0-PREVIEW-3-ubuntu15.10/usr/bin$ ./swift 
Welcome to Swift version 3.0 (swift-3.0-PREVIEW-3). Type :help for assistance. 
    1> 6 * 7 
$R0: Int = 42 
    2> import Dispatch 
error: module 'CDispatch' requires feature 'blocks' 
error: could not build Objective-C module 'CDispatch' 

    2> 

Vagrantfile設立一個對話框:

# -*- mode: ruby -*- 
# vi: set ft=ruby : 


Vagrant.configure(2) do |config| 
    config.ssh.forward_agent = true 
    config.vm.box = "bento/ubuntu-16.04" 

    config.vm.define "swift3" do |dev| 
     dev.vm.hostname = "swift3.dev" 
    end 

    config.vm.network :private_network, ip: "10.0.0.10" 

    config.vm.provider "virtualbox" do |vb| 
     vb.memory = "2048" 
    end 

    config.vm.provision "ansible" do |ansible| 
     ansible.playbook = "ansible/main.yml" 
    end 
end 

Ansible任務安裝斯威夫特3:

--- 

- name: Install Swift 3 requirements 
    apt: name={{ item }} state=installed 
    with_items: 
    - autoconf 
    - clang 
    - git 
    - libblocksruntime-dev 
    - libbsd-dev 
    - libcurl4-openssl-dev 
    - libdispatch-dev 
    - libkqueue-dev 
    - libpython2.7-dev 
    - libtool 
    - pkg-config 


- name: download Swift 3 
    get_url: url=https://swift.org/builds/swift-3.0-preview-3/ubuntu1510/swift-3.0-PREVIEW-3/swift-3.0-PREVIEW-3-ubuntu15.10.tar.gz 
      dest=/tmp/swift.tgz mode=0440 

- name: unarchive Swift 3 
    unarchive: dest=/tmp src=/tmp/swift.tgz copy=no creates=/tmp/swift-3.0-PREVIEW-3-ubuntu15.10 

- name: clone Swift 3 libdispatch core library 
    git: repo=https://github.com/apple/swift-corelibs-libdispatch dest=/tmp/swift-corelibs-libdispatch 
     version=swift-3.0-preview-3-branch force=true 

- name: generate Swift 3 libdispatch build files 
    command: "sh ./autogen.sh" 
    args: 
    chdir: /tmp/swift-corelibs-libdispatch 

- name: configure Swift 3 libdispatch 
    command: "sh ./configure --with-blocks-runtime=/usr/lib/x86_64-linux-gnu --with-swift-toolchain=/tmp/swift-3.0-PREVIEW-3-ubuntu15.10/usr --prefix=/tmp/swift-3.0-PREVIEW-3-ubuntu15.10/usr" 
    args: 
    chdir: /tmp/swift-corelibs-libdispatch 

- name: make Swift 3 libdispatch 
    command: "make" 
    args: 
    chdir: /tmp/swift-corelibs-libdispatch 

- name: install Swift 3 libdispatch 
    command: "make install" 
    args: 
    chdir: /tmp/swift-corelibs-libdispatch 

- name: grant permissions to use Swift 3 
    file: dest=/tmp/swift-3.0-PREVIEW-3-ubuntu15.10 mode=a+rX recurse=true 
+0

雖然我對Swift 3一無所知,但我可以建議您可以跳過安裝程序(通過使用'--no-provision'標誌)並手動運行安裝步驟以隔離問題區。如果有效,那麼問題可能在劇本中。如果它仍然不起作用,那麼問題可能是盒子圖像中缺少一些依賴關係。 – Amit

回答

1

正如你已經注意到-fblocks鏈接器標誌在編譯時適當地爲libdispatch設置。這很好,因爲現在你有一個工作版本的libdispatch。

不幸的是什麼,你化妝包括Dispatch將要求-fblocks鏈接器標誌了。

tl; dr解決方法是在編譯時簡單地提供-Xcc -fblocksswiftc

這就像我說過的解決方法。較長期的解決方案是建議"ClangImporter: enable -fblocks on non-Darwin platforms"。儘管如此,儘管上述解決方法是距離您想要去的地方最短的距離。

我會自己補充一點,我只是使用上面拉取請求中的補丁來修補我的本地版本。因人而異。