Skip to content

Commit 34628b5

Browse files
committed
Initial commit
0 parents  commit 34628b5

7 files changed

Lines changed: 256 additions & 0 deletions

File tree

.github/workflows/publish.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Build & Publish
2+
3+
on:
4+
workflow_dispatch:
5+
6+
push:
7+
tags:
8+
- 'v*.*.*'
9+
10+
jobs:
11+
build:
12+
13+
runs-on: macos-latest
14+
15+
steps:
16+
- uses: actions/checkout@v4
17+
- name: Setup .NET
18+
uses: actions/setup-dotnet@v4
19+
with:
20+
dotnet-version: 9.0.x
21+
22+
- name: Workloads Restore
23+
run: dotnet workload restore src/Firebase.iOS.BitcodeStrip/Firebase.iOS.BitcodeStrip.csproj
24+
25+
- name: Pack
26+
run: dotnet pack src/Firebase.iOS.BitcodeStrip/Firebase.iOS.BitcodeStrip.csproj --output packs
27+
28+
- name: List output
29+
run: ls -l packs
30+
31+
- name: Publish to NuGet
32+
run: dotnet nuget push "packs/*.nupkg" --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
src/Firebase.iOS.BitcodeStrip/obj
2+
src/Firebase.iOS.BitcodeStrip/bin

