From 94eadd1d76d3f084b45908d5ea9e5cded29a296a Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Thu, 15 Sep 2022 14:05:14 +0200 Subject: [PATCH 1/3] Disable Deno snapshotting when docs.rs builds docs This attempts to fix build errors like https://docs.rs/crate/apollo-router/1.0.0-rc.0/builds/629200 by imitating what Deno does in https://github.com/denoland/deno/blob/6bb72a80863ac3913d32ea21aae32dd327ce6b71/runtime/build.rs#L228-238 --- federation-2/router-bridge/Cargo.toml | 8 ++++++++ federation-2/router-bridge/build.rs | 16 +++++++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/federation-2/router-bridge/Cargo.toml b/federation-2/router-bridge/Cargo.toml index 3433d2bb1..a3e7dc0b7 100644 --- a/federation-2/router-bridge/Cargo.toml +++ b/federation-2/router-bridge/Cargo.toml @@ -45,3 +45,11 @@ tracing-test = "0.2.1" [build-dependencies] deno_core = "0.142.0" which = "4.2.2" + +[features] +# "fake" feature to disable V8 usage when building on docs.rs +# See ./build.rs +docsrs = [] + +[package.metadata.docs.rs] +features = ["docsrs"] diff --git a/federation-2/router-bridge/build.rs b/federation-2/router-bridge/build.rs index 435c3a4c4..7e936aab7 100644 --- a/federation-2/router-bridge/build.rs +++ b/federation-2/router-bridge/build.rs @@ -1,6 +1,3 @@ -use deno_core::{JsRuntime, RuntimeOptions}; -use std::fs::{read_to_string, File}; -use std::io::Write; use std::path::{Path, PathBuf}; use std::process::Command; @@ -69,7 +66,20 @@ fn update_bridge(current_dir: &Path) { .success()); } +#[cfg(feature = "docsrs")] fn create_snapshot(out_dir: &Path) { + // If we're building on docs.rs we just create + // and empty snapshot file and return, because `rusty_v8` + // doesn't actually compile on docs.rs + std::fs::write(out_dir.join("query_runtime.snap"), &[]).unwrap(); +} + +#[cfg(not(feature = "docsrs"))] +fn create_snapshot(out_dir: &Path) { + use deno_core::{JsRuntime, RuntimeOptions}; + use std::fs::{read_to_string, File}; + use std::io::Write; + let options = RuntimeOptions { will_snapshot: true, ..Default::default() From a13b9f0fc40dc8589992203fe5252a50ad891e38 Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Thu, 15 Sep 2022 14:27:25 +0200 Subject: [PATCH 2/3] Apply suggestions from code review Co-authored-by: Gary Pennington --- federation-2/router-bridge/Cargo.toml | 2 +- federation-2/router-bridge/build.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/federation-2/router-bridge/Cargo.toml b/federation-2/router-bridge/Cargo.toml index a3e7dc0b7..de27c440e 100644 --- a/federation-2/router-bridge/Cargo.toml +++ b/federation-2/router-bridge/Cargo.toml @@ -49,7 +49,7 @@ which = "4.2.2" [features] # "fake" feature to disable V8 usage when building on docs.rs # See ./build.rs -docsrs = [] +docs_rs = [] [package.metadata.docs.rs] features = ["docsrs"] diff --git a/federation-2/router-bridge/build.rs b/federation-2/router-bridge/build.rs index 7e936aab7..ab732db5a 100644 --- a/federation-2/router-bridge/build.rs +++ b/federation-2/router-bridge/build.rs @@ -69,7 +69,7 @@ fn update_bridge(current_dir: &Path) { #[cfg(feature = "docsrs")] fn create_snapshot(out_dir: &Path) { // If we're building on docs.rs we just create - // and empty snapshot file and return, because `rusty_v8` + // an empty snapshot file and return, because `rusty_v8` // doesn't actually compile on docs.rs std::fs::write(out_dir.join("query_runtime.snap"), &[]).unwrap(); } From 35742bbb9db3f6ec8992df553d3f7983cf9c26cb Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Thu, 15 Sep 2022 14:28:51 +0200 Subject: [PATCH 3/3] Other uses of the renamed feature flag --- federation-2/router-bridge/Cargo.toml | 2 +- federation-2/router-bridge/build.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/federation-2/router-bridge/Cargo.toml b/federation-2/router-bridge/Cargo.toml index de27c440e..66d8c3802 100644 --- a/federation-2/router-bridge/Cargo.toml +++ b/federation-2/router-bridge/Cargo.toml @@ -52,4 +52,4 @@ which = "4.2.2" docs_rs = [] [package.metadata.docs.rs] -features = ["docsrs"] +features = ["docs_rs"] diff --git a/federation-2/router-bridge/build.rs b/federation-2/router-bridge/build.rs index ab732db5a..178aa1c08 100644 --- a/federation-2/router-bridge/build.rs +++ b/federation-2/router-bridge/build.rs @@ -66,7 +66,7 @@ fn update_bridge(current_dir: &Path) { .success()); } -#[cfg(feature = "docsrs")] +#[cfg(feature = "docs_rs")] fn create_snapshot(out_dir: &Path) { // If we're building on docs.rs we just create // an empty snapshot file and return, because `rusty_v8` @@ -74,7 +74,7 @@ fn create_snapshot(out_dir: &Path) { std::fs::write(out_dir.join("query_runtime.snap"), &[]).unwrap(); } -#[cfg(not(feature = "docsrs"))] +#[cfg(not(feature = "docs_rs"))] fn create_snapshot(out_dir: &Path) { use deno_core::{JsRuntime, RuntimeOptions}; use std::fs::{read_to_string, File};