@@ -7,15 +7,19 @@ description: Create universal Homebrew package which contains x86_64 and arm64
77# that has both x86_64 and arm64 arch, as Homebrew's distributed bottles are thin binaries with only one arch.
88#
99# We still use Homebrew to manage the library because their formulas are up to date and have correct build instructions
10- # that will work. This way we don't have to manually configuring and building and updating the package info.
10+ # that will work. This way we don't have to manually configure, build, and update the package info.
1111
1212inputs :
1313 formula :
14- description : Formura name
14+ description : Formula name
1515 required : true
1616 contents :
1717 description : Path for contents in package's keg
1818 required : true
19+ gnuiconv :
20+ description : Use the Homebrew GNU libiconv instead of system one
21+ type : boolean
22+ required : false
1923runs :
2024 using : ' composite'
2125 steps :
@@ -31,14 +35,24 @@ runs:
3135 # version and stomp what we have here.
3236 brew update
3337
38+ brew cat ${formula} >${formula}.rb
39+
40+ if [[ "${{ inputs.gnuiconv }}" == "true" ]]; then
41+ # Modify formula to build using Homebrew libiconv. Usually just adding "depends_on" is enough, but since we
42+ # override "CC" to use vanilla system clang, we need to manually inject the compilation/link flags to specify
43+ # the locations.
44+ sed -i.bak '/^[[:blank:]]*def install$/i\'$'\n depends_on "libiconv"\n' ${formula}.rb
45+ sed -i.bak '/^[[:blank:]]*def install$/a\'$'\n ENV["CFLAGS"] += " -I'$(brew --prefix)$'/opt/libiconv/include"\n' ${formula}.rb
46+ sed -i.bak '/^[[:blank:]]*def install$/a\'$'\n ENV["LDFLAGS"] += " -L'$(brew --prefix)$'/opt/libiconv/lib"\n' ${formula}.rb
47+ fi
48+
3449 # Patch the official Homebrew formula to explicitly build for min deployment target and a universal binary. We
3550 # also need to explicitly use system Clang because Homebrew's bundled clang script tries to inject -march
3651 # compiler flags that will cause universal builds to fail as Clang does not like that.
37- brew cat ${formula} | \
38- sed '/^[[:blank:]]*def install$/a\'$'\n ENV["MACOSX_DEPLOYMENT_TARGET"] = "'${MACOSX_DEPLOYMENT_TARGET}$'"\n' | \
39- sed '/^[[:blank:]]*def install$/a\'$'\n ENV["CC"] = "/usr/bin/clang"\n' | \
40- sed '/^[[:blank:]]*def install$/a\'$'\n ENV["CFLAGS"] = "-arch x86_64 -arch arm64"\n' | \
41- sed '/^[[:blank:]]*def install$/a\'$'\n ENV["LDFLAGS"] = "-arch x86_64 -arch arm64"\n' >${formula}.rb
52+ sed -i.bak '/^[[:blank:]]*def install$/a\'$'\n ENV["MACOSX_DEPLOYMENT_TARGET"] = "'${MACOSX_DEPLOYMENT_TARGET}$'"\n' ${formula}.rb
53+ sed -i.bak '/^[[:blank:]]*def install$/a\'$'\n ENV["CC"] = "/usr/bin/clang"\n' ${formula}.rb
54+ sed -i.bak '/^[[:blank:]]*def install$/a\'$'\n ENV["CFLAGS"] = "-arch x86_64 -arch arm64"\n' ${formula}.rb
55+ sed -i.bak '/^[[:blank:]]*def install$/a\'$'\n ENV["LDFLAGS"] = "-arch x86_64 -arch arm64"\n' ${formula}.rb
4256
4357 # Homebrew requires formula files to be placed in taps and disallows
4458 # installing from raw paths, so we manually create a taps folder for a
8599 brew list ${formula} &>/dev/null || brew install --quiet --formula -s macvim-dev/deps/${formula}
86100
87101 # If formula was cached, this step is necessary to relink it to brew prefix (e.g. /usr/local)
88- brew unlink ${formula} && brew link ${formula}
102+ # The "-f" is there to force link keg-only formulas. Homebrew doesn't provide a command to just link in the
103+ # optional /opt/homebrew/opt/... folders, so we have to resort to doing this.
104+ brew unlink ${formula} && brew link -f ${formula}
89105 echo '::endgroup::'
90106
91107 echo '::group::Verify built version'
0 commit comments