From 6753ba21c4ae39e20112d4d1cdfd3133f0fd64c8 Mon Sep 17 00:00:00 2001 From: Matt Crane Date: Mon, 17 Apr 2023 05:46:32 -0700 Subject: [PATCH] fix: allow server functions to work with non-Cargo build systems with `SERVER_FN_OVERRIDE_KEY` env var (#878) --- server_fn_macro/src/lib.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/server_fn_macro/src/lib.rs b/server_fn_macro/src/lib.rs index c5f426570e..096721a747 100644 --- a/server_fn_macro/src/lib.rs +++ b/server_fn_macro/src/lib.rs @@ -194,6 +194,11 @@ pub fn server_macro_impl( .map(|path| quote!(#path)) .unwrap_or_else(|| quote! { server_fn }); + let key_env_var = match option_env!("SERVER_FN_OVERRIDE_KEY") { + Some(_) => "SERVER_FN_OVERRIDE_KEY", + None => "CARGO_MANIFEST_DIR", + }; + Ok(quote::quote! { #[derive(Clone, Debug, ::serde::Serialize, ::serde::Deserialize)] pub struct #struct_name { @@ -208,7 +213,7 @@ pub fn server_macro_impl( } fn url() -> &'static str { - #server_fn_path::const_format::concatcp!(#fn_name_as_str, #server_fn_path::xxhash_rust::const_xxh64::xxh64(concat!(env!("CARGO_MANIFEST_DIR"), ":", file!(), ":", line!(), ":", column!()).as_bytes(), 0)) + #server_fn_path::const_format::concatcp!(#fn_name_as_str, #server_fn_path::xxhash_rust::const_xxh64::xxh64(concat!(env!(#key_env_var), ":", file!(), ":", line!(), ":", column!()).as_bytes(), 0)) } fn encoding() -> #server_fn_path::Encoding {