いろいろやってみるにっき

てきとーに生きている奴の日記

古いエントリのサムネイル画像がリンク切れになってたりするけど、チマチマ修正中


SwiftをWSLで動かす その2

↓を書いたあとにiOSアプリだけを作る話は流れた。でも乗り掛かった舟なので、環境を構築してみる。

 

 

WSLの準備

今まではUbuntu18.04を使っていたが、そろそろUbuntu20.04でもいいだろう。ということで、ストアから新しいUbuntu20.04をインストールする。

f:id:shigeo-t:20210421092323p:plain

f:id:shigeo-t:20210421092348p:plain

あっという間である。

f:id:shigeo-t:20210421092425p:plain

起動する。初回なのでちょっと時間がかかる。

f:id:shigeo-t:20210421092544p:plain

とりあえず、初期では2GBくらいのようだ。Windows TerminalにもUbuntu20.04が追加された。

f:id:shigeo-t:20210421092658p:plain

 

WSLにSwiftをインストール

Swiftインストール

このエントリの手順に沿ってインストールしていく。最初はSwiftのダウンロード。

wget ${SwiftのダウンロードURL}

ここからダウンロードする。何も考えず、最新の5.3.3のUbuntu20.04用をダウンロード。

swift.org

 

1分くらいダウンロードに掛かった。

shigeo-t@LightningII:~$ wget https://swift.org/builds/swift-5.3.3-release/ubuntu2004/swift-5.3.3-RELEASE/swift-5.3.3-RELEASE-ubuntu20.04.tar.gz
--2021-04-21 09:31:00--  https://swift.org/builds/swift-5.3.3-release/ubuntu2004/swift-5.3.3-RELEASE/swift-5.3.3-RELEASE-ubuntu20.04.tar.gz
Resolving swift.org (swift.org)... 169.47.73.10
Connecting to swift.org (swift.org)|169.47.73.10|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 411919110 (393M) [application/x-gzip]
Saving to: ‘swift-5.3.3-RELEASE-ubuntu20.04.tar.gz’

swift-5.3.3-RELEASE-ubuntu20. 100%[=================================================>] 392.84M  8.61MB/s    in 49s

2021-04-21 09:31:50 (8.03 MB/s) - ‘swift-5.3.3-RELEASE-ubuntu20.04.tar.gz’ saved [411919110/411919110]

 

次は展開。

shigeo-t@LightningII:~$ tar -zxvf swift-5.3.3-RELEASE-ubuntu20.04.tar.gz -C swift/
swift-5.3.3-RELEASE-ubuntu20.04/usr/
swift-5.3.3-RELEASE-ubuntu20.04/usr/bin/
swift-5.3.3-RELEASE-ubuntu20.04/usr/bin/swift-api-digester
swift-5.3.3-RELEASE-ubuntu20.04/usr/bin/llvm-cov
swift-5.3.3-RELEASE-ubuntu20.04/usr/bin/swift-symbolgraph-extract
swift-5.3.3-RELEASE-ubuntu20.04/usr/bin/repl_swift
swift-5.3.3-RELEASE-ubuntu20.04/usr/bin/plutil
## 中略
swift-5.3.3-RELEASE-ubuntu20.04/usr/include/unicode/dtintrv.h
swift-5.3.3-RELEASE-ubuntu20.04/usr/include/unicode/plurrule.h
swift-5.3.3-RELEASE-ubuntu20.04/usr/include/unicode/gender.h
swift-5.3.3-RELEASE-ubuntu20.04/usr/include/unicode/udateintervalformat.h
swift-5.3.3-RELEASE-ubuntu20.04/usr/include/unicode/fieldpos.h

 

次はパスを通す。例のままやったら通らなかった。echo 'export PATH=/home/${ユーザー名}/swift/usr/bin:"${PATH}"' >> .bashrc

調べたらもう一個階層があった。確かにtarで展開している時にそうなってる。そこでコピーして問題が無ければ元を消すことにした。

