Skip to content

Commit b1effb4

Browse files
lukaspiatkowskimarch-github
authored andcommitted
mononoke: add README.md and the missing pieces for supporting cargo (facebookarchive#13)
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
1 parent 067dc94 commit b1effb4

File tree

4 files changed

+71
-15
lines changed

4 files changed

+71
-15
lines changed

build/fbcode_builder/getdeps/builder.py

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -813,12 +813,22 @@ def _build(self, install_dirs, reconfigure):
813813

814814
class CargoBuilder(BuilderBase):
815815
def __init__(
816-
self, build_opts, ctx, manifest, src_dir, build_dir, inst_dir, build_doc, loader
816+
self,
817+
build_opts,
818+
ctx,
819+
manifest,
820+
src_dir,
821+
build_dir,
822+
inst_dir,
823+
build_doc,
824+
workspace_dir,
825+
loader,
817826
):
818827
super(CargoBuilder, self).__init__(
819828
build_opts, ctx, manifest, src_dir, build_dir, inst_dir
820829
)
821830
self.build_doc = build_doc
831+
self.ws_dir = workspace_dir
822832
self.loader = loader
823833

824834
def run_cargo(self, install_dirs, operation, args=None):
@@ -832,11 +842,14 @@ def run_cargo(self, install_dirs, operation, args=None):
832842
"--workspace",
833843
"-j%s" % self.build_opts.num_jobs,
834844
] + args
835-
self._run_cmd(cmd, cwd=self.build_source_dir(), env=env)
845+
self._run_cmd(cmd, cwd=self.workspace_dir(), env=env)
836846

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

850+
def workspace_dir(self):
851+
return os.path.join(self.build_source_dir(), self.ws_dir)
852+
840853
def recreate_dir(self, src, dst):
841854
if os.path.isdir(dst):
842855
shutil.rmtree(dst)
@@ -862,7 +875,7 @@ def _build(self, install_dirs, reconfigure):
862875
)
863876
)
864877

865-
self._patchup_workspace(build_source_dir)
878+
self._patchup_workspace()
866879

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

884-
def _patchup_workspace(self, build_source_dir):
897+
def _patchup_workspace(self):
885898
"""
886-
This method makes a lot of assumptions about the state of the project
887-
and its cargo dependendies:
888-
1. There is a virtual manifest with workspace in the root of this project
889-
2. Crates from cargo dependencies can be extracted from Cargo.toml files
899+
This method makes some assumptions about the state of the project and
900+
its cargo dependendies:
901+
1. Crates from cargo dependencies can be extracted from Cargo.toml files
890902
using _extract_crates function. It is using a heuristic so check its
891903
code to understand how it is done.
892-
3. The extracted cargo dependencies crates can be found in the
904+
2. The extracted cargo dependencies crates can be found in the
893905
dependency's install dir using _resolve_crate_to_path function
894906
which again is using a heuristic.
895907
@@ -902,9 +914,10 @@ def _patchup_workspace(self, build_source_dir):
902914
Exception. There migh be more cases where the code will silently pass
903915
producing bad results.
904916
"""
905-
config = self._resolve_config(build_source_dir)
917+
workspace_dir = self.workspace_dir()
918+
config = self._resolve_config()
906919
if config:
907-
with open(os.path.join(build_source_dir, "Cargo.toml"), "a") as f:
920+
with open(os.path.join(workspace_dir, "Cargo.toml"), "a") as f:
908921
# A fake manifest has to be crated to change the virtual
909922
# manifest into a non-virtual. The virtual manifests are limited
910923
# in many ways and the inability to define patches on them is
@@ -923,15 +936,15 @@ def _patchup_workspace(self, build_source_dir):
923936
)
924937
f.write(config)
925938

926-
def _resolve_config(self, build_source_dir):
939+
def _resolve_config(self):
927940
"""
928941
Returns a configuration to be put inside root Cargo.toml file which
929942
patches the dependencies git code with local getdeps versions.
930943
See https://doc.rust-lang.org/cargo/reference/manifest.html#the-patch-section
931944
"""
932945
dep_to_git = self._resolve_dep_to_git()
933946
dep_to_crates = CargoBuilder._resolve_dep_to_crates(
934-
build_source_dir, dep_to_git
947+
self.build_source_dir(), dep_to_git
935948
)
936949

937950
config = []
@@ -960,7 +973,7 @@ def _resolve_dep_to_git(self):
960973
"""
961974
For each direct dependency of the currently build manifest check if it
962975
is also cargo-builded and if yes then extract it's git configs and
963-
install dir
976+
install dir
964977
"""
965978
dependencies = self.manifest.get_section_as_dict("dependencies", ctx=self.ctx)
966979
if not dependencies:

build/fbcode_builder/getdeps/manifest.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,10 @@
6969
},
7070
},
7171
"msbuild": {"optional_section": True, "fields": {"project": REQUIRED}},
72-
"cargo": {"optional_section": True, "fields": {"build_doc": OPTIONAL}},
72+
"cargo": {
73+
"optional_section": True,
74+
"fields": {"build_doc": OPTIONAL, "workspace_dir": OPTIONAL},
75+
},
7376
"cmake.defines": {"optional_section": True},
7477
"autoconf.args": {"optional_section": True},
7578
"b2.args": {"optional_section": True},
@@ -421,6 +424,7 @@ def create_builder(self, build_options, src_dir, build_dir, inst_dir, ctx, loade
421424

422425
if builder == "cargo":
423426
build_doc = self.get("cargo", "build_doc", False, ctx)
427+
workspace_dir = self.get("cargo", "workspace_dir", "", ctx)
424428
return CargoBuilder(
425429
build_options,
426430
ctx,
@@ -429,6 +433,7 @@ def create_builder(self, build_options, src_dir, build_dir, inst_dir, ctx, loade
429433
build_dir,
430434
inst_dir,
431435
build_doc,
436+
workspace_dir,
432437
loader,
433438
)
434439

build/fbcode_builder/manifests/eden

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ fbcode/tools/lfs = tools/lfs
4848
[shipit.strip]
4949
^fbcode/eden/fs/eden-config\.h$
5050
^fbcode/eden/hg/.*$
51+
^fbcode/eden/mononoke/.*$
5152

5253
[cmake.defines.all(fb=on,os=windows)]
5354
INSTALL_PYTHON_LIB=ON
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
[manifest]
2+
name = mononoke
3+
fbsource_path = fbcode/eden
4+
shipit_project = eden
5+
shipit_fbcode_builder = true
6+
7+
[git]
8+
repo_url = https://github.com/facebookexperimental/eden.git
9+
10+
[build.not(os=windows)]
11+
builder = cargo
12+
13+
[build.os=windows]
14+
# building Mononoke on windows is not supported
15+
builder = nop
16+
17+
[cargo]
18+
build_doc = true
19+
workspace_dir = eden/mononoke
20+
21+
[shipit.pathmap]
22+
fbcode/eden/oss = .
23+
fbcode/eden = eden
24+
fbcode/eden/mononoke/public_autocargo = eden/mononoke
25+
fbcode/tools/lfs = tools/lfs
26+
tools/rust/ossconfigs = .
27+
28+
[shipit.strip]
29+
# strip all code unrelated to mononoke to prevent triggering unnecessary checks
30+
^fbcode/eden/(?!mononoke)/.*$
31+
^fbcode/eden/mononoke/(?!public_autocargo).+/Cargo\.toml$
32+
33+
[dependencies]
34+
rust-shed
35+
36+
[dependencies.fb=on]
37+
rust

0 commit comments

Comments
 (0)