Skip to content

Commit 77833a4

Browse files
committed
Merge branch 'support-fips-branch' of github.com:awslabs/aws-crt-builder into support-fips-branch
2 parents 7ee3dc3 + a3b0f57 commit 77833a4

File tree

8 files changed

+120
-8
lines changed

8 files changed

+120
-8
lines changed

.github/docker-images/alpine-3.16-arm64/Dockerfile

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ RUN apk add \
1818
ca-certificates \
1919
cmake \
2020
bash \
21-
aws-cli
21+
aws-cli \
22+
perl-strictures
2223

2324
WORKDIR /tmp
2425

.github/docker-images/alpine-3.16-x64/Dockerfile

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ RUN apk add \
1818
ca-certificates \
1919
cmake \
2020
bash \
21-
aws-cli
21+
aws-cli \
22+
perl-strictures
2223

2324
WORKDIR /tmp
2425

.github/docker-images/openwrt-x64-openjdk8/Dockerfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ RUN mkdir -p /usr/local/bin
77
RUN opkg update
88

99
# packages in openwrt
10-
RUN opkg install git-http ca-bundle curl python3 python3-pip gcc make bash sudo
10+
RUN opkg install git-http ca-bundle curl python3 python3-pip gcc make bash sudo perl
1111

1212
# packages we have to get from alpine
1313

@@ -27,7 +27,7 @@ RUN tar -xzf apk-tools-static-2.12.9-r3.apk
2727
RUN ./sbin/apk.static -X http://dl-cdn.alpinelinux.org/alpine/v3.16/main -X http://dl-cdn.alpinelinux.org/alpine/v3.16/community -U --allow-untrusted --initdb add cmake openjdk8 maven aws-cli
2828

2929
# stub libraries for stuff we unconditionally link; functionality is all actually in musl already
30-
# long term we might want to make our recognition better, but this is a blocker for the s2n build
30+
# long term we might want to make our recognition better, but this is a blocker for the s2n build
3131
RUN ar -rc /usr/lib/libpthread.a
3232
RUN ar -rc /usr/lib/libdl.a
3333
RUN ar -rc /usr/lib/librt.a

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

+6
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ RUN apt-get update -qq \
2424
ca-certificates \
2525
&& apt-get clean
2626

27+
# Add the longsleep/golang-backports PPA
28+
RUN apt-get update && apt-get install -y software-properties-common && add-apt-repository ppa:longsleep/golang-backports && apt-get update
29+
30+
# Install Go from the PPA
31+
RUN apt-get install -y golang-go
32+
2733
###############################################################################
2834
# Python/AWS CLI
2935
###############################################################################

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

+6
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ RUN apt-get update -qq \
2020
ca-certificates \
2121
&& apt-get clean
2222

23+
# Add the longsleep/golang-backports PPA
24+
RUN apt-get update && apt-get install -y software-properties-common && add-apt-repository ppa:longsleep/golang-backports && apt-get update
25+
26+
# Install Go from the PPA
27+
RUN apt-get install -y golang-go
28+
2329
###############################################################################
2430
# Python/AWS CLI
2531
###############################################################################

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

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ RUN apt-get update -qq \
1818
software-properties-common \
1919
apt-transport-https \
2020
ca-certificates \
21+
golang-go \
2122
&& apt-get clean
2223

2324
###############################################################################

