Skip to content

Commit fbf4ad3

Browse files
lukaspiatkowskisimpkins
authored andcommitted
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 e80f5a5 commit fbf4ad3

File tree

4 files changed

+110
-8
lines changed

4 files changed

+110
-8
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/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)