forked from xamarin/GoogleApisForiOSComponents
-
-
Notifications
You must be signed in to change notification settings - Fork 29
[codex] Fix Cloud Functions emulator runtime drift #113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
AdamEssenmacher
merged 6 commits into
main
from
codex/runtime-drift-cloudfunctions-emulator-origin
Apr 10, 2026
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9834976
Fix Cloud Functions emulator runtime drift
AdamEssenmacher 18b41ac
Link Cloud Functions runtime drift PR
AdamEssenmacher b5d605a
Persist Cloud Functions emulator origin on native instance
AdamEssenmacher 8bc5238
Keep Cloud Functions emulator fix as a thin binding
AdamEssenmacher f1cb678
Revert incidental Cloud Functions version cleanup
AdamEssenmacher d597783
Drop Cloud Functions whitespace-only churn
AdamEssenmacher File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,23 +1,80 @@ | ||
| using System; | ||
| using System.Runtime.CompilerServices; | ||
| using System.Runtime.InteropServices; | ||
| using ObjCRuntime; | ||
| namespace Firebase.CloudFunctions { | ||
| public partial class CloudFunctions { | ||
| static string currentVersion; | ||
| static string? currentVersion; | ||
| // The current native SDK only exposes useEmulatorWithHost:port: to ObjC, so preserve the | ||
| // managed emulatorOrigin/useFunctionsEmulatorOrigin API by caching the last requested origin. | ||
| static readonly ConditionalWeakTable<CloudFunctions, EmulatorOriginState> emulatorOrigins = new (); | ||
|
|
||
| sealed class EmulatorOriginState { | ||
| public string? Origin { get; set; } | ||
| } | ||
|
|
||
| public static string CurrentVersion { | ||
| get { | ||
| if (currentVersion == null) { | ||
| IntPtr RTLD_MAIN_ONLY = Dlfcn.dlopen (null, 0); | ||
| IntPtr ptr = Dlfcn.dlsym (RTLD_MAIN_ONLY, "FirebaseCloudFunctionsVersionStr"); | ||
| currentVersion = Marshal.PtrToStringAnsi (ptr); | ||
| Dlfcn.dlclose (RTLD_MAIN_ONLY); | ||
| } | ||
| currentVersion = Marshal.PtrToStringAnsi (ptr) ?? string.Empty; | ||
| Dlfcn.dlclose (RTLD_MAIN_ONLY); | ||
| } | ||
|
|
||
| return currentVersion; | ||
| return currentVersion ?? string.Empty; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| public const string CloudFunctionsErrorDomain = "com.firebase.functions"; | ||
| public const string CloudFunctionsErrorDetailsKey = "details"; | ||
|
|
||
| public string? EmulatorOrigin => emulatorOrigins.GetOrCreateValue (this).Origin; | ||
|
|
||
| public void UseFunctionsEmulatorOrigin (string origin) | ||
| { | ||
| var (host, port) = ParseEmulatorOrigin (origin); | ||
| UseEmulatorOriginWithHost (host, port); | ||
|
AdamEssenmacher marked this conversation as resolved.
Outdated
|
||
| emulatorOrigins.GetOrCreateValue (this).Origin = origin; | ||
| } | ||
|
|
||
| public void UseEmulatorOriginWithHost (string host, uint port) | ||
| { | ||
| if (string.IsNullOrWhiteSpace (host)) | ||
| throw new ArgumentException ("Host must not be null or empty.", nameof (host)); | ||
|
|
||
| _UseEmulatorOriginWithHost (host, checked ((nint) port)); | ||
| emulatorOrigins.GetOrCreateValue (this).Origin = $"{host}:{port}"; | ||
| } | ||
|
|
||
| static (string Host, uint Port) ParseEmulatorOrigin (string origin) | ||
| { | ||
| if (string.IsNullOrWhiteSpace (origin)) | ||
| throw new ArgumentException ("Origin must not be null or empty.", nameof (origin)); | ||
|
|
||
| if (TryParseOrigin (origin, out var host, out var port)) | ||
| return (host, port); | ||
|
|
||
| if (TryParseOrigin ($"http://{origin}", out host, out port)) | ||
| return (host, port); | ||
|
|
||
| throw new ArgumentException ("Expected a Cloud Functions emulator origin in 'host:port' or absolute URL form.", nameof (origin)); | ||
| } | ||
|
|
||
| static bool TryParseOrigin (string origin, out string host, out uint port) | ||
| { | ||
| host = string.Empty; | ||
| port = 0; | ||
|
|
||
| if (!Uri.TryCreate (origin, UriKind.Absolute, out var uri)) | ||
| return false; | ||
|
|
||
| if (string.IsNullOrWhiteSpace (uri.Host) || uri.Port <= 0) | ||
| return false; | ||
|
|
||
| host = uri.Host; | ||
| port = checked ((uint) uri.Port); | ||
| return true; | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.