builder/actions/cmake.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,12 @@ def _project_dirs(env, project):
103103
def _build_project(env, project, cmake_extra, build_tests=False, args_transformer=None, coverage=False):
104104
sh = env.shell
105105
config = project.get_config(env.spec)
106+
build_env = []
106107
toolchain = env.toolchain
108+
if toolchain.cross_compile and 'go_path' in env.variables:
109+
# We need to set the envrionment variable of GO_PATH for cross compile
110+
build_env = ["GO_PATH={}\n".format(env.variables['go_path'])]
111+
107112
# build dependencies first, let cmake decide what needs doing
108113
for dep in project.get_dependencies(env.spec):
109114
_build_project(env, dep, cmake_extra)
@@ -178,13 +183,11 @@ def _build_project(env, project, cmake_extra, build_tests=False, args_transforme
178183
cmake_args = args_transformer(env, project, cmake_args)
179184

180185
# When cross compiling, we must inject the build_env into the cross compile container
181-
build_env = []
182186
if toolchain.cross_compile:
183-
build_env = ['{}={}\n'.format(key, val)
184-
for key, val in config.get('build_env', {}).items()]
187+
build_env = build_env + ['{}={}\n'.format(key, val)
188+
for key, val in config.get('build_env', {}).items()]
185189
with open(toolchain.env_file, 'a') as f:
186190
f.writelines(build_env)
187-
188191
# set parallism via env var (cmake's --parallel CLI option doesn't exist until 3.12)
189192
if os.environ.get('CMAKE_BUILD_PARALLEL_LEVEL') is None:
190193
sh.setenv('CMAKE_BUILD_PARALLEL_LEVEL', str(os.cpu_count()))

builder/imports/golang.py

+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
# SPDX-License-Identifier: Apache-2.0.
3+
4+
import os
5+
from pathlib import Path
6+
7+
from builder.core.fetch import fetch_and_extract, mirror_package
8+
from builder.core.project import Import
9+
import builder.core.util as util
10+
from builder.core.host import current_platform
11+
12+
URLs = {
13+
'linux-armv6': 'https://go.dev/dl/go1.21.5.linux-armv6l.tar.gz',
14+
'linux-armv7': 'https://go.dev/dl/go1.21.5.linux-armv6l.tar.gz',
15+
'linux-armv8': 'https://go.dev/dl/go1.21.5.linux-arm64.tar.gz',
16+
'linux-x86': 'https://go.dev/dl/go1.21.5.linux-386.tar.gz',
17+
'linux-x64': 'https://go.dev/dl/go1.21.5.linux-amd64.tar.gz',
18+
'openbsd-x64': 'https://go.dev/dl/go1.21.5.linux-amd64.tar.gz',
19+
'windows-x64': 'https://go.dev/dl/go1.21.5.windows-amd64.zip',
20+
'windows-x86': 'https://go.dev/dl/go1.21.5.windows-386.zip',
21+
'macos-x64': 'https://go.dev/dl/go1.21.5.darwin-amd64.tar.gz',
22+
}
23+
24+
25+
class GOLANG(Import):
26+
def __init__(self, **kwargs):
27+
super().__init__(
28+
config={},
29+
**kwargs)
30+
self.path = None
31+
self.installed = False
32+
33+
def resolved(self):
34+
return True
35+
36+
def install(self, env):
37+
if self.installed:
38+
return
39+
40+
sh = env.shell
41+
42+
target = '{}-{}'.format(env.spec.target, env.spec.arch)
43+
44+
cross_compile = util.deep_get(env, 'toolchain.cross_compile', False)
45+
46+
# If this is a local build, check the local machine
47+
if not cross_compile or target not in URLs:
48+
# run `go version`
49+
result = util.run_command('go', 'version')
50+
if result.returncode == 0:
51+
# check the version, we need version >=1.18
52+
version_str = result.output.split(" ")[2][2:]
53+
version_numbers = list(map(int, version_str.split('.')))
54+
compare_version_numbers = list(map(int, "1.18.0".split('.')))
55+
if version_numbers >= compare_version_numbers:
56+
return
57+
58+
if target not in URLs:
59+
raise EnvironmentError(
60+
'No pre-built binaries for {} are available, please install golang greater than 1.18'.format(target))
61+
62+
install_dir = os.path.join(env.deps_dir, self.name.lower())
63+
# If path is going to be relative, it has to be relative to the source directory
64+
self.path = str(Path(install_dir).relative_to(env.root_dir))
65+
print('Installing pre-built golang binaries for {} to {}'.format(
66+
target, install_dir))
67+
68+
sh.mkdir(install_dir)
69+
if cross_compile:
70+
# If cross compile using the go execuble for current platform instead to codegen
71+
url = URLs[current_platform()]
72+
else:
73+
url = URLs[target]
74+
ext = '.tar.gz' if url.endswith('.tar.gz') else '.zip'
75+
filename = '{}/golang{}'.format(install_dir, ext)
76+
print('Downloading {}'.format(url))
77+
fetch_and_extract(url, filename, install_dir)
78+
os.remove(filename)
79+
80+
# Set PATH
81+
if cross_compile:
82+
# Path to go binary
83+
env.variables['go_path'] = "/work/"+str(Path(os.path.join(install_dir, 'go/bin')
84+
).relative_to(env.root_dir))
85+
else:
86+
# export the PATH directly if not cross compile.
87+
# env.variables['go_path'] = '{}/go/bin'.format(install_dir)
88+
sh.setenv('PATH', '{}{}{}'.format('{}/go/bin'.format(install_dir), os.pathsep, sh.getenv('PATH')))
89+
90+
self.installed = True
91+
92+
def mirror(self, env):
93+
for src_url in URLs.values():
94+
mirror_package(self.name, src_url)

0 commit comments

Comments
 (0)