Skip to content

Commit 96928cc

Browse files
committed
Merge pull request swift-arm#3 from pj4533/swift-3.0
Beginning of support for crosscompiling scripting
2 parents 930cb53 + 9f83ec4 commit 96928cc

File tree

15 files changed

+229
-0
lines changed

15 files changed

+229
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@ swift.tar.gz
1313
compiler-rt
1414
swift-corelibs-libdispatch
1515
swift-integration-tests
16+
cache
17+
.DS_Store
18+
sysroot

crosscompile_build.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/bin/bash
2+
#
3+
# Cross Compile Script
4+
# https://swift-arm.slack.com/files/kawa/F17GA65L4/cross-compiling.txt
5+
#
6+
7+
# target
8+
TARGET="linux-armv6"
9+
10+
while getopts ":t:" opt; do
11+
case $opt in
12+
t) TARGET="$OPTARG"
13+
;;
14+
\?) echo "Invalid option -$OPTARG" >&2
15+
;;
16+
esac
17+
done
18+
19+
WORKSPACE="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
20+
INSTALL_DIR=${WORKSPACE}/install
21+
SYSROOT=${WORKSPACE}/crosscompile_support/sysroot
22+
TOOLCHAIN=${WORKSPACE}/crosscompile_support/toolchain/bin
23+
./swift/utils/build-script -R \
24+
--installable-package="${INSTALL_DIR}/swift-3.0" \
25+
--install-destdir="${INSTALL_DIR}/output" \
26+
--install-symroot="${INSTALL_DIR}/debug-output" \
27+
-- \
28+
--llvm-install-components="clang;clang-headers;libclang;libclang-headers" \
29+
--swift-install-components="compiler;stdlib;sdk-overlay;clang-builtin-headers;editor-integration;sourcekit-xpc-service" \
30+
--darwin-toolchain-name="swift-3.0" \
31+
--darwin_toolchain_display_name="local.swift.3" \
32+
--darwin_toolchain_bundle_identifier="local.swift.3" \
33+
--toolchain_prefix="swift3.xctoolchain" \
34+
--darwin_toolchain_alias="local" \
35+
--install-swift \
36+
--install-prefix="/usr" \
37+
--cross-compile-hosts="${TARGET}" \
38+
--cross-compile-sysroot="${SYSROOT}" \
39+
--cross-compile-toolchain-bin="${TOOLCHAIN}" \
40+
--reconfigure
41+

