Skip to content
This repository was archived by the owner on Jan 7, 2022. It is now read-only.

Commit c0b6207

Browse files
Fixes for travic CI build (#3)
Summary: This should fix the Travis CI builds. It adds rust toolchain support inside docker and sets the required THRIFT env variable. Pull Request resolved: facebookexperimental/rust-shed#3 Reviewed By: krallin Differential Revision: D18905608 Pulled By: lukaspiatkowski fbshipit-source-id: 5db1eff6f215a6617d8acaa0c99a62d45225956b
1 parent 794d484 commit c0b6207

File tree

5 files changed

+158
-13
lines changed

5 files changed

+158
-13
lines changed

build/fbcode_builder/docker_builder.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,20 @@ def setup(self):
4242
# To allow exercising non-root installs -- we change users after the
4343
# system packages are installed. TODO: For users not defined in the
4444
# image, we should probably `useradd`.
45-
return self.step('Setup', [
46-
# Docker's FROM does not understand shell quoting.
47-
ShellQuoted('FROM {}'.format(self.option('os_image'))),
48-
# /bin/sh syntax is a pain
49-
ShellQuoted('SHELL ["/bin/bash", "-c"]'),
50-
]
51-
+ self.install_debian_deps() + [self._change_user()]
52-
+ [self.workdir(self.option('prefix'))]
45+
return self.step(
46+
"Setup",
47+
[
48+
# Docker's FROM does not understand shell quoting.
49+
ShellQuoted("FROM {}".format(self.option("os_image"))),
50+
# /bin/sh syntax is a pain
51+
ShellQuoted('SHELL ["/bin/bash", "-c"]'),
52+
]
53+
+ self.install_debian_deps()
54+
+ [self._change_user()]
55+
+ [self.workdir(self.option("prefix"))]
5356
+ self.create_python_venv()
5457
+ self.python_venv()
58+
+ self.rust_toolchain(),
5559
)
5660

5761
def python_venv(self):
@@ -71,6 +75,9 @@ def step(self, name, actions):
7175
def run(self, shell_cmd):
7276
return ShellQuoted('RUN {cmd}').format(cmd=shell_cmd)
7377

78+
def set_env(self, key, value):
79+
return ShellQuoted("ENV {key}={val}").format(key=key, val=value)
80+
7481
def workdir(self, dir):
7582
return [
7683
# As late as Docker 1.12.5, this results in `build` being owned

build/fbcode_builder/facebook_legocastle_builder.py

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ def __init__(self, message):
4444

4545
LegocastleFBCheckout = namedtuple('LegocastleFBCheckout', ['project_and_path'])
4646
LegocastleWorkdir = namedtuple('LegocastleWorkdir', ['dir'])
47+
LegocastleSetEnv = namedtuple("LegocastleSetEnv", ["key", "value"])
4748

4849

4950
class LegocastleStep(namedtuple('LegocastleStepBase', ('name', 'actions'))):
@@ -60,9 +61,13 @@ def __new__(cls, name, actions):
6061
class LegocastleFBCodeBuilder(FBCodeBuilder):
6162

6263
def setup(self):
63-
return self.step('Setup',
64-
self.create_python_venv() + [
65-
self.run(ShellQuoted("""
64+
return self.step(
65+
"Setup",
66+
self.create_python_venv()
67+
+ [
68+
self.run(
69+
ShellQuoted(
70+
"""
6671
case "$OSTYPE" in
6772
darwin*)
6873
http_proxy= https_proxy= ./tools/lfs/lfs.py \\
@@ -72,17 +77,44 @@ def setup(self):
7277
tar xzf homebrew.tar.gz -C /var/tmp
7378
;;
7479
esac
75-
"""))])
80+
"""
81+
)
82+
)
83+
]
84+
+ self.rust_toolchain(),
85+
)
7686

7787
def step(self, name, actions):
7888
return LegocastleStep(name=name, actions=actions)
7989

8090
def run(self, shell_cmd):
8191
return shell_cmd
8292

93+
def set_env(self, key, value):
94+
return LegocastleSetEnv(key, value)
95+
8396
def workdir(self, dir):
8497
return LegocastleWorkdir(dir)
8598

99+
def rust_toolchain(self):
100+
actions = []
101+
if self.option("rust_toolchain", False):
102+
(toolchain, is_bootstrap) = self.option("rust_toolchain")
103+
assert toolchain == "stable", (
104+
"Only stable toolchain is supported in legocastle,"
105+
+ " but {0} provided"
106+
).format(toolchain)
107+
actions = [
108+
self.set_env(
109+
"PATH", ShellQuoted("$BOX_DIR/xplat/rust/toolchain/current:$PATH")
110+
),
111+
self.set_env("RUSTC_BOOTSTRAP", "1" if is_bootstrap else "0"),
112+
self.run(ShellQuoted("rustc --version")),
113+
self.run(ShellQuoted("rustdoc --version")),
114+
self.run(ShellQuoted("cargo --version")),
115+
]
116+
return actions
117+
86118
def fb_github_project_workdir(self, project_and_path, github_org='facebook'):
87119
return LegocastleFBCheckout(project_and_path)
88120

@@ -106,6 +138,7 @@ def _render_impl(self, actions):
106138
#
107139
# If we just replayed the last workdir('baz'), we would not end up
108140
# in '<github_prefix>/foo/bar/baz', but rather in `<unknown>/baz`.
141+
next_set_env = []
109142
next_step_workdirs = []
110143
shipit_projects = []
111144
build_steps = []
@@ -124,6 +157,8 @@ def _render_impl(self, actions):
124157
shipit_projects.append(
125158
action.project_and_path.split('/', 1)[0]
126159
)
160+
elif isinstance(action, LegocastleSetEnv):
161+
next_set_env.append(action)
127162
elif isinstance(action, LegocastleStep):
128163
pre_actions = [
129164
ShellQuoted('set -ex')
@@ -157,7 +192,10 @@ def _render_impl(self, actions):
157192
)
158193
pre_actions.extend(self.workdir(w) for w in next_step_workdirs)
159194

160-
shell_steps = []
195+
shell_steps = [
196+
ShellQuoted("export {k}={v}").format(k=a.key, v=a.value)
197+
for a in next_set_env
198+
]
161199
for a in itertools.chain(pre_actions, action.actions):
162200
if isinstance(a, LegocastleWorkdir):
163201
next_step_workdirs.append(a.dir)
@@ -167,6 +205,11 @@ def _render_impl(self, actions):
167205
'_wd={d} ; mkdir -p "$_wd" && cd "$_wd"'
168206
).format(d=a.dir)
169207
)
208+
elif isinstance(a, LegocastleSetEnv):
209+
next_set_env.append(a)
210+
shell_steps.append(
211+
ShellQuoted("export {k}={v}").format(k=a.key, v=a.value)
212+
)
170213
else:
171214
shell_steps.append(a)
172215

