|
| 1 | +[](https://www.nuget.org/packages/Xam.Firebase.iOS.BitcodeStrip/) |
| 2 | + |
| 3 | +# Xam.Firebase.iOS.BitcodeStrip |
| 4 | + |
| 5 | +Workaround for https://github.com/dotnet/macios/issues/22591. |
| 6 | +Just add package reference to `Xam.Firebase.iOS.BitcodeStrip` whereever you reference `Xamarin.Firebase.iOS.*` to get the issue resolved. |
| 7 | + |
| 8 | +``` |
| 9 | +dotnet add package Xam.Firebase.iOS.BitcodeStrip |
| 10 | +``` |
| 11 | + |
| 12 | +## Synopsis |
| 13 | + |
| 14 | +`bitcode_strip` shipped with xcode 16.4 expects to be executed from working directory it resides in, i.e. `/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin`. |
| 15 | + |
| 16 | +If you run it from outside of its' directory it fails with `"ld: file cannot be open()ed, errno=2 path=strip"` error. It can not resolve `strip` utility located alongside. |
| 17 | + |
| 18 | +`Xamarin.Firebase.iOS.*` binding packages wrap firebase sdk version that shipped with `bitcode` inside. `bitcode` is deprecated by Apple. Apple does not accept app store submissions with `bitcode` anymore. That is why bindings do rely on 'bitcode_strip' to remove bitcode from native frameworks. Strip invocation is done by extending msbuild process with following targets: |
| 19 | + |
| 20 | +MacOS |
| 21 | +``` |
| 22 | +<Target Name="_FirebaseStripBitcodeFromFrameworksOnMac"> |
| 23 | + <!-- Get the frameworks to strip bitcode --> |
| 24 | + <FindInList |
| 25 | + List="@(_FrameworkNativeReference)" |
| 26 | + ItemSpecToFind="%(_FrameworkNamesToStripBitcode.Identity)" |
| 27 | + MatchFileNameOnly="True"> |
| 28 | + <Output TaskParameter="ItemFound" ItemName="_FrameworksToStripBitcode"/> |
| 29 | + </FindInList> |
| 30 | +
|
| 31 | + <!-- Find the bitcode_strip command --> |
| 32 | + <Exec Command="xcrun -find bitcode_strip" ConsoleToMSBuild="true"> |
| 33 | + <Output TaskParameter="ConsoleOutput" PropertyName="_BitcodeStripCommand" /> |
| 34 | + </Exec> |
| 35 | +
|
| 36 | + <!-- Strip the bitcode from frameworks --> |
| 37 | + <Exec Command="$(_BitcodeStripCommand) %(_FrameworksToStripBitcode.Identity) -r -o %(_FrameworksToStripBitcode.Identity)" /> |
| 38 | +</Target> |
| 39 | +``` |
| 40 | +Windows |
| 41 | +``` |
| 42 | +<Target Name="_FirebaseStripBitcodeFromFrameworksOnWindows" |
| 43 | + Condition="'$(IsMacEnabled)'=='true'"> |
| 44 | + <!-- Get the frameworks to strip bitcode --> |
| 45 | + <FindInList |
| 46 | + CaseSensitive="false" |
| 47 | + List="@(_FrameworkNativeReference)" |
| 48 | + ItemSpecToFind="%(_FrameworkNamesToStripBitcode.Identity)" |
| 49 | + MatchFileNameOnly="True"> |
| 50 | + <Output TaskParameter="ItemFound" ItemName="_FrameworksToStripBitcode"/> |
| 51 | + </FindInList> |
| 52 | +
|
| 53 | + <!-- Strip the bitcode from frameworks --> |
| 54 | + <Exec SessionId="$(BuildSessionId)" |
| 55 | + Command=""%24(xcrun -find bitcode_strip)" %(_FrameworksToStripBitcode.Identity) -r -o %(_FrameworksToStripBitcode.Identity)" /> |
| 56 | +
|
| 57 | + <CopyFileFromBuildServer |
| 58 | + SessionId="$(BuildSessionId)" |
| 59 | + File="%(_FrameworksToStripBitcode.Identity)" |
| 60 | + TargetFile="%(_FrameworksToStripBitcode.Identity)" /> |
| 61 | +</Target> |
| 62 | +``` |
| 63 | + |
| 64 | +So `bitcode_strip` is called by absolute path from current project directory and fails. |
| 65 | + |
| 66 | +`Xamarin.Firebase.iOS.*` bindings are not maintained by microsoft anymore. The repository was archived on May 1, 2024 https://github.com/xamarin/GoogleApisForiOSComponents. You should consider moving away from it by making own bindings or use community ones out there if any. Meanwhile use this package as a workaround. |
| 67 | + |
| 68 | +This package employs overrides of the targets mentioned above to ensure that working directory is properly set as expected: |
| 69 | + |
| 70 | +MacOS |
| 71 | +``` |
| 72 | +<!-- Capture bitcode_strip dir --> |
| 73 | +<PropertyGroup> |
| 74 | + <_BitcodeStripDir>$([System.IO.Path]::GetDirectoryName($(_BitcodeStripCommand)))</_BitcodeStripDir> |
| 75 | +</PropertyGroup> |
| 76 | +
|
| 77 | +<!-- Strip the bitcode from frameworks --> |
| 78 | +<Exec WorkingDirectory="$(_BitcodeStripDir)" Command="./bitcode_strip %(_FrameworksToStripBitcode.Identity) -r -o %(_FrameworksToStripBitcode.Identity)"/> |
| 79 | +``` |
| 80 | + |
| 81 | +Windows |
| 82 | +``` |
| 83 | +<!-- |
| 84 | + use subshell for safe change of working dir, so it will not cause any side effects on subsequent commands |
| 85 | + (cd "$(dirname "$(xcrun -find bitcode_strip)")" && ./bitcode_strip %(_FrameworksToStripBitcode.Identity) -r -o %(_FrameworksToStripBitcode.Identity)) |
| 86 | +--> |
| 87 | +<Exec SessionId="$(BuildSessionId)" |
| 88 | + Command="(cd "%24(dirname "%24(xcrun -find bitcode_strip)")" && ./bitcode_strip %(_FrameworksToStripBitcode.Identity) -r -o %(_FrameworksToStripBitcode.Identity))" /> |
| 89 | +``` |
| 90 | + |
| 91 | +We rely on **determenistic order** of targets imports from nuget packages. The order is dictated by dependency graph. If package A references package B than targets from package B are imported before targets from package A. We do explicitly reference `Xamarin.Firebase.iOS.Core` package to ensure the overrides are imported after original targets. |
| 92 | + |
| 93 | +--- |
| 94 | +**Note** |
| 95 | + |
| 96 | +Determenistic order is confirmed here https://github.com/NuGet/Home/issues/4229#issuecomment-271387190 |
| 97 | +> 4.x ensures everything is in dependency order and has the right behavior now. |
| 98 | +___ |
0 commit comments