Tuesday, March 15, 2016

Personal Installation Guide for Raspberry Pi 3 with Swift

Hardware List from RS:
Raspberry Pi 3 Model B SBC
Heatsink BGA 12x12 27K/W black
Official Pi 3 Power Supply Black
Official Pi 3 Black/Grey Case

MicroSDHC Card (with Adapter) 32G Class 10
USB SSD Harddisk 240G
USB Keyboard and Mouse

SD Card images for multiboot
1. NOOBS(easy to install but hard to reconfigure or add custom image for multiboot)
#Download NOOBS using Mac Terminal and write to MicroSDHC Card (with Adapter and mounted in Mac)
cd ~/Downloads
wget http://vx2-downloads.raspberrypi.org/NOOBS/images/NOOBS-2016-02-29/NOOBS_v1_8_0.zip
unzip NOOBS_v1_8_0.zip -d /Volumes/NO\ NAME/

#insert the SD card and power on the machine
#after boot into NOOBS and choose install Rasbian and OSMC (that is kodi)
#Rasbian username and password are pi and raspberry respectively
#OSMC username and password are all osmc

2. BerryBoot(very flexible and allow to add custom image for multiboot)
wget http://downloads.sourceforge.net/project/berryboot/berryboot-20160313-pi2-pi3.zip
# for reformat SD Card to FAT32 and label BERRYBOOT
# sudo diskutil eraseDisk FAT32 BERRYBOOT MBRFormat /dev/disk4

unzip berryboot-20160313-pi2-pi3.zip -d /Volumes/BERRYBOOT/

#insert the SD card and power on the machine
#after boot into BerryBoot and choose install Debian Rasbian, OpenELEC (that is kodi) or others
#OpenELEC username and password are root and openelec respectively.
#hold down mouse button on AddOS button of BerryBoot Menu and choose Copy OS from USB stick

#To install Ubuntu-trusty image for berryboot downloaded here below
# login to Ubuntu-trusty, username and password are all ubuntu

#BerryBoot additional images are here below and can be downloaded in USB drive for offline installation

It is possible to shrink the Linux partition of berryboot in order to create a third partition for the dphys-swapfile with about 2G size. The SD card for berryboot should be mounted as USB and Use  sudo umount /dev/sda2; sudo e2fsck -f /dev/sda2; sudo resize2fs /dev/sda2 27G;  to check and shrink and use  sudo fdisk /dev/sda;  to delete the second partition, recreate the second partition with +27G and then create the third partition with remaining space for swap (about 2.5G if for 32G SD card). And then  sudo mkfs.ext4 /dev/sda3;  to format as ext4 and run  sudo fsck.ext4 /dev/sda1; sudo fsck.ext4 /dev/sda2;  to check.
After booting into the berryboot SD card, add this in /etc/fstab
/dev/mmcblk0p3 /swap ext4 defaults,noatime 0 0
and then edit swap location to /swap/swap and mount the partition using  sudo mkdir -p /swap; sudo mount -t ext4 /dev/mmcblk0p3 /swap;  and then setup dphys-swapfile using  sudo vi /etc/dphys-swapfile;  to /swap/swap and run  sudo dphys-swapfile setup; sudo dphys-swapfile swapon; 