build/fbcode_builder/fbcode_builder.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,10 @@ def run(self, shell_cmd):
172172
'Run this bash command'
173173
raise NotImplementedError
174174

175+
def set_env(self, key, value):
176+
'Set the environment "key" to value "value"'
177+
raise NotImplementedError
178+
175179
def workdir(self, dir):
176180
'Create this directory if it does not exist, and change into it'
177181
raise NotImplementedError
@@ -276,6 +280,52 @@ def python_venv(self):
276280
self.python_deps())))))
277281
return(actions)
278282

283+
def enable_rust_toolchain(self, toolchain="stable", is_bootstrap=True):
284+
choices = set(["stable", "beta", "nightly"])
285+
286+
assert toolchain in choices, (
287+
"while enabling rust toolchain: {} is not in {}"
288+
).format(toolchain, choices)
289+
290+
rust_toolchain_opt = (toolchain, is_bootstrap)
291+
prev_opt = self.option("rust_toolchain", rust_toolchain_opt)
292+
assert prev_opt == rust_toolchain_opt, (
293+
"while enabling rust toolchain: previous toolchain already set to"
294+
" {}, but trying to set it to {} now"
295+
).format(prev_opt, rust_toolchain_opt)
296+
297+
self.add_option("rust_toolchain", rust_toolchain_opt)
298+
299+
def rust_toolchain(self):
300+
actions = []
301+
if self.option("rust_toolchain", False):
302+
(toolchain, is_bootstrap) = self.option("rust_toolchain")
303+
rust_dir = path_join(self.option("prefix"), "rust")
304+
actions = [
305+
self.set_env("CARGO_HOME", rust_dir),
306+
self.set_env("RUSTUP_HOME", rust_dir),
307+
self.set_env("RUSTC_BOOTSTRAP", "1" if is_bootstrap else "0"),
308+
self.run(
309+
ShellQuoted(
310+
"curl -sSf https://build.travis-ci.com/files/rustup-init.sh"
311+
" | sh -s --"
312+
" --default-toolchain={r} "
313+
" --profile=minimal"
314+
" --no-modify-path"
315+
" -y"
316+
).format(p=rust_dir, r=toolchain)
317+
),
318+
self.set_env(
319+
"PATH",
320+
ShellQuoted("{p}:$PATH").format(p=path_join(rust_dir, "bin")),
321+
),
322+
self.run(ShellQuoted("rustup update")),
323+
self.run(ShellQuoted("rustc --version")),
324+
self.run(ShellQuoted("rustup --version")),
325+
self.run(ShellQuoted("cargo --version")),
326+
]
327+
return actions
328+
279329
def debian_ccache_setup_steps(self):
280330
return [] # It's ok to ship a renderer without ccache support.
281331