README.md

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
[![NuGet](https://img.shields.io/nuget/v/Xam.Firebase.iOS.BitcodeStrip.svg)](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="&quot;%24(xcrun -find bitcode_strip)&quot; %(_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 &quot;%24(dirname &quot;%24(xcrun -find bitcode_strip)&quot;)&quot; &amp;&amp; ./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+
___

src/Firebase.iOS.BitcodeStrip.sln

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.0.31903.59
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Firebase.iOS.BitcodeStrip", "Firebase.iOS.BitcodeStrip\Firebase.iOS.BitcodeStrip.csproj", "{7AB70646-0C7A-4C23-B80D-EB792C20FEB3}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Debug|x64 = Debug|x64
12+
Debug|x86 = Debug|x86
13+
Release|Any CPU = Release|Any CPU
14+
Release|x64 = Release|x64
15+
Release|x86 = Release|x86
16+
EndGlobalSection
17+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
18+
{7AB70646-0C7A-4C23-B80D-EB792C20FEB3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
19+
{7AB70646-0C7A-4C23-B80D-EB792C20FEB3}.Debug|Any CPU.Build.0 = Debug|Any CPU
20+
{7AB70646-0C7A-4C23-B80D-EB792C20FEB3}.Debug|x64.ActiveCfg = Debug|Any CPU
21+
{7AB70646-0C7A-4C23-B80D-EB792C20FEB3}.Debug|x64.Build.0 = Debug|Any CPU
22+
{7AB70646-0C7A-4C23-B80D-EB792C20FEB3}.Debug|x86.ActiveCfg = Debug|Any CPU
23+
{7AB70646-0C7A-4C23-B80D-EB792C20FEB3}.Debug|x86.Build.0 = Debug|Any CPU
24+
{7AB70646-0C7A-4C23-B80D-EB792C20FEB3}.Release|Any CPU.ActiveCfg = Release|Any CPU
25+
{7AB70646-0C7A-4C23-B80D-EB792C20FEB3}.Release|Any CPU.Build.0 = Release|Any CPU
26+
{7AB70646-0C7A-4C23-B80D-EB792C20FEB3}.Release|x64.ActiveCfg = Release|Any CPU
27+
{7AB70646-0C7A-4C23-B80D-EB792C20FEB3}.Release|x64.Build.0 = Release|Any CPU
28+
{7AB70646-0C7A-4C23-B80D-EB792C20FEB3}.Release|x86.ActiveCfg = Release|Any CPU
29+
{7AB70646-0C7A-4C23-B80D-EB792C20FEB3}.Release|x86.Build.0 = Release|Any CPU
30+
EndGlobalSection
31+
GlobalSection(SolutionProperties) = preSolution
32+
HideSolutionNode = FALSE
33+
EndGlobalSection
34+
EndGlobal
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<!--
4+
That solves following issue https://github.com/dotnet/macios/issues/22591
5+
by overriding Xamarin.Firebase.iOS.Core targets and setting proper working dir for bitcode_strip execution (XCode 16.4).
6+
It works well if executed from dir it resides in: it locates "strip" utility that resides in same dir without any issues,
7+
otherwise it fails with "ld: file cannot be open()ed, errno=2 path=strip" error.
8+
-->
9+
<Target Name="_FirebaseStripBitcodeFromFrameworksOnMac">
10+
<!-- Get the frameworks to strip bitcode -->
11+
<FindInList
12+
List="@(_FrameworkNativeReference)"
13+
ItemSpecToFind="%(_FrameworkNamesToStripBitcode.Identity)"
14+
MatchFileNameOnly="True">
15+
<Output TaskParameter="ItemFound" ItemName="_FrameworksToStripBitcode"/>
16+
</FindInList>
17+
18+
<!-- Find the bitcode_strip command -->
19+
<Exec Command="xcrun -find bitcode_strip" ConsoleToMSBuild="true">
20+
<Output TaskParameter="ConsoleOutput" PropertyName="_BitcodeStripCommand" />
21+
</Exec>
22+
23+
<!-- Capture bitcode_strip dir -->
24+
<PropertyGroup>
25+
<_BitcodeStripDir>$([System.IO.Path]::GetDirectoryName($(_BitcodeStripCommand)))</_BitcodeStripDir>
26+
</PropertyGroup>
27+
28+
<!-- Strip the bitcode from frameworks -->
29+
<Exec WorkingDirectory="$(_BitcodeStripDir)" Command="./bitcode_strip %(_FrameworksToStripBitcode.Identity) -r -o %(_FrameworksToStripBitcode.Identity)"/>
30+
</Target>
31+
32+
<Target Name="_FirebaseStripBitcodeFromFrameworksOnWindows"
33+
Condition="'$(IsMacEnabled)'=='true'">
34+
<!-- Get the frameworks to strip bitcode -->
35+
<FindInList
36+
CaseSensitive="false"
37+
List="@(_FrameworkNativeReference)"
38+
ItemSpecToFind="%(_FrameworkNamesToStripBitcode.Identity)"
39+
MatchFileNameOnly="True">
40+
<Output TaskParameter="ItemFound" ItemName="_FrameworksToStripBitcode"/>
41+
</FindInList>
42+
43+
<!-- Strip the bitcode from frameworks -->
44+
<!--
45+
use subshell for safe change of working dir, so it will not cause any side effects on subsequent commands
46+
(cd "$(dirname "$(xcrun -find bitcode_strip)")" && ./bitcode_strip %(_FrameworksToStripBitcode.Identity) -r -o %(_FrameworksToStripBitcode.Identity))
47+
-->
48+
<Exec SessionId="$(BuildSessionId)"
49+
Command="(cd &quot;%24(dirname &quot;%24(xcrun -find bitcode_strip)&quot;)&quot; &amp;&amp; ./bitcode_strip %(_FrameworksToStripBitcode.Identity) -r -o %(_FrameworksToStripBitcode.Identity))" />
50+
51+
<CopyFileFromBuildServer
52+
SessionId="$(BuildSessionId)"
53+
File="%(_FrameworksToStripBitcode.Identity)"
54+
TargetFile="%(_FrameworksToStripBitcode.Identity)" />
55+
</Target>
56+
</Project>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<Project Sdk="Microsoft.Build.NoTargets/3.7.134">
2+
<PropertyGroup>
3+
<TargetFramework>net9.0-ios18.0</TargetFramework>
4+
</PropertyGroup>
5+
<PropertyGroup>
6+
<PackageId>Xam.Firebase.iOS.BitcodeStrip</PackageId>
7+
<Version>1.0.0</Version>
8+
<Authors>yaliashkevich</Authors>
9+
<Description>Helper tool for stripping bitcode from native frameworks shipped with Xamarin.Firebase.iOS.* packages, ensuring compatibility with the modern Xcode toolchain.</Description>
10+
<PackageLicenseExpression>MIT</PackageLicenseExpression>
11+
<RepositoryUrl>https://github.com/yaliashkevich/Firebase.iOS.BitcodeStrip.git</RepositoryUrl>
12+
<PackageProjectUrl>https://github.com/yaliashkevich/Firebase.iOS.BitcodeStrip</PackageProjectUrl>
13+
<PackageReadmeFile>Readme.md</PackageReadmeFile>
14+
<PackageTags>xamarin;firebase;ios;bitcode;bitcode_strip</PackageTags>
15+
</PropertyGroup>
16+
<ItemGroup>
17+
<PackageReference Include="Xamarin.Firebase.iOS.Core" Version="8.10.0.3" />
18+
</ItemGroup>
19+
<ItemGroup>
20+
<None Include="README.md" Pack="true" PackagePath="\" />
21+
<None Include="$(IntermediateOutputPath)_._" Pack="true" PackagePath="lib\$(TargetFramework)\_._" />
22+
<None Include="BitcodeStrip.targets"
23+
Pack="true"
24+
PackagePath="build\$(TargetFramework)\$(PackageId).targets" />
25+
<None Include="BitcodeStrip.targets"
26+
Pack="true"
27+
PackagePath="buildTransitive\$(TargetFramework)\$(PackageId).targets" />
28+
</ItemGroup>
29+
<Target Name="EnsureEmptyMarker" BeforeTargets="GenerateNuspec">
30+
<WriteLinesToFile File="$(IntermediateOutputPath)_._" Lines="" Overwrite="true" />
31+
</Target>
32+
</Project>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Helper tool for stripping bitcode from native frameworks shipped with Xamarin.Firebase.iOS.* packages, ensuring compatibility with the modern Xcode toolchain.
2+
https://github.com/yaliashkevich/Firebase.iOS.BitcodeStrip

0 commit comments

Comments
 (0)