Commit f6d0e220 authored by Lukas Piatkowski's avatar Lukas Piatkowski Committed by Facebook GitHub Bot

cargo_from_buck: add the patch section to Cargo workspace and allow workspace...

cargo_from_buck: add the patch section to Cargo workspace and allow workspace appending to existing manifest

Summary:
Two changes here:
1. The `[patch.crates-io]` section of `third-party/rust/Cargo.toml` is being now copied over to workspaces generated by autocargo for OSS and in the runtime generated Cargo.toml file for cargo-fbcode builds. Without that some projects could be buildable in Buck internally, but not externally on GitHub due to missing patches.
2. If a `[workspace]` Cargo.toml file is being generated and there is already a generated Cargo.toml file in the same directory then instead of overriding that file the `[workspace]` (and `[patch]`) sections are appended to that Cargo.toml file.

Reviewed By: farnz

Differential Revision: D22023144

fbshipit-source-id: dec54491c36c2ee0ab29eefb722b3eceaef6ffe1
parent f0471228
......@@ -724,6 +724,9 @@ class OpenSSLBuilder(BuilderBase):
elif self.build_opts.is_darwin():
make = "make"
args = ["darwin64-x86_64-cc"]
elif self.build_opts.is_linux():
make = "make"
args = ["linux-x86_64"]
else:
raise Exception("don't know how to build openssl for %r" % self.ctx)
......@@ -955,6 +958,7 @@ class CargoBuilder(BuilderBase):
self.add_openssl_to_env(env, install_dirs)
# Enable using nightly features with stable compiler
env["RUSTC_BOOTSTRAP"] = "1"
env["LIBZ_SYS_STATIC"] = "1"
cmd = [
"cargo",
operation,
......@@ -1052,23 +1056,27 @@ git-fetch-with-cli = true
workspace_dir = self.workspace_dir()
config = self._resolve_config()
if config:
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
# one. Check https://github.com/rust-lang/cargo/issues/4934 to
# see if it is resolved.
f.write(
"""
[package]
name = "fake_manifest_of_{}"
version = "0.0.0"
[lib]
path = "/dev/null"
""".format(
self.manifest.name
with open(os.path.join(workspace_dir, "Cargo.toml"), "r+") as f:
manifest_content = f.read()
if "[package]" not in manifest_content:
# 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
# one. Check https://github.com/rust-lang/cargo/issues/4934 to
# see if it is resolved.
f.write(
"""
[package]
name = "fake_manifest_of_{}"
version = "0.0.0"
[lib]
path = "/dev/null"
""".format(
self.manifest.name
)
)
)
else:
f.write("\n")
f.write(config)
def _resolve_config(self):
......
......@@ -30,6 +30,7 @@ tools/rust/ossconfigs = .
[shipit.strip]
# strip all code unrelated to mononoke to prevent triggering unnecessary checks
^fbcode/eden/(?!mononoke|scm/lib/xdiff.*)/.*$
^fbcode/eden/mononoke/Cargo\.toml$
^fbcode/eden/mononoke/(?!public_autocargo).+/Cargo\.toml$
^fbcode/configerator/structs/scm/mononoke/(?!public_autocargo).+/Cargo\.toml$
......
......@@ -24,13 +24,9 @@ tools/rust/ossconfigs = .
[dependencies]
fbthrift
# macOS doesn't expose the openssl api so we need to build our own.
[dependencies.os=darwin]
openssl
# Windows doesn't have openssl, so we get to provide it
[dependencies.os=windows]
# Windows doesn't have openssl and Linux might contain an old version,
# so we get to provide it
openssl
[dependencies.fb=on]
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment