Skip to content

Commit

Permalink
mononoke: add README.md and the missing pieces for supporting cargo (#13
Browse files Browse the repository at this point in the history
)

Summary:
Take the README.md from
https://github.com/facebookexperimental/mononoke/blob/7ead0e29e41aec0771531a4650b6170bc1ff6566/README.md
and apply it on Eden repo.

Re-add the Cargo.toml file that declares Cargo workspace.

Re-add fbcode_builder/getdeps manifest for Mononoke
Pull Request resolved: facebook/sapling#13

Test Plan:
./build/fbcode_builder/getdeps.py build mononoke
  ./build/fbcode_builder/getdeps.py test mononoke

Reviewed By: ahornby

Differential Revision: D19833059

Pulled By: lukaspiatkowski

fbshipit-source-id: fb37e13306c0b9969a7c4e52b05e1a66a577022f
  • Loading branch information
lukaspiatkowski authored and facebook-github-bot committed Feb 13, 2020
1 parent 7951d10 commit 4c624f3
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 15 deletions.
41 changes: 27 additions & 14 deletions build/fbcode_builder/getdeps/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -813,12 +813,22 @@ def _build(self, install_dirs, reconfigure):

class CargoBuilder(BuilderBase):
def __init__(
self, build_opts, ctx, manifest, src_dir, build_dir, inst_dir, build_doc, loader
self,
build_opts,
ctx,
manifest,
src_dir,
build_dir,
inst_dir,
build_doc,
workspace_dir,
loader,
):
super(CargoBuilder, self).__init__(
build_opts, ctx, manifest, src_dir, build_dir, inst_dir
)
self.build_doc = build_doc
self.ws_dir = workspace_dir
self.loader = loader

def run_cargo(self, install_dirs, operation, args=None):
Expand All @@ -832,11 +842,14 @@ def run_cargo(self, install_dirs, operation, args=None):
"--workspace",
"-j%s" % self.build_opts.num_jobs,
] + args
self._run_cmd(cmd, cwd=self.build_source_dir(), env=env)
self._run_cmd(cmd, cwd=self.workspace_dir(), env=env)

def build_source_dir(self):
return os.path.join(self.build_dir, "source")

def workspace_dir(self):
return os.path.join(self.build_source_dir(), self.ws_dir)

def recreate_dir(self, src, dst):
if os.path.isdir(dst):
shutil.rmtree(dst)
Expand All @@ -862,7 +875,7 @@ def _build(self, install_dirs, reconfigure):
)
)

self._patchup_workspace(build_source_dir)
self._patchup_workspace()

try:
from getdeps.facebook.rust import vendored_crates
Expand All @@ -881,15 +894,14 @@ def run_tests(self, install_dirs, schedule_type, owner):
if self.build_doc:
self.run_cargo(install_dirs, "doc", ["--no-deps"])

def _patchup_workspace(self, build_source_dir):
def _patchup_workspace(self):
"""
This method makes a lot of assumptions about the state of the project
and its cargo dependendies:
1. There is a virtual manifest with workspace in the root of this project
2. Crates from cargo dependencies can be extracted from Cargo.toml files
This method makes some assumptions about the state of the project and
its cargo dependendies:
1. Crates from cargo dependencies can be extracted from Cargo.toml files
using _extract_crates function. It is using a heuristic so check its
code to understand how it is done.
3. The extracted cargo dependencies crates can be found in the
2. The extracted cargo dependencies crates can be found in the
dependency's install dir using _resolve_crate_to_path function
which again is using a heuristic.
Expand All @@ -902,9 +914,10 @@ def _patchup_workspace(self, build_source_dir):
Exception. There migh be more cases where the code will silently pass
producing bad results.
"""
config = self._resolve_config(build_source_dir)
workspace_dir = self.workspace_dir()
config = self._resolve_config()
if config:
with open(os.path.join(build_source_dir, "Cargo.toml"), "a") as f:
with open(os.path.join(workspace_dir, "Cargo.toml"), "a") as f:
# A fake manifest has to be crated to change the virtual
# manifest into a non-virtual. The virtual manifests are limited
# in many ways and the inability to define patches on them is
Expand All @@ -923,15 +936,15 @@ def _patchup_workspace(self, build_source_dir):
)
f.write(config)