shell script    Select all
# change password passwd # su sudo su sudo apt-get update sudo apt-get upgrade sudo apt-get install vim zip unzip openssh-server git #Login to Ubuntu-trusty, username and password are ubuntu and ubuntu respectively # install clang and swift for Ubuntu-trusty only (but no swift package manager) sudo apt-get install libicu-dev clang-3.6 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 #install swift-2.2_1%3a2.2-0ubuntu11~trusty1_armhf.deb (Ubuntu-trusty only) or just download from here without adding source repo #https://mega.nz/#!fpYxzBgY!MLGiW8HAV6MllAD0gkzrSFlQ6TdubwBfFYGyezNVAXg wget -qO- http://dev.iachieved.it/iachievedit.gpg.key | sudo apt-key add - echo "deb [arch=armhf] http://iachievedit-repos.s3.amazonaws.com/ trusty main" | sudo tee --append /etc/apt/sources.list sudo apt-get update sudo apt-get install swift-2.2 swift --version #test simple swift compile cat > hello.swift <<EOF let device = "Raspberry Pi 3!" print("Hello from Swift on \(device)") EOF swiftc hello.swift ./hello #Login to Rasbian, username and password are pi and raspberry respectively #change password (recomended) passwd #Rasbian config to set locale and timezone sudo raspi-config # configure keyboard to US sudo dpkg-reconfigure keyboard-configuration #reload the keymap sudo invoke-rc.d keyboard-setup start #scan hidden SSID sudo iwlist wlan0 scanning essid "Your Hidden SSID" #vi ~/.bashrc and add export LC_ALL="en_US.UTF-8" #add export LS_COLORS=$LS_COLORS:'di=1;44:' ; # dir white on blue background sudo locale-gen en_US.UTF-8 # generate locale for en_US.UTF-8 sudo dpkg-reconfigure locales #command line reset timezone sudo dpkg-reconfigure tzdata apt-get update apt-get upgrade apt-get install vim openssh-server #install nginx (lightweght webserver) sudo apt-get install nginx cd; ln -s /usr/share/nginx/html . #check ip adress and use browser connect to test web server hostname -I ifconfig eth0 ifconfig wlan0 # for wireless lan ip addr | grep -Po '(?!(inet 127.\d.\d.1))(inet \K(\d{1,3}\.){3}\d{1,3})' #install php in nginx sudo apt-get install php5-fpm php-apc # link the html folder to home cd #ln -s /usr/share/nginx/html . ln -s /var/www/html . # create testing php page cat > ~/html/info.php <<EOF <?php phpinfo(); ?> EOF # enable php in nginx sudo vi /etc/nginx/sites-enabled/default #see instructions here https://www.raspberrypi.org/documentation/remote-access/web-server/nginx.md #reload web server and test sudo service nginx reload #install samba as a file server sudo apt-get install samba samba-common-bin #edit /etc/samba/smb.conf and add the followings # assume USB drive is mounted on /media/pi/USBDRIVE #manual mount external drive sudo mkdir -p /media/pi/USBDRIVE sudo mount -o uid=pi,gid=pi,rw /dev/sda1 /media/pi/USBDRIVE [public_USBDRIVE] comment = Public USBDRIVE browseable = yes read only = no force user = "pi" guest ok = yes public = yes writable = yes path = /media/pi/USBDRIVE create mask = 0755 directory mask = 0755 # reload samba sudo service samba reload #install google app engine for development wget --no-check-certificate https://storage.googleapis.com/appengine-sdks/featured/google_appengine_1.9.34.zip unzip google_appengine_1.9.34.zip export PATH=$HOME/google_appengine:$PATH #test GAE web page from localhost web browser dev_appserver.py ~/google_appengine/demos/python/guestbook #test GAE web app from other machine dev_appserver.py --host $(ip addr | grep -Po '(?!(inet 127.\d.\d.1))(inet \K(\d{1,3}\.){3}\d{1,3})') --port 8080 ~/google_appengine/demos/python/guestbook/ dev_appserver.py --host $(hostname -I) --port 8080 ~/google_appengine/demos/python/guestbook/ # download node-v6.9.4-linux-armv7l.tar.xz from https://nodejs.org/en/download/ wget --no-check-certificate https://nodejs.org/dist/v6.9.4/node-v6.9.4-linux-armv7l.tar.xz # extract node-v6.9.4-linux-armv7l.tar.xz cd $HOME tar xJvf $HOME/Download/node-v6.9.4-linux-armv7l.tar.xz # setup PATH export PATH=$HOME/node-v6.9.4-linux-armv7l/bin:$PATH # Compile and Install Visual Studio Code 1.9.1 sudo apt-get update sudo apt-get install libx11-dev build-essential cd $HOME git clone https://github.com/microsoft/vscode cd $HOME/vscode git tag -l #checkout 1.9.1 git checkout tags/1.9.1 ./scripts/npm.sh install --arch=armhf # run Visual Studio Code ./scripts/code.sh # Visual Studio Code - Desktop Entry sudo tee /usr/share/applications/code.desktop > /dev/null <<'EOF' [Desktop Entry] Name=Visual Studio Code Comment=Code Editing. Redefined. GenericName=Text Editor Exec=/home/pi/vscode/scripts/code.sh %U Icon=code Type=Application StartupNotify=true StartupWMClass=Code Categories=Utility;TextEditor;Development;IDE; MimeType=text/plain;inode/directory; Actions=new-window; Keywords=vscode; [Desktop Action new-window] Name=New Window Name[de]=Neues Fenster Name[es]=Nueva ventana Name[fr]=Nouvelle fenêtre Name[it]=Nuova finestra Name[ja]=新規ウインドウ Name[ko]=새 창 Name[ru]=Новое окно Name[zh_CN]=新建窗口 Name[zh_TW]=開新視窗 Exec=/home/pi/vscode/scripts/code.sh %U Icon=code EOF # Manual download and install Visual Studio Extension # please refer to how to get the download url as referenced from http://stackoverflow.com/questions/37071388/how-to-install-vscode-extensions-offline wget --no-check-certificate https://ms-vscode.gallery.vsassets.io:443/_apis/public/gallery/publisher/ms-vscode/extension/cpptools/0.10.1/assetbyname/Microsoft.VisualStudio.Services.VSIXPackage mv Microsoft.VisualStudio.Services.VSIXPackage ms-vscode-cpptools.vsix # Then use "Install from VSIX" menu item in Visual Studio code Debug Setting #install squid + unblock cn and assume node.js npm are installed as above sudo apt-get install squid3 git npm install Unblocker/Unblock-Youku #install phantomjs for testing git clone --depth 1 https://github.com/gautamMalu/PhantomJs-armhf.git #optionally install casper tag 1.1.1, PhantomJs+Casper for web scraping git clone --branch '1.1.1' --single-branch --depth 1 https://github.com/casperjs/casperjs.git sudo apt-get install libfontconfig1 libjpeg8 libicu-dev cd PhantomJs-armhf/bin; sudo mv phantomjs /usr/local/bin/ cd ~/node_modules/ub.uku.js/ npm install npm test #cp ~/node_modules/ub.uku.js/shared/urls.js ~/node_modules/ub.uku.js/youku.rules #cat ~/node_modules/ub.uku.js/shared/urls.js | grep "^[ ']*http" | sed "s/^[ ']*/\^/;s/[,'][ ]*\/\/.*$//;s/\*'$//;s/\*',$//;s/',//;s/[*?]$//;s/\*/\.\*/g;s/\?/\\\?/g;" > ~/node_modules/ub.uku.js/youku.rules vi ~/node_modules/ub.uku.js/youku.rules curl -o ~/node_modules/ub.uku.js/youku.rules http://pac.uku.im/regex sudo vi /etc/squid3/squid.conf acl localnet src # RFC1918 possible internal network acl localnet src # RFC1918 possible internal network http_access allow localnet # add acl rules acl uyouku url_regex -i "/home/pi/node_modules/ub.uku.js/youku.rules" never_direct allow uyouku cache_peer parent 8888 0 no-query default cache_peer_access allow uyouku cache_peer_access deny all # enable cache_dir say 2048 (The default is 100 MB) cache_dir ufs /var/spool/squid3 2048 16 256 # 2016/03/09 https://github.com/Unblocker/Unblock-Youku/issues/618 # dns_nameservers #restart squid3 sudo service squid3 reload #edit /home/pi/node_modules/ub.uku.js/server/server.js (near line 257) to change listening ip and port say 8888 # ubuku_server.listen('8888','')... # auto run unblockcn and use http://ipservice.163.com/isFromMainland to test # sudo vi /etc/rc.local and add su pi -c '/usr/bin/nodejs /home/pi/node_modules/ub.uku.js/server/server.js --nolog --proxy=https://secure.uku.im:993 --bak_proxy=http://proxy.uku.im:443 --pac_proxy=http://proxy.uku.im:443 > /dev/null &' # test terminal run with external proxy sudo node /home/pi/node_modules/ub.uku.js/server/server.js --proxy=https://secure.uku.im:993 --bak_proxy=http://proxy.uku.im:443 --pac_proxy=http://proxy.uku.im:443 #support Chinese font 文鼎 PL 上海宋 Un and input method sudo apt-get install ttf-arphic-uming scim-tables-zh im-switch #support Chinese font 文泉驛微米黑體、文泉驛正黑體、文泉驛點陣宋體 sudo apt-get install ttf-wqy-microhei ttf-wqy-zenhei xfonts-wqy #ext4 TRIM command support using the discard mount option in fstab (or with tune2fs -o discard /dev/sdaX). sudo tune2fs -o discard /dev/sdb1 #bitcoind #sudo apt-get install bitcoind # bitcoind deb package in Debian is obsolete and needs upgrade #build from source as below or download the precompiled version from here and use sudo dpkg -i to install https://mega.nz/#!KtJWTZ7A!RN4IOGtvflSc0lXuJB1__lYTkdYvsnoegk_JJ0JGtA8 #Build requirements sudo apt-get install build-essential libtool autotools-dev automake pkg-config libssl-dev libevent-dev bsdmainutils git sudo apt-get install libboost-system-dev libboost-filesystem-dev libboost-chrono-dev libboost-program-options-dev libboost-test-dev libboost-thread-dev libminiupnpc-dev libminiupnpc-dev libzmq3-dev libcrypto++9 minissdpd git clone -b 0.12 --depth 1 https://github.com/bitcoin/bitcoin.git #see here to build bitcoind with Berkeley DB script https://github.com/bitcoin/bitcoin/blob/master/doc/build-unix.md cd bitcoin mkdir -p db4 wget 'http://download.oracle.com/berkeley-db/db-4.8.30.NC.tar.gz' tar -xzvf db-4.8.30.NC.tar.gz cd db-4.8.30.NC/build_unix/ BDB_PREFIX=$(cd $(dirname "../../db4") && pwd -P)/$(basename "../../db4"); ../dist/configure --enable-cxx --disable-shared --with-pic --prefix=$BDB_PREFIX make install cd ../.. ./autogen.sh BDB_PREFIX="$(pwd)/db4"; ./configure LDFLAGS="-L${BDB_PREFIX}/lib/" CPPFLAGS="-I${BDB_PREFIX}/include/" CXXFLAGS="--param ggc-min-expand=1 --param ggc-min-heapsize=32768" --without-gui --with-miniupnpc --enable-upnp-default --disable-tests #Rasbian config to set boot option to CLI mode sudo raspi-config #compiling bitcoind is cpu-intensive and memory-hungry, better to reboot to CLI mode and kill unnecessary services then make -j2 sudo make install #setup bitcoind and let it create bitcoin.conf bitcoind -daemon bitcoin-cli stop #create data directory in USB SSD drive mkdir -p /media/pi/SSDDRIVE/bitcoin cp ~/.bitcoin/bitcoin.conf /media/pi/SSDDRIVE/bitcoin/ cp ~/wallet.dat /media/pi/SSDDRIVE/bitcoin/ # if have old bitcoin wallet.dat #start bitcoind as daemon in SSD Drive bitcoind -datadir=/media/pi/SSDDRIVE/bitcoin -daemon bitcoind --help #while bitcoind is running as daemon, get new address and check other status # bitcoin-cli help bitcoin-cli getinfo bitcoin-cli listaccounts bitcoin-cli getnewaddress "worker1" # check tx history say https://blockchain.info/address/14uUbzJSi2t5MGgYH72PdTonD22V8drBVN bitcoin-cli getaccountaddress "worker1" bitcoin-cli getbalance #daemon will download the entire block chain data and can take over several days and total size > 60G bitcoin-cli getblockcount # the current blockcount should be over 1M https://blockchain.info/latestblock bitcoin-cli getconnectioncount #cpuminer sudo apt-get install libcurl4-openssl-dev git make git clone --depth 1 git://github.com/pooler/cpuminer.git cd cpuminer ./autogen.sh ./configure CFLAGS="-O3" make sudo make install minerd --help minerd --url http://api.bitcoin.cz:8332 -a sha256d --userpass=yourid.worker1:pass1 #cgminer (but not working in Raspberry Pi 3 #OpenCL...............: Detection overrided. GPU mining support DISABLED git clone -b 3.7 https://github.com/ckolivas/cgminer.git cd cgminer ./autogen.sh ./configure --enable-opencl --enable-scrypt # configure failed due to absence of GPU and opencl in Raspberry Pi 3 #libquantlib0-dev 1.4.2 is available in package repo #QuantLib 1.7.1 #or download the updated package from here https://mega.nz/#!PkYWBDLC!dC8klXxcouc1RrNQ2Bct_tSweaO6A3UwTNkGeXvGldo #Download QuantLib source and extract wget http://jaist.dl.sourceforge.net/project/quantlib/QuantLib/1.7.1/QuantLib-1.7.1.tar.gz tar -xzvf QuantLib-1.7.1.tar.gz #Build requirement sudo apt-get install build-essential libtool libboost-all-dev cd QuantLib-1.7.1 ./configure CXXFLAGS="--param ggc-min-expand=1 --param ggc-min-heapsize=32768" --disable-shared #Rasbian config to set boot option to CLI mode sudo raspi-config #compiling QuantLib is cpu-intensive and memory-hungry, better to reboot to CLI mode and kill unnecessary services then make -j2 # or just make if failed sudo make install #test compile QuantLib example cd ~/QuantLib-1.7.1/Examples/Bonds g++ Bonds.cpp -o bin/Bonds -lQuantLib # run example Bonds ./bin/Bonds #compiling litecoind is similar to bitcoind but it would conflict with bitcoind git clone --depth 1 https://github.com/litecoin-project/litecoin.git #build from source or download the precompiled version from here https://mega.nz/#!Ptwl0KZD!XVyO7DHugtoK2iEib2nj2jdyMRSkadlIMa1oPp3QSak #setup litecoind in raspberry pi litecoind #create data directory in USB SSD drive mkdir -p /media/pi/SSDDRIVE/litecoin cp ~/.litecoin/litecoin.conf /media/pi/SSDDRIVE/litecoin/ #start litecoind as daemon in SSD Drive litecoind -datadir=/media/pi/SSDDRIVE/litecoin -daemon litecoind --help #reindex litecoin database if corrupted litecoind -reindex -datadir=/media/pi/SSDDRIVE/litecoin #while litecoind is running as daemon, get new address and check other status # litecoin-cli help litecoin-cli getinfo litecoin-cli listaccounts litecoin-cli getnewaddress "worker2" # check tx history say https://block-explorer.com/address/LRwz2mJpoMz2FPkqE7hxKvcLnUyUHESW4Q litecoin-cli getaccountaddress "worker2" litecoin-cli getbalance litecoin-cli getblockcount # the current blockcount should be over 900000 see http://explorer.litecoin.net/ #setup local repo sudo apt-get install dpkg-dev sudo mkdir -p /usr/local/mydebs sudo cp -s /var/cache/apt/archives/*.deb /usr/local/mydebs/ cd /usr/local/mydebs sudo sh -c 'dpkg-scanpackages . /dev/null | gzip -9c > Packages.gz' echo "deb file:/usr/local/mydebs ./" | sudo tee --append /etc/apt/sources.list sudo apt-get update #setup swapfile in Rasbian sudo vi /etc/dphys-swapfile #edit the swapfile location and size (suggest min 2048) then save the file #for berryboot the swapfile should be in external USB drive sudo dphys-swapfile setup sudo dphys-swapfile swapon #check memory and swap free -h #turn off swap sudo dphys-swapfile swapoff #configure and make again for the projects #shutdown the machine sudo halt #restart the machine sudo reboot

Swift 2.2 for Linux package requires clang-3.6 and Ubuntu-trusty for Pi
This image https://wiki.ubuntu.com/ARM/RaspberryPi (2015-04-06-ubuntu-trusty.img) is for Raspberry Pi 2 and does not work on Raspberry Pi 3, the FAT32 partition content in the layout folder and the start*.elf, bcm2710-rpi-3-b.dtb should be upgraded/added for the new hardware for booting.
config.txt add these settings
initramfs initrd7.img

It is possible to install the Swift 2.2 in Rasbian other than Ubuntu-trusty for Pi
1. Install clang-3.7 and libicu-dev in Rasbian
sudo apt-get install libicu-dev clang-3.7
sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-3.7 100
sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-3.7 100

2. download the package from here without adding source repo

3. download a fake clang-3.6 package that install nothing but to meet dependency as a hack

4. install these deb files together
sudo dkpg -i clang-3.6-fake.deb swift-2.2_1%3a2.2-0ubuntu11~trusty1_armhf.deb

Swift 2.2 for Linux without Swift Package Manager. Here are the alternative ways:
shell script    Select all
#Method 1 : compile everything on build cd ${HOME} mkdir -p SwiftProjects cd ${HOME}/SwiftProjects # get dependency package git clone --depth 1 https://github.com/erica/SwiftString.git git clone --depth 1 https://github.com/haginile/SwiftDate.git #fix some errors in SwiftDate/SwiftDate/DateHelpers.swift and SwiftDate/SwiftDate/Term.swift simlar to previous post "What you need for Swift on Linux" vi SwiftDate/SwiftDate/DateHelpers.swift extension String { /* comment out these 2 func subscript (i: Int) -> String { return String(Array(self.characters)[i]) } subscript (r: Range<int>) -> String { get { let subStart = self.startIndex.advancedBy(r.startIndex, limit: self.endIndex) let subEnd = subStart.advancedBy(r.endIndex - r.startIndex, limit: self.endIndex) return self.substringWithRange(Range(start: subStart, end: subEnd)) } } */ vi +195 SwiftDate/SwiftDate/Term.swift #change from switch timeUnit { #to switch timeUnit! { // unwrapped optional cd ${HOME}/SwiftProjects mkdir -p Sources/Test1 cat > Sources/Test1/main.swift <<EOF #if os(Linux) import Glibc import Foundation #endif //import SwiftString //import SwiftDate import XCTest class SwiftDateTesting: XCTestCase { var allTests : [(String, () -> Void)] { return [ ("testCalendar", testCalendar), ("testDayCounter", testDayCounter), ] } func testCalendar() { var cal = USSettlementCalendar() XCTAssert(cal.isBizDay(Date(string: "2014-05-15")) == true, "Pass") XCTAssert(cal.isBizDay(Date(string: "2014-05-17")) == false, "Pass") XCTAssertEqual(cal.nextBizDay(Date(string: "2014-05-16")).serialNumber, Date(string: "2014-05-19").serialNumber, "Pass") XCTAssertEqual(cal.bizDaysBetween(Date(string: "2014-05-15"), toDate: Date(string : "2014-05-20")), 3, "Pass") } func testDayCounter() { var start_date = Date(string: "2000-01-15") var end_date = Date(string: "2000-05-31") var actual_365 = Actual365Fixed() XCTAssertEqual(actual_365.dayCountFraction(start_date, date2: end_date), 137.0 / 365, "Pass") var nl_365 = NL365() XCTAssertEqual(nl_365.dayCountFraction(start_date, date2: end_date), 136.0 / 365, "Pass") var act_360 = Actual360() XCTAssertEqual(act_360.dayCountFraction(start_date, date2: end_date), 137.0 / 360.0, "Pass") var thirty_360 = Thirty360() XCTAssertEqual(thirty_360.dayCountFraction(start_date, date2: end_date), 136.0 / 360.0, "Pass") var thirty_360e = Thirty360(convention: Thirty360.Convention.EurobondBasis) } } XCTMain([SwiftDateTesting()]) EOF cd Sources/Test1 swiftc -emit-executable ../../SwiftString/Sources/*.swift ../../SwiftDate/SwiftDate/*.swift main.swift -o test1 ./test1 #Method 2 : dynamic library link #build module and library for dynamic linking cd ${HOME}/SwiftProjects mkdir -p Sources/Test2 cat > Sources/Test2/main.swift <<EOF #if os(Linux) import Glibc import Foundation #endif import SwiftDateString let start_date = Date(string: "2000-01-15") var end_date = Date(string: "2000-05-31") var actual_365 = Actual365Fixed() print(actual_365.dayCountFraction(start_date, date2: end_date)) EOF cd Sources/Test2 #build module and dynamic library swiftc -emit-library ../../SwiftString/Sources/*.swift ../../SwiftDate/SwiftDate/*.swift -module-name SwiftDateString -emit-module-path SwiftDateString.swiftmodule -module-name SwiftDateString -module-link-name SwiftDateString #compile and link with dynamic library at current directory swiftc -emit-executable main.swift -o test2 -I. -L. -Xlinker -rpath -Xlinker "." -lSwiftDateString ./test2 #alternative way is to copy the shared library to /usr/lib then link sudo cp libSwiftDateString.so /usr/lib/ swiftc -emit-executable -I. -lSwiftDateString main.swift -o test2a ./test2a #Method 3: static library link #build module and static library for linking cd ${HOME}/SwiftProjects mkdir -p Sources/Test3 cat > Sources/Test3/main.swift <<EOF #if os(Linux) import Glibc import Foundation #endif import SwiftDateString public func timetest(block: () -> Void) { let date = NSDate() block() let timeInterval = NSDate().timeIntervalSinceDate(date) print("Elasped time: \(timeInterval)") } public func testit() { let start_date = Date(string: "2000-01-15") let end_date = Date(string: "2000-05-31") let actual_365 = Actual365Fixed() print("Function: \(__FUNCTION__), File: \(__FILE__)") print("2000-01-15 to 2000-05-31 dayCountFraction is ", terminator:"") print(actual_365.dayCountFraction(start_date, date2: end_date)) } timetest(testit) EOF #compile cd Sources/Test3 swiftc -module-name SwiftDateString -c ../../SwiftString/Sources/*.swift ../../SwiftDate/SwiftDate/*.swift -emit-module-path SwiftDateString.swiftmodule -module-link-name SwiftDateString PROJECT_PREFIX=$(cd $(dirname "../../") && pwd -P)/$(basename "../../"); mkdir -p obj; cd obj; swiftc -parse-as-library -module-name SwiftDateString -emit-object ${PROJECT_PREFIX}/SwiftString/Sources/*.swift ${PROJECT_PREFIX}/SwiftDate/SwiftDate/*.swift; cd .. #build static library ar -rcs libSwiftDateString.a obj/*.o #link with static library swiftc -emit-executable main.swift -o test3 -I. -L. -Xlinker libSwiftDateString.a #Method 4: Use makefile for static library link #makefile to build module and static library for linking cd ${HOME}/SwiftProjects mkdir -p Sources/tidyjson cd Sources/tidyjson git clone --depth 1 https://github.com/benloong/TidyJSON.git # edit TidyJSON/Sources/TidyJSON.swift #find dataUsingEncoding #//if let data = string.dataUsingEncoding(NSUTF8StringEncoding) { #and change it to if let data = NSString(string:string).dataUsingEncoding(NSUTF8StringEncoding) { # edit TidyJSON/Tests/Test.swift #add #if os(Linux) import Glibc #endif # find all lines with # var allTests : [(String, () throws -> ())] { # and change them to var allTests : [(String, () -> Void)] { # find all lines with let content = try String(contentsOfFile: "./Tests/TestCases/\(path).json", encoding: NSUTF8StringEncoding) # and change them to block code as below if let content = try? NSString(contentsOfFile: "./TidyJSON/Tests/TestCases/\(path).json", encoding: NSUTF8StringEncoding).bridge() { // no change here if let _ = try? JSON.parse(content) { ... //(no change here) } else { ... //(no change here) } } #create this Makefile cat <<'EOF' > Makefile APP=tidyjsonTest PROJECT_PREFIX=$(PWD) MODULENAME=TidyJSON OBJ_DIR=obj DEP_LIB_SRC_FOLDER1 = TidyJSON/Sources SWIFT_FILES = $(wildcard $(PROJECT_PREFIX)/$(DEP_LIB_SRC_FOLDER1)/*.swift) OBJ_FILES=$(addprefix, ./obj/, $(notdir $(SWIFT_FILES:.swift=.o))) testfile= $(PROJECT_PREFIX)/TidyJSON/Tests/Test.swift mainfile=$(PROJECT_PREFIX)/TidyJSON/Tests/main.swift all: $(APP) $(APP): $(testfile) $(mainfile) lib$(MODULENAME).a $(MODULENAME).swiftmodule ; \ swiftc -emit-executable $(testfile) $(mainfile) -o $(APP) -I. -L. -Xlinker lib$(MODULENAME).a ; lib$(MODULENAME).a: $(SWIFT_FILES) ; \ $(shell mkdir -p $(OBJ_DIR); cd $(OBJ_DIR); swiftc -parse-as-library -module-name $(MODULENAME) -emit-object $(SWIFT_FILES)) \ rm -f lib$(MODULENAME).* ; \ ar -rcs lib$(MODULENAME).a $(OBJ_DIR)/*.o ; $(MODULENAME).swiftmodule: $(SWIFT_FILES) ; \ rm -f $(MODULENAME).swiftmodule $(MODULENAME).swiftdoc ; \ swiftc -emit-module -module-name $(MODULENAME) -c $(SWIFT_FILES) -emit-module-path $(MODULENAME).swiftmodule -module-link-name $(MODULENAME) ; clean: ; rm -rf obj $(MODULENAME).swift* lib$(MODULENAME).* $(APP) .PHONY: all clean EOF # make then run to test make ./tidyjsonTest

To install docker, see this http://blog.hypriot.com/post/run-docker-rpi3-with-wifi/
The latest Kali Linux image for pentesting is here https://www.offensive-security.com/kali-linux-arm-images/

Swift 3.0 is out for Ubuntu 16 (Xenial Xerus)
see Raspberry Pi image for Ubuntu 16 here https://wiki.ubuntu.com/ARM/RaspberryPi

installation shell script    Select all
cd $HOME wget http://swift-arm.ddns.net/job/Swift-3.0-Pi3-ARM-Incremental/lastSuccessfulBuild/artifact/swift-3.0.tgz mkdir $HOME/swift-3.0 cd $HOME/swift-3.0 && tar -xzf ../swift-3.0.tgz export PATH=$HOME/swift-3.0/usr/bin:$PATH sudo apt-get update sudo apt-get install -y libicu-dev clang-3.6 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 mkdir $HOME/hello; cd $HOME/hello swift package init --type executable swift build .build/debug/hello

No comments: