为 Raspberry PI(交叉)编译 Swift [英] (Cross-)Compiling Swift for Raspberry PI
问题描述
Swift 现在是开源的.有人试过为 Raspberry PI 编译 Swift 吗?我开始这样做了,但我的 8 GB SD 卡似乎太小了 ;) 是否可以从 Ubuntu 交叉编译它?
8GB SD 卡可以正常工作,但您需要扩展根卷.我让它工作了,/dev/root
分区上的已用空间约为 3.1GB.
以下步骤基于 Andrew Madsen 额外关注 fdisk
中的步骤.
获取 Ubuntu
从 finnie.org 并将其复制到 SD 卡上.启动树莓派.
更改分区
登录树莓派并更改分区大小./dev/root
的默认大小为 1.7G,其中 1.1G 可用.这还不够.
$ df -h已使用的文件系统大小 Avail Use% Mounted on/dev/root 1.7G 540M 1.1G 35%/devtmpfs 458M 4.0K 458M 1%/dev无 4.0K 0 4.0K 0%/sys/fs/cgroup无 93M 228K 93M 1%/运行无 5.0M 0 5.0M 0%/运行/锁定无 462M 0 462M 0%/run/shm无 100M 0 100M 0%/运行/用户/dev/mmcblk0p1 64M 20M 45M 31%/boot/firmware
运行 fdisk
sudo fdisk/dev/mmcblk0
在提示符下输入 p
为打印分区表".有两个分区
/dev/mmcblk0p1 * 2048 133119 65536 c W95 FAT32 (LBA)/dev/mmcblk0p2 133120 3670015 1768448 83 Linux
出现提示时,输入 d
(用于删除),然后输入 2
.然后,通过输入 n
、p
、2
重新创建分区,然后在接下来的两个提示中按 Enter 接受默认值.>
再次输入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
输入 w
将更改写入磁盘,然后重新启动
sudo 重启
调整分区大小
重启后,通过运行调整分区文件系统的大小
sudo resize2fs/dev/mmcblk0p2
交换空间
通过执行设置交换文件
sudo apt-get install dphys-swapfile
安装 libicu-dev 和 clang-3.6
sudo apt-get install libicu-dev clang-3.6
使用 update-alternatives 为 clang 和 clang++ 提供/usr/bin 链接:
sudo update-alternatives --install/usr/bin/clang clang/usr/bin/clang-3.6 100须藤更新替代品 --install/usr/bin/clang++ clang++/usr/bin/clang++-3.6 100
然后,添加@iachievedit 的存储库密钥:
wget -qO- http://dev.iachieved.it/iachievedit.gpg.key |sudo apt-key 添加 -
将适当的存储库添加到sources.list:
echo "deb [arch=armhf] http://iachievedit-repos.s3.amazonaws.com/trusty main" |须藤 tee --append/etc/apt/sources.list
运行 apt-get 更新:
sudo apt-get 更新
安装 Swift
sudo apt-get install swift-2.2
安装完成后,就可以编译 Swift 程序了!
编写 Swift
打开你最喜欢的文本编辑器,编写一个程序,然后保存(例如到hello.swift"):
let device = "Raspberry Pi 2!"打印(来自 Swift 在 \(设备)上的问候")
编译
swiftc hello.swift
并运行它:
./hello来自 Swift 在 Raspberry Pi 2 上的问候!
就是这样!在树莓派上运行 Swift
Swift is now Open Source. Did anyone tried compiling Swift for a Raspberry PI? 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?
A 8GB SD Card works ok, but you'll need to extend the root volume. I have it working and the used space on /dev/root
partition is around 3.1GB.
The steps below are based on the blog post by Andrew Madsen with a little extra focus on the steps inside fdisk
.
Get Ubuntu
Download an image of Ubuntu 14.04 for Raspberry Pi 2 from finnie.org and copy it onto the SD card. Boot the Raspberry Pi.
Change the partition
Log into the Raspberry Pi and change the partition size. The default size for /dev/root
is 1.7G with 1.1G available. 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
sudo fdisk /dev/mmcblk0
At the prompt enter p
for 'print the partition table'. 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
. Then, recreate the partition by entering n
, then p
, then 2
, then pressing enter at the next two prompts accepting the defaults.
Enter p
again and see the second partition is now bigger, now all space on an 8GB card is used.
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
sudo reboot
Resize the partition
After the reboot, resize the partition’s file system by running
sudo resize2fs /dev/mmcblk0p2
Swap space
Setup a swap file by doing
sudo apt-get install dphys-swapfile
Install libicu-dev and clang-3.6
sudo apt-get install libicu-dev clang-3.6
Use update-alternatives to provide /usr/bin links for clang and clang++:
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:
wget -qO- http://dev.iachieved.it/iachievedit.gpg.key | sudo apt-key add -
Add the appropriate repository to 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:
sudo apt-get update
Install Swift
sudo apt-get install swift-2.2
After the installation is complete, you’re ready to compile Swift programs!
Write Swift
Open your favorite text editor, write a program, and save it (e.g. to 'hello.swift’):
let device = "Raspberry Pi 2!"
print("Hello from Swift on \(device)")
Compile it
swiftc hello.swift
and run it:
./hello
Hello from Swift on Raspberry Pi 2!
That’s it! Swift running on Raspberry Pi
这篇关于为 Raspberry PI(交叉)编译 Swift的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!