shigeo-t@LightningII:~/swift$ cp -r swift-5.3.3-RELEASE-ubuntu20.04/usr/ .
shigeo-t@LightningII:~/swift$ ls -las
total 16
4 drwxr-xr-x 4 shigeo-t shigeo-t 4096 Apr 21 09:52 .
4 drwxr-xr-x 4 shigeo-t shigeo-t 4096 Apr 21 09:34 ..
4 drwxr-xr-x 3 shigeo-t shigeo-t 4096 Apr 21 09:34 swift-5.3.3-RELEASE-ubuntu20.04
4 drwxr-xr-x 7 shigeo-t shigeo-t 4096 Apr 21 09:52 usr
shigeo-t@LightningII:~/swift$ cd usr/
shigeo-t@LightningII:~/swift/usr$ ls -las
total 28
4 drwxr-xr-x 7 shigeo-t shigeo-t 4096 Apr 21 09:52 .
4 drwxr-xr-x 4 shigeo-t shigeo-t 4096 Apr 21 09:52 ..
4 drwxr-xr-x 3 shigeo-t shigeo-t 4096 Apr 21 09:52 bin
4 drwxr-xr-x 5 shigeo-t shigeo-t 4096 Apr 21 09:52 include
4 drwxr-xr-x 5 shigeo-t shigeo-t 4096 Apr 21 09:52 lib
4 drwxr-xr-x 3 shigeo-t shigeo-t 4096 Apr 21 09:52 local
4 drwxr-xr-x 6 shigeo-t shigeo-t 4096 Apr 21 09:52 share

物は所定の場所に入った。確認する。

## コピー前
shigeo-t@LightningII:~$ swift --version

Command 'swift' not found, but can be installed with:

sudo apt install python3-swiftclient

## コピー後
shigeo-t@LightningII:~/swift/usr$ cd
shigeo-t@LightningII:~$ swift --version
swift: error while loading shared libraries: libz3.so.4: cannot open shared object file: No such file or directory

 

エラーは変わったけどエラーには変わりがない。swiftコマンドは動いているけどlibz3.so.4が無いようだ。調べてみた。

https://ubuntu.pkgs.org/20.04/ubuntu-universe-amd64/libz3-4_4.8.7-4build1_amd64.deb.html

  1. Update the package index:
    # sudo apt-get update
  2. Install libz3-4 deb package:
    # sudo apt-get install libz3-4

じゃあインストールしましょう。このUbuntuまっさらだし。

shigeo-t@LightningII:~$ sudo apt-get update -y
Hit:1 http://archive.ubuntu.com/ubuntu focal InRelease
Get:2 http://archive.ubuntu.com/ubuntu focal-updates InRelease [114 kB]
Get:3 http://security.ubuntu.com/ubuntu focal-security InRelease [109 kB]
Get:4 http://archive.ubuntu.com/ubuntu focal-backports InRelease [101 kB]
Get:5 http://security.ubuntu.com/ubuntu focal-security/main amd64 Packages [623 kB]
Get:6 http://archive.ubuntu.com/ubuntu focal/universe amd64 Packages [8628 kB]
Get:7 http://security.ubuntu.com/ubuntu focal-security/main Translation-en [127 kB]
Get:8 http://security.ubuntu.com/ubuntu focal-security/main amd64 c-n-f Metadata [7464 B]
Get:9 http://security.ubuntu.com/ubuntu focal-security/restricted amd64 Packages [183 kB]
Get:10 http://security.ubuntu.com/ubuntu focal-security/restricted Translation-en [27.0 kB]
Get:11 http://security.ubuntu.com/ubuntu focal-security/restricted amd64 c-n-f Metadata [396 B]
Get:12 http://security.ubuntu.com/ubuntu focal-security/universe amd64 Packages [552 kB]
Get:13 http://security.ubuntu.com/ubuntu focal-security/universe Translation-en [82.8 kB]
Get:14 http://security.ubuntu.com/ubuntu focal-security/universe amd64 c-n-f Metadata [10.8 kB]
Get:15 http://security.ubuntu.com/ubuntu focal-security/multiverse amd64 Packages [14.8 kB]
Get:16 http://security.ubuntu.com/ubuntu focal-security/multiverse Translation-en [3160 B]
Get:17 http://security.ubuntu.com/ubuntu focal-security/multiverse amd64 c-n-f Metadata [340 B]
Get:18 http://archive.ubuntu.com/ubuntu focal/universe Translation-en [5124 kB]
Get:19 http://archive.ubuntu.com/ubuntu focal/universe amd64 c-n-f Metadata [265 kB]
Get:20 http://archive.ubuntu.com/ubuntu focal/multiverse amd64 Packages [144 kB]
Get:21 http://archive.ubuntu.com/ubuntu focal/multiverse Translation-en [104 kB]
Get:22 http://archive.ubuntu.com/ubuntu focal/multiverse amd64 c-n-f Metadata [9136 B]
Get:23 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages [947 kB]
Get:24 http://archive.ubuntu.com/ubuntu focal-updates/main Translation-en [216 kB]
Get:25 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 c-n-f Metadata [13.2 kB]
Get:26 http://archive.ubuntu.com/ubuntu focal-updates/restricted amd64 Packages [207 kB]
Get:27 http://archive.ubuntu.com/ubuntu focal-updates/restricted Translation-en [30.7 kB]
Get:28 http://archive.ubuntu.com/ubuntu focal-updates/restricted amd64 c-n-f Metadata [440 B]
Get:29 http://archive.ubuntu.com/ubuntu focal-updates/universe amd64 Packages [760 kB]
Get:30 http://archive.ubuntu.com/ubuntu focal-updates/universe Translation-en [163 kB]
Get:31 http://archive.ubuntu.com/ubuntu focal-updates/universe amd64 c-n-f Metadata [17.2 kB]
Get:32 http://archive.ubuntu.com/ubuntu focal-updates/multiverse amd64 Packages [21.6 kB]
Get:33 http://archive.ubuntu.com/ubuntu focal-updates/multiverse Translation-en [5508 B]
Get:34 http://archive.ubuntu.com/ubuntu focal-updates/multiverse amd64 c-n-f Metadata [600 B]
Get:35 http://archive.ubuntu.com/ubuntu focal-backports/main amd64 c-n-f Metadata [112 B]
Get:36 http://archive.ubuntu.com/ubuntu focal-backports/restricted amd64 c-n-f Metadata [116 B]
Get:37 http://archive.ubuntu.com/ubuntu focal-backports/universe amd64 Packages [4032 B]
Get:38 http://archive.ubuntu.com/ubuntu focal-backports/universe Translation-en [1448 B]
Get:39 http://archive.ubuntu.com/ubuntu focal-backports/universe amd64 c-n-f Metadata [224 B]
Get:40 http://archive.ubuntu.com/ubuntu focal-backports/multiverse amd64 c-n-f Metadata [116 B]
Fetched 18.6 MB in 6s (3033 kB/s)
Reading package lists... Done
shigeo-t@LightningII:~$ sudo apt-get install libz3-4 -y
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
  libz3-4
0 upgraded, 1 newly installed, 0 to remove and 62 not upgraded.
Need to get 6792 kB of archives.
After this operation, 22.7 MB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu focal/universe amd64 libz3-4 amd64 4.8.7-4build1 [6792 kB]
Fetched 6792 kB in 3s (2599 kB/s)
Selecting previously unselected package libz3-4:amd64.
(Reading database ... 32157 files and directories currently installed.)
Preparing to unpack .../libz3-4_4.8.7-4build1_amd64.deb ...
Unpacking libz3-4:amd64 (4.8.7-4build1) ...
Setting up libz3-4:amd64 (4.8.7-4build1) ...
Processing triggers for libc-bin (2.31-0ubuntu9.2) ...
shigeo-t@LightningII:~$ swift --version
Swift version 5.3.3 (swift-5.3.3-RELEASE)
Target: x86_64-unknown-linux-gnu

 今度は通った。例はUbuntu18.04だったし、まあこんなこともあるでしょう。

 

VS Codeの準備

Windows上でSwiftの環境構築をする (WSL + VS Code) - Qiita では

公式の拡張機能もあるようなのですが、今のところ利用するためにビルドが必要とのことなので「Maintained Swift Development Environment (SDE)」を利用することにします。

探してインストール。

f:id:shigeo-t:20210421103114p:plain

 

次にこうなっているので設定してみる。

ファイル/基本設定/設定 から設定画面に入り、Swiftで検索すると出てくる項目から次のものを設定してください。

  • Swift > Path: Swift_driver_bin (上記の手順でインストールしている場合 /home/${ユーザー名}/swift/bin/swift)
  • Sde: Language Server Mode (sourcekit-lsp)
  • Sourcekit-lsp: Server Path (上記の手順でインストールしている場合 /home/${ユーザー名}/swift/bin/sourcekit-lsp)

f:id:shigeo-t:20210421103821p:plain

f:id:shigeo-t:20210421103911p:plain

f:id:shigeo-t:20210421103930p:plain

 

以上で終了。ヒマがあったら触ってみる。

【Swift】作って学ぼうiOSアプリ開発

【Swift】作って学ぼうiOSアプリ開発

 

 

お時間あったら、他のエントリもクリックして頂ければ幸いです。