diff --git a/apollo-federation-types/src/config/version.rs b/apollo-federation-types/src/config/version.rs index 199fd4b16..ff21d8bdd 100644 --- a/apollo-federation-types/src/config/version.rs +++ b/apollo-federation-types/src/config/version.rs @@ -127,8 +127,8 @@ impl FederationVersion { if self.is_latest() { supports_arm = true; } else if let Some(exact) = self.get_exact() { - // v2.7.3 is the earliest version published with aarch64 support for macOS - supports_arm = exact.ge(&Version::parse("2.7.3").unwrap()) + // v2.7.3 is the earliest version published with aarch64 support for macOS + supports_arm = exact.ge(&Version::parse("2.7.3").unwrap()) } } supports_arm diff --git a/harmonizer/build.rs b/harmonizer/build.rs index 1d461b020..f2ad1bf67 100644 --- a/harmonizer/build.rs +++ b/harmonizer/build.rs @@ -198,6 +198,12 @@ fn get_underlying_composition_npm_module_version() -> Version { parsed_version } +#[cfg(all(target_os = "macos", target_arch = "x86_64"))] +fn create_snapshot(out_dir: &Path) -> Result<(), Box> { + Ok(()) +} + +#[cfg(not(all(target_os = "macos", target_arch = "x86_64")))] fn create_snapshot(out_dir: &Path) -> Result<(), Box> { let options = RuntimeOptions { ..Default::default() diff --git a/harmonizer/src/lib.rs b/harmonizer/src/lib.rs index 3388443d5..cf30000de 100644 --- a/harmonizer/src/lib.rs +++ b/harmonizer/src/lib.rs @@ -29,7 +29,9 @@ composition implementation while we work toward something else. #![forbid(unsafe_code)] #![deny(missing_debug_implementations, nonstandard_style)] #![warn(missing_docs, future_incompatible, unreachable_pub, rust_2018_idioms)] -use deno_core::{JsRuntime, RuntimeOptions, Snapshot}; +#[cfg(not(all(target_os = "macos", target_arch = "x86_64")))] +use deno_core::Snapshot; +use deno_core::{JsRuntime, RuntimeOptions}; mod js_types; @@ -44,7 +46,6 @@ const APOLLO_HARMONIZER_EXPERIMENTAL_V8_INITIAL_HEAP_SIZE_DEFAULT: &str = "256"; // A reasonable default max limit for our deno heap. const APOLLO_HARMONIZER_EXPERIMENTAL_V8_MAX_HEAP_SIZE_DEFAULT: &str = "1400"; - /// The `harmonize` function receives a [`Vec`] and invokes JavaScript /// composition on it, either returning the successful output, or a list of error messages. pub fn harmonize(subgraph_definitions: Vec) -> BuildResult { @@ -58,19 +59,15 @@ pub fn harmonize_limit( subgraph_definitions: Vec, nodes_limit: Option, ) -> BuildResult { - // The snapshot is created in the build_harmonizer.rs script and included in our binary image - let buffer = include_bytes!(concat!(env!("OUT_DIR"), "/composition.snap")); - - let initial_heap_size = - std::env::var("APOLLO_HARMONIZER_EXPERIMENTAL_V8_INITIAL_HEAP_SIZE").unwrap_or_else(|_e| { + let initial_heap_size = std::env::var("APOLLO_HARMONIZER_EXPERIMENTAL_V8_INITIAL_HEAP_SIZE") + .unwrap_or_else(|_e| { APOLLO_HARMONIZER_EXPERIMENTAL_V8_INITIAL_HEAP_SIZE_DEFAULT.to_string() }); let max_heap_size_maybe = std::env::var("APOLLO_HARMONIZER_EXPERIMENTAL_V8_MAX_HEAP_SIZE").ok(); let max_heap_size_provided = max_heap_size_maybe.is_some(); - let max_heap_size = max_heap_size_maybe.unwrap_or_else(|| { - APOLLO_HARMONIZER_EXPERIMENTAL_V8_MAX_HEAP_SIZE_DEFAULT.to_string() - }); + let max_heap_size = max_heap_size_maybe + .unwrap_or_else(|| APOLLO_HARMONIZER_EXPERIMENTAL_V8_MAX_HEAP_SIZE_DEFAULT.to_string()); // The first flag is argv[0], so provide an ignorable value let flags = vec![ @@ -91,12 +88,36 @@ pub fn harmonize_limit( panic!("deno ignored these flags: {:?}", ignored); } - // Use our snapshot to provision our new runtime - let options = RuntimeOptions { + // The snapshot is created in the build_harmonizer.rs script and included in our binary image + #[cfg(not(all(target_os = "macos", target_arch = "x86_64")))] + let buffer = include_bytes!(concat!(env!("OUT_DIR"), "/composition.snap")); + + #[cfg(not(all(target_os = "macos", target_arch = "x86_64")))] + let mut runtime = JsRuntime::new(RuntimeOptions { startup_snapshot: Some(Snapshot::Static(buffer)), ..Default::default() + }); + + #[cfg(all(target_os = "macos", target_arch = "x86_64"))] + let mut runtime = { + let mut runtime = JsRuntime::new(RuntimeOptions { + ..Default::default() + }); + + // The runtime automatically contains a Deno.core object with several + // functions for interacting with it. + let runtime_str = include_str!("../bundled/runtime.js"); + runtime + .execute_script("", deno_core::FastString::Owned(runtime_str.into())) + .expect("unable to initialize router bridge runtime environment"); + + // Load the composition library. + let bridge_str = include_str!("../bundled/composition_bridge.js"); + runtime + .execute_script("bridge.js", deno_core::FastString::Owned(bridge_str.into())) + .expect("unable to evaluate bridge module"); + runtime }; - let mut runtime = JsRuntime::new(options); // if max_heap_size was not set, we resize the heap every time // we approach the limit. This is a tradeoff as it might cause diff --git a/router-bridge/src/js.rs b/router-bridge/src/js.rs index 736580289..1341a2afd 100644 --- a/router-bridge/src/js.rs +++ b/router-bridge/src/js.rs @@ -1,6 +1,8 @@ use crate::error::Error; +#[cfg(not(all(target_os = "macos", target_arch = "x86_64")))] +use deno_core::Snapshot; /// Wraps creating the Deno Js runtime collecting parameters and executing a script. -use deno_core::{Extension, JsRuntime, RuntimeOptions, Snapshot}; +use deno_core::{Extension, JsRuntime, RuntimeOptions}; use serde::de::DeserializeOwned; use serde::Serialize;