From 24ed129271c7ac8fd0c936e8b6582a89dd99df9e Mon Sep 17 00:00:00 2001 From: Lukas Piatkowski Date: Wed, 17 Jun 2020 06:26:05 -0700 Subject: [PATCH] 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 --- build/fbcode_builder/getdeps/builder.py | 40 ++++++++++++++---------- build/fbcode_builder/manifests/mononoke | 1 + build/fbcode_builder/manifests/rust-shed | 8 ++--- 3 files changed, 27 insertions(+), 22 deletions(-) diff --git a/build/fbcode_builder/getdeps/builder.py b/build/fbcode_builder/getdeps/builder.py index c69efc87f..3bc92ee1a 100644 --- a/build/fbcode_builder/getdeps/builder.py +++ b/build/fbcode_builder/getdeps/builder.py @@ -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): diff --git a/build/fbcode_builder/manifests/mononoke b/build/fbcode_builder/manifests/mononoke index 604a5c2d9..d14056967 100644 --- a/build/fbcode_builder/manifests/mononoke +++ b/build/fbcode_builder/manifests/mononoke @@ -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$ diff --git a/build/fbcode_builder/manifests/rust-shed b/build/fbcode_builder/manifests/rust-shed index 7cb2f027e..e5cd7d75c 100644 --- a/build/fbcode_builder/manifests/rust-shed +++ b/build/fbcode_builder/manifests/rust-shed @@ -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]