crosscompile_get.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/bash
2+
3+
4+
# distro can be: debian, raspbian or ubuntu
5+
DISTRO="raspbian"
6+
7+
# version of distro
8+
VERSION="jessie"
9+
10+
# arch to build for
11+
ARCH="armhf"
12+
13+
while getopts ":d:v:a:" opt; do
14+
case $opt in
15+
d) DISTRO="$OPTARG"
16+
;;
17+
v) VERSION="$OPTARG"
18+
;;
19+
a) ARCH="$OPTARG"
20+
;;
21+
\?) echo "Invalid option -$OPTARG" >&2
22+
;;
23+
esac
24+
done
25+
26+
#fetch the proper sysroot using script from karwa
27+
echo "Fetching sysroot: sysroot.$ARCH.$DISTRO.$VERSION"
28+
./crosscompile_support/make_sysroot.py --distro $DISTRO --version $VERSION --arch $ARCH --install ./crosscompile_support/sysroot
29+
30+
# cross compiling requires changes from Karwa & armv6 changes from pj4533
31+
git clone https://github.com/pj4533/swift.git swift
32+
33+
./swift/utils/update-checkout --clone
34+
35+
#compiler-rt caused issues
36+
rm -rf compiler-rt
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
#!/usr/bin/env python
2+
3+
import argparse
4+
import sys
5+
import gzip
6+
import urllib
7+
import urlparse
8+
import posixpath
9+
import cStringIO
10+
import os
11+
import subprocess
12+
13+
14+
def get_packages_list(args):
15+
filename = "Packages.gz"
16+
filepath = cachedir + "/" + filename
17+
if not os.path.isfile(filepath):
18+
url = mirror + \
19+
"/dists/%s/main/binary-%s/%s" % (args.version, args.arch, filename)
20+
print "Retrieving:", url
21+
urllib.urlretrieve(url, filepath)
22+
io = gzip.open(filepath, 'r')
23+
24+
packages = dict()
25+
curPackage = None
26+
i = 0
27+
28+
print "Processing:", filepath
29+
for line in io.readlines():
30+
if len(line) == 1 and line[0] == '\n':
31+
curPackage = None
32+
continue
33+
34+
try:
35+
key, value = line.rstrip().split(": ", 1)
36+
except:
37+
continue
38+
if curPackage is None:
39+
assert key == "Package"
40+
curPackage = dict()
41+
packages[value] = curPackage
42+
else:
43+
curPackage[key] = value
44+
io.close()
45+
46+
return packages
47+
48+
49+
def urlAndNameFromPackage(p):
50+
url = mirror + "/" + p['Filename']
51+
name = posixpath.basename(urlparse.urlparse(url).path)
52+
return (url, name)
53+
54+
55+
parser = argparse.ArgumentParser(prog='make_sysroot',
56+
description="""Create a sysroot to use when cross-compiling things.
57+
e.g. to make an Ubuntu 14.04 armhf sysroot run:
58+
make_sysroot.py --distro ubuntu --version trusty --arch armhf --install <destination sysroot>
59+
e.g. to make a Debian Jessie armel sysroot run:
60+
make_sysroot.py --distro debian --version jessie --arch armel --install <destination sysroot>"""
61+
)
62+
parser.add_argument('--distro', required=True, help='Distribution')
63+
parser.add_argument('--version', required=True, help='Version')
64+
parser.add_argument('--arch', required=True, help='Architecture')
65+
parser.add_argument('--install', help='Install dir')
66+
67+
68+
args = parser.parse_args(sys.argv[1:])
69+
70+
71+
required_packages = [
72+
'libc6',
73+
'libc6-dev',
74+
'linux-libc-dev',
75+
'libicu52',
76+
'libicu-dev',
77+
'libbsd0',
78+
'libbsd-dev',
79+
'libgcc-4.8-dev',
80+
'libstdc++-4.8-dev',
81+
'libstdc++6',
82+
'libstdc++-4.8-dev',
83+
'libatomic1',
84+
'libgcc1',
85+
'libxml2',
86+
'libxml2-dev',
87+
'libuuid1',
88+
'uuid-dev',
89+
'libncurses5',
90+
'libncurses5-dev',
91+
'libtinfo5',
92+
'libtinfo-dev',
93+
'zlib1g',
94+
'zlib1g-dev',
95+
'libedit2',
96+
'libedit-dev',
97+
'python-dev', # for LLDB
98+
'libsqlite3-0', # for LLBuild
99+
'libsqlite3-dev' # for LLBuild
100+
]
101+
102+
mirror = ""
103+
if args.distro == "ubuntu":
104+
mirror = "http://ports.ubuntu.com/ubuntu-ports"
105+
elif args.distro == "debian":
106+
mirror = "http://ftp.debian.org/debian"
107+
elif args.distro == "raspbian":
108+
mirror = "http://archive.raspbian.com/raspbian"
109+
else:
110+
sys.exit(1)
111+
112+
cachedir = "cache/%s/%s" % (args.distro, args.version)
113+
if not os.path.exists(cachedir):
114+
os.makedirs(cachedir)
115+
116+
all_packages = get_packages_list(args)
117+
118+
deps = []
119+
120+
for name in required_packages:
121+
p = all_packages[name]
122+
url, filename = urlAndNameFromPackage(p)
123+
if p.has_key("Depends"):
124+
for d in p['Depends'].split(', '):
125+
deps.append(d)
126+
filepath = cachedir + "/" + filename
127+
if not os.path.isfile(filepath):
128+
print "Retrieving:", url
129+
urllib.urlretrieve(url, filepath)
130+
131+
if args.install:
132+
print "Installing:", filepath
133+
ret = subprocess.call(['dpkg-deb', '-x', filepath, args.install])
134+
assert ret == 0
135+
136+
137+
# Fixup broken symlinks
138+
if args.install:
139+
for dirname, dirnames, filenames in os.walk(args.install):
140+
for filename in filenames:
141+
path = os.path.join(dirname, filename)
142+
if os.path.islink(path):
143+
link = os.readlink(path)
144+
if link[0] == os.path.sep:
145+
fulllink = os.path.normpath(
146+
os.path.join(args.install, "." + link))
147+
fixed = os.path.relpath(fulllink, dirname)
148+
os.unlink(path)
149+
os.symlink(fixed, path)
895 KB
Binary file not shown.
1.47 MB
Binary file not shown.
1.33 MB
Binary file not shown.
1.33 MB
Binary file not shown.
6.63 MB
Binary file not shown.
875 KB
Binary file not shown.

0 commit comments

Comments
 (0)