[英](Cross-)Compiling Swift for Raspberry PI
Swift is now Open Source. Swift现在是开源的。 Did anyone tried compiling Swift for a Raspberry PI? 有人试过为Raspberry PI编译Swift吗? I started to do, but my 8 GB SD card seems to be too small for it ;) Is it possible to cross compile it from Ubuntu? 我开始做了,但我的8 GB SD卡似乎太小了;)是否可以从Ubuntu交叉编译?
A 8GB SD Card works ok, but you'll need to extend the root volume. 8GB SD卡工作正常,但您需要扩展根音量。 I have it working and the used space on /dev/root
partition is around 3.1GB. 我有它工作, /dev/root
分区上的已用空间大约为3.1GB。
The steps below are based on the blog post by Andrew Madsen with a little extra focus on the steps inside fdisk
. 以下步骤基于Andrew Madsen的博客文章,稍微关注fdisk
的步骤。
Download an image of Ubuntu 14.04 for Raspberry Pi 2 from finnie.org and copy it onto the SD card. 从finnie.org下载Ubuntu 14.04 for Raspberry Pi 2的图像并将其复制到SD卡上。 Boot the Raspberry Pi. 启动Raspberry Pi。
Log into the Raspberry Pi and change the partition size. 登录Raspberry Pi并更改分区大小。 The default size for /dev/root
is 1.7G with 1.1G available. /dev/root
的默认大小为1.7G,可用1.1G。 That is not enough. 这还不够。
$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/root 1.7G 540M 1.1G 35% /
devtmpfs 458M 4.0K 458M 1% /dev
none 4.0K 0 4.0K 0% /sys/fs/cgroup
none 93M 228K 93M 1% /run
none 5.0M 0 5.0M 0% /run/lock
none 462M 0 462M 0% /run/shm
none 100M 0 100M 0% /run/user
/dev/mmcblk0p1 64M 20M 45M 31% /boot/firmware
Run fdisk 运行fdisk
sudo fdisk /dev/mmcblk0
At the prompt enter p
for 'print the partition table'. 在提示符下输入p
''打印分区表'。 There are two partitions 有两个分区
/dev/mmcblk0p1 * 2048 133119 65536 c W95 FAT32 (LBA)
/dev/mmcblk0p2 133120 3670015 1768448 83 Linux
When prompted, enter d
(for delete), then 2
. 出现提示时,输入d
(删除),然后输入2
。 Then, recreate the partition by entering n
, then p
, then 2
, then pressing enter at the next two prompts accepting the defaults. 然后,通过输入n
,然后是p
,然后输入2
重新创建分区,然后在接下来的两个提示中按Enter键接受默认值。
Enter p
again and see the second partition is now bigger, now all space on an 8GB card is used. 再次输入p
并看到第二个分区现在更大,现在使用8GB卡上的所有空间。
Device Boot Start End Blocks Id System
/dev/mmcblk0p1 * 2048 133119 65536 c W95 FAT32 (LBA)
/dev/mmcblk0p2 133120 15523839 7695360 83 Linux
Enter w
to write the changes to disk, then reboot 输入w
将更改写入磁盘,然后重新启动
sudo reboot
After the reboot, resize the partition's file system by running 重新启动后,通过运行调整分区文件系统的大小
sudo resize2fs /dev/mmcblk0p2
Setup a swap file by doing 通过执行设置交换文件
sudo apt-get install dphys-swapfile
sudo apt-get install libicu-dev clang-3.6
Use update-alternatives to provide /usr/bin links for clang and clang++: 使用update-alternatives为clang和clang ++提供/ usr / bin链接:
sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-3.6 100
sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-3.6 100
Then, add @iachievedit's repository key: 然后,添加@ iachievedit的存储库密钥:
wget -qO- http://dev.iachieved.it/iachievedit.gpg.key | sudo apt-key add -
Add the appropriate repository to sources.list: 将相应的存储库添加到sources.list:
echo "deb [arch=armhf] http://iachievedit-repos.s3.amazonaws.com/ trusty main" | sudo tee --append /etc/apt/sources.list
Run apt-get update: 运行apt-get update:
sudo apt-get update
sudo apt-get install swift-2.2
After the installation is complete, you're ready to compile Swift programs! 安装完成后,您就可以编译Swift程序了!
Open your favorite text editor, write a program, and save it (eg to 'hello.swift'): 打开您喜欢的文本编辑器,编写程序并保存(例如'hello.swift'):
let device = "Raspberry Pi 2!"
print("Hello from Swift on \(device)")
swiftc hello.swift
and run it: 并运行它:
./hello
Hello from Swift on Raspberry Pi 2!
That's it! 而已! Swift running on Raspberry Pi Swift在Raspberry Pi上运行
The Swift Package Manager got custom toolchain support via PR-1098 end of April 2017. Swift Package Manager在2017年4月底通过PR-1098获得了定制工具链支持。
I wrote up detailed instructions on how to build a RaspberryPi toolchain over here: macOS -> RasPi Cross Compilation Toolchain and even the reverse ( build macOS binaries on a RaspberryPi ) for the fun of it. 我写了关于如何在这里构建RaspberryPi工具链的详细说明: macOS - > RasPi交叉编译工具链 ,甚至反过来( 在RaspberryPi上构建macOS二进制文件 )以获得它的乐趣。 The same would work for Intel-Linux to ARM-Linux w/ minimal modifications. 这同样适用于Intel-Linux到ARM-Linux的最小修改。 The SwiftPM repo contains an example script on how to do this for Intel-macOS to Intel-Ubuntu. SwiftPM repo包含一个示例脚本 ,介绍如何将Intel-macOS用于Intel-Ubuntu。
You can find a 2017-05-01 update on Swift-on-ARM over here: An Update on Swift 3.1.1 For Raspberry Pi Zero/1/2/3 . 你可以在这里找到关于Swift-on-ARM的2017-05-01更新: Swift 3.1.1更新为Raspberry Pi Zero / 1/2/3 。
As a small summary, so that this answer isn't just links ;-), ARM status 2017-05-16: 作为一个小小的总结,这个答案不只是链接;-),ARM状态2017-05-16:
swift-arm
Swift ARM有一个Slack组: swift-arm
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.