@@ -388,6 +438,18 @@ def cmake_install(self, name, cmake_path='..'):
388438
self.cmake_configure(name, cmake_path) + self.make_and_install()
389439
)
390440

441+
def cargo_build(self, name):
442+
return self.step(
443+
"Build {0}".format(name),
444+
[
445+
self.run(
446+
ShellQuoted("cargo build -j {n}").format(
447+
n=self.option("make_parallelism")
448+
)
449+
)
450+
],
451+
)
452+
391453
def fb_github_autoconf_install(self, project_and_path, github_org='facebook'):
392454
return [
393455
self.fb_github_project_workdir(project_and_path, github_org),
@@ -399,3 +461,9 @@ def fb_github_cmake_install(self, project_and_path, cmake_path='..', github_org=
399461
self.fb_github_project_workdir(project_and_path, github_org),
400462
self.cmake_install(project_and_path, cmake_path),
401463
]
464+
465+
def fb_github_cargo_build(self, project_and_path, github_org="facebook"):
466+
return [
467+
self.fb_github_project_workdir(project_and_path, github_org),
468+
self.cargo_build(project_and_path),
469+
]

build/fbcode_builder/shell_builder.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ class ShellFBCodeBuilder(FBCodeBuilder):
3333
def _render_impl(self, steps):
3434
return raw_shell(shell_join('\n', recursively_flatten_list(steps)))
3535

36+
def set_env(self, key, value):
37+
return ShellQuoted("export {key}={val}").format(key=key, val=value)
38+
3639
def workdir(self, dir):
3740
return [
3841
ShellQuoted('mkdir -p {d} && cd {d}').format(
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env python
2+
# Copyright (c) Facebook, Inc. and its affiliates.
3+
from __future__ import absolute_import
4+
from __future__ import division
5+
from __future__ import print_function
6+
from __future__ import unicode_literals
7+
8+
from shell_quoting import path_join
9+
import specs.fbthrift as fbthrift
10+
11+
12+
def fbcode_builder_spec(builder):
13+
builder.enable_rust_toolchain()
14+
return {
15+
"depends_on": [fbthrift],
16+
"steps": [
17+
builder.set_env(
18+
"THRIFT", path_join(builder.option("prefix"), "bin", "thrift1")
19+
),
20+
builder.fb_github_cargo_build(
21+
"rust-shed/", github_org="facebookexperimental"
22+
),
23+
],
24+
}

0 commit comments

Comments
 (0)