Skip to content

Commit 56ca92e

Browse files
author
Justin Boswell
authored
FreeBSD support and config compilation (#15)
* Added support for FreeBSD * Added darwin -> macos aliases * Fleshed out arch/os aliases, normalize targets always * Added aliases for FreeBSD/OSX uname -m arch * Try harder to divine branch when github lies to us * Always normalize toolchain platform * Install docker in ubuntu image for cross compile * Make sanity tests check for platform normalization via armv8 * Make sure compiler installation happens at package installation time * Fixed where path shenanigans * Finally got the courage to just recursively process config trees * Resolve symlinks when looking up executables
1 parent 2490477 commit 56ca92e

File tree

13 files changed

+209
-97
lines changed

13 files changed

+209
-97
lines changed

.github/actions/release-tag/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ try {
66
const parts = github_ref.split('/');
77
const branch = parts[parts.length - 1];
88
var release_tag = branch;
9-
if (branch == 'master') {
9+
// GITHUB_REF can be refs/pull/<pr#>/merge for PR openings
10+
if (branch == 'master' || branch == 'merge') {
1011
const spawnSync = require('child_process').spawnSync;
1112
const result = spawnSync('git', ['describe', '--abbrev=0'], {
1213
timeout: 2000

.github/docker-images/ubuntu-16-x64/Dockerfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,15 @@ RUN apt-get update -qq \
2020
apt-transport-https \
2121
&& apt-get clean
2222

23+
##############################################################################
24+
# Docker (for cross compiling via dockcross)
25+
###############################################################################
26+
WORKDIR /tmp
27+
RUN set -ex && curl -fsSL https://get.docker.com -o /tmp/get-docker.sh \
28+
&& sh /tmp/get-docker.sh \
29+
&& systemctl enable docker \
30+
&& echo "service docker start" >> ~/.bashrc
31+
2332
###############################################################################
2433
# Python/AWS CLI
2534
###############################################################################

.github/workflows/docker-images.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ on:
66
- '*'
77
- '!master'
88
paths:
9+
- '.github/actions/release-tag/*'
910
- '.github/docker-images/**/*'
1011
- '.github/docker-images/entrypoint.sh'
1112
- '.github/workflows/docker-images.yml'

.github/workflows/sanity-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ jobs:
144144
needs: package
145145
strategy:
146146
matrix:
147-
arch: [linux-armv6, linux-armv7, linux-arm64]
147+
arch: [linux-armv6, linux-armv7, linux-armv8]
148148

149149
steps:
150150
- name: Checkout Source

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,17 @@ Usage: ```builder.pyz [build|inspect|<action-name>] [spec] [OPTIONS]```
2525
* ```--config CONFIG``` - CMake config to use (Debug, Release, RelWithDebInfo, DebugOpt) Default is RelWithDebInfo
2626
* ```--compiler COMPILER[-VERSION]``` - Use the specified compiler, installing it if necessary
2727
* ```--platform PLATFORM``` - Platform to cross-compile for (via dockcross, requires docker to be installed)
28+
* Valid values are anything that you could get from `uname`.lower() - `uname -m`, e.g. linux-x86_64, linux-x64. See targets below.
2829
* ```--build-dir DIR``` - Make a new directory to do all the build work in, instead of using the current directory
2930
* ```--dump-config``` - Dumps the resultant config after merging all available options. Useful for debugging your project configuration.
3031

32+
33+
### Supported Targets:
34+
* linux: x86|i686, x64|x86_64, armv6, armv7, arm64|armv8|aarch64|arm64v8
35+
* macos|darwin: x64|x86_64
36+
* windows: x86, x64
37+
* freebsd: x64
38+
3139
### Example build
3240
```builder.pyz build --project=aws-c-common downstream```
3341

builder/__main__.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
from project import Project
2929
from scripts import Scripts
3030
from toolchain import Toolchain
31-
from host import current_os, current_host, current_arch, current_platform
31+
from host import current_os, current_host, current_arch, current_platform, normalize_target
3232
import data
3333

3434
import api # force API to load and expose the virtual module
@@ -113,7 +113,7 @@ def inspect_host(env):
113113
toolchain = Toolchain(spec=spec)
114114
print('Host Environment:')
115115
print(' Host: {} {}'.format(spec.host, spec.arch))
116-
print(' Default Target: {} {}'.format(spec.target, spec.arch))
116+
print(' Target: {} {}'.format(spec.target, spec.arch))
117117
compiler_path = toolchain.compiler_path()
118118
if not compiler_path:
119119
compiler_path = '(Will Install)'
@@ -183,11 +183,15 @@ def parse_args():
183183
args.command = args.spec
184184
args.spec = None
185185

186+
# normalize target
187+
if args.target:
188+
args.target = normalize_target(args.target)
189+
186190
if args.spec:
187191
spec = BuildSpec(spec=args.spec, target=args.target)
188192

189193
if args.compiler or args.target:
190-
compiler, version = (None, None)
194+
compiler, version = ('default', 'default')
191195
if args.compiler:
192196
compiler, version = args.compiler.split('-')
193197
spec = str(spec) if spec else None

builder/actions/install.py

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from host import current_os, package_tool
2323
from actions.script import Script
2424
from toolchain import Toolchain
25+
from util import list_unique
2526

2627

2728
class InstallPackages(Action):
@@ -39,6 +40,7 @@ def run(self, env):
3940
if not packages:
4041
return
4142

43+
packages = list_unique(packages)
4244
pkg_tool = package_tool()
4345
print('Installing packages via {}: {}'.format(
4446
pkg_tool.value, ', '.join(packages)))
@@ -58,7 +60,7 @@ def run(self, env):
5860
if not InstallPackages.pkg_init_done:
5961
pkg_setup = config.get('pkg_setup', [])
6062
if pkg_setup:
61-
for cmd in pkg_setup:
63+
for cmd in list_unique(pkg_setup):
6264
if isinstance(cmd, str):
6365
cmd = cmd.split(' ')
6466
assert isinstance(cmd, list)
@@ -95,16 +97,21 @@ def run(self, env):
9597
assert toolchain
9698

9799
# Cross compile with dockcross
98-
if toolchain.cross_compile:
100+
def _install_cross_compile_toolchain(env):
99101
print(
100102
'Installing cross-compile via dockcross for {}'.format(toolchain.platform))
103+
cross_compile_platform = env.config.get(
104+
'cross_compile_platform', toolchain.platform)
101105
result = sh.exec(
102-
'docker', 'run', 'dockcross/{}'.format(toolchain.platform), quiet=True)
103-
assert result.returncode == 0
106+
'docker', 'run', 'dockcross/{}'.format(cross_compile_platform), quiet=True)
104107
# Strip off any output from docker itself
105-
script = '#!' + result.output.partition('#!')[2]
108+
output, shebang, script = result.output.partition('#!')
109+
script = shebang + script
110+
print(output)
111+
assert result.returncode == 0
112+
106113
dockcross = os.path.abspath(os.path.join(
107-
env.build_dir, 'dockcross-{}'.format(toolchain.platform)))
114+
env.build_dir, 'dockcross-{}'.format(cross_compile_platform)))
108115
Path(dockcross).touch(0o755)
109116
with open(dockcross, "w+t") as f:
110117
f.write(script)
@@ -118,22 +125,8 @@ def run(self, env):
118125
toolchain.env_file = dockcross_env
119126
toolchain.shell_env = [
120127
dockcross, '-a', '--env-file={}'.format(dockcross_env)]
121-
return
122-
123-
# Compiler is local, or should be, so verify/install and export it
124-
compiler = env.spec.compiler
125-
version = env.spec.compiler_version
126-
if version == 'default':
127-
version = None
128-
129-
# See if the compiler is already installed
130-
compiler_path, found_version = Toolchain.find_compiler(
131-
compiler, version)
132-
if compiler_path:
133-
print('Compiler {} {} is already installed ({})'.format(
134-
compiler, version, compiler_path))
135-
return
136128

129+
# Expose compiler via environment
137130
def _export_compiler(_env):
138131
if current_os() == 'windows':
139132
return
@@ -149,5 +142,23 @@ def _export_compiler(_env):
149142
print(
150143
'WARNING: Compiler {} could not be found'.format(exe))
151144

152-
packages = config['compiler_packages']
153-
return Script([InstallPackages(packages), _export_compiler])
145+
if not toolchain.cross_compile:
146+
# Compiler is local, or should be, so verify/install and export it
147+
compiler = env.spec.compiler
148+
version = env.spec.compiler_version
149+
if version == 'default':
150+
version = None
151+
152+
# See if the compiler is already installed
153+
compiler_path, found_version = Toolchain.find_compiler(
154+
compiler, version)
155+
if compiler_path:
156+
print('Compiler {} {} is already installed ({})'.format(
157+
compiler, version, compiler_path))
158+
return
159+
160+
packages = list_unique(config.get('compiler_packages', []))
161+
after_packages = [_export_compiler]
162+
if toolchain.cross_compile:
163+
after_packages = [_install_cross_compile_toolchain]
164+
return Script([InstallPackages(packages), *after_packages])

0 commit comments

Comments
 (0)