def _resolve_config(self, build_source_dir):
def _resolve_config(self):
"""
Returns a configuration to be put inside root Cargo.toml file which
patches the dependencies git code with local getdeps versions.
See https://doc.rust-lang.org/cargo/reference/manifest.html#the-patch-section
"""
dep_to_git = self._resolve_dep_to_git()
dep_to_crates = CargoBuilder._resolve_dep_to_crates(
build_source_dir, dep_to_git
self.build_source_dir(), dep_to_git
)

config = []
Expand Down Expand Up @@ -960,7 +973,7 @@ def _resolve_dep_to_git(self):
"""
For each direct dependency of the currently build manifest check if it
is also cargo-builded and if yes then extract it's git configs and
install dir
install dir
"""
dependencies = self.manifest.get_section_as_dict("dependencies", ctx=self.ctx)
if not dependencies:
Expand Down
7 changes: 6 additions & 1 deletion build/fbcode_builder/getdeps/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@
},
},
"msbuild": {"optional_section": True, "fields": {"project": REQUIRED}},
"cargo": {"optional_section": True, "fields": {"build_doc": OPTIONAL}},
"cargo": {
"optional_section": True,
"fields": {"build_doc": OPTIONAL, "workspace_dir": OPTIONAL},
},
"cmake.defines": {"optional_section": True},
"autoconf.args": {"optional_section": True},
"b2.args": {"optional_section": True},
Expand Down Expand Up @@ -421,6 +424,7 @@ def create_builder(self, build_options, src_dir, build_dir, inst_dir, ctx, loade

if builder == "cargo":
build_doc = self.get("cargo", "build_doc", False, ctx)
workspace_dir = self.get("cargo", "workspace_dir", "", ctx)
return CargoBuilder(
build_options,
ctx,
Expand All @@ -429,6 +433,7 @@ def create_builder(self, build_options, src_dir, build_dir, inst_dir, ctx, loade
build_dir,
inst_dir,
build_doc,
workspace_dir,
loader,
)

Expand Down
1 change: 1 addition & 0 deletions build/fbcode_builder/manifests/eden
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ fbcode/tools/lfs = tools/lfs
[shipit.strip]
^fbcode/eden/fs/eden-config\.h$
^fbcode/eden/hg/.*$
^fbcode/eden/mononoke/.*$

[cmake.defines.all(fb=on,os=windows)]
INSTALL_PYTHON_LIB=ON
37 changes: 37 additions & 0 deletions build/fbcode_builder/manifests/mononoke
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[manifest]
name = mononoke
fbsource_path = fbcode/eden
shipit_project = eden
shipit_fbcode_builder = true

[git]
repo_url = https://github.com/facebookexperimental/eden.git

[build.not(os=windows)]
builder = cargo

[build.os=windows]
# building Mononoke on windows is not supported
builder = nop

[cargo]
build_doc = true
workspace_dir = eden/mononoke

[shipit.pathmap]
fbcode/eden/oss = .
fbcode/eden = eden
fbcode/eden/mononoke/public_autocargo = eden/mononoke
fbcode/tools/lfs = tools/lfs
tools/rust/ossconfigs = .

[shipit.strip]
# strip all code unrelated to mononoke to prevent triggering unnecessary checks
^fbcode/eden/(?!mononoke)/.*$
^fbcode/eden/mononoke/(?!public_autocargo).+/Cargo\.toml$

[dependencies]
rust-shed

[dependencies.fb=on]
rust

0 comments on commit 4c624f3

Please sign in to comment.