Skip to content

Commit 2c26143

Browse files
authored
Merge pull request #1626 from ychin/ci-use-homebrew-libiconv
Build MacVim binary release with GNU iconv instead of Apple iconv
2 parents 21a4147 + cdeaa64 commit 2c26143

File tree

4 files changed

+51
-8
lines changed

4 files changed

+51
-8
lines changed

.github/actions/universal-package/action.yml

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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

1212
inputs:
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
1923
runs:
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
@@ -85,7 +99,9 @@ runs:
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'

.github/workflows/macvim-buildtest.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,15 @@ jobs:
8989
xcode-select -p
9090
xcodebuild -version
9191
92+
# Set up, install, and cache GNU libiconv library to work around Apple iconv issues.
93+
94+
- name: Set up libiconv
95+
if: inputs.publish
96+
uses: ./.github/actions/universal-package
97+
with:
98+
formula: libiconv
99+
contents: opt/libiconv/lib/libiconv.a,opt/libiconv/lib/libiconv.dylib
100+
92101
# Set up, install, and cache gettext library for localization.
93102

94103
- name: Set up gettext
@@ -97,6 +106,7 @@ jobs:
97106
with:
98107
formula: gettext
99108
contents: lib/libintl.a,lib/libintl.dylib
109+
gnuiconv: true # gettext needs to match MacVim in using the same version of iconv
100110

101111
# Set up, install, and cache libsodium library for encryption.
102112

@@ -222,6 +232,9 @@ jobs:
222232
sed -i.bak -f ci/config.mk.optimized.sed src/auto/config.mk
223233
fi
224234
235+
# Use Homebrew GNU libiconv since Apple iconv has been broken since macOS 14
236+
sed -i.bak -f ci/config.mk.brew-libiconv.sed src/auto/config.mk
237+
225238
- name: Modify configure result
226239
if: inputs.publish
227240
run: |
@@ -271,6 +284,11 @@ jobs:
271284
echo 'Found external dynamic linkage!'; false
272285
fi
273286
287+
# Make sure we are not using system iconv, which has been buggy since macOS 14.
288+
if otool -L ${VIM_BIN} | grep '^\s*/usr/lib/libiconv'; then
289+
echo 'Using system iconv! We should be linking against GNU iconv instead.'; false
290+
fi
291+
274292
# Make sure that --disable-sparkle flag will properly exclude all references to Sparkle symbols. This is
275293
# necessary because we still use weak linking to Sparkle when that flag is set and so references to Sparkle
276294
# wouldn't fail the build (we just remove Sparkle.framework from the built app after the fact).

ci/config.mk.brew-libiconv.sed

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Use Homebrew GNU libiconv to work around broken Apple iconv. Use static
2+
# linking as we don't want our binary releases to pull in third-party
3+
# dependencies.
4+
#
5+
# If gettext is configured in the build, it also needs to be built against GNU
6+
# libiconv. Otherwise we would get a link error from this.
7+
/^CFLAGS[[:blank:]]*=/s/$/ -I\/opt\/homebrew\/opt\/libiconv\/include/
8+
/^LIBS[[:blank:]]*=/s/-liconv/\/opt\/homebrew\/opt\/libiconv\/lib\/libiconv.a/

src/testdir/test_macvim.vim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ func Test_macvim_options_commands_exist()
3535
call assert_true(has('clientserver'), 'Missing feature "clientserver"')
3636
call assert_true(has('clipboard'), 'Missing feature "clipboard"')
3737
call assert_true(has('clipboard_working'), 'Missing feature "clipboard_working"')
38+
call assert_true(has('iconv'), 'Missing feature "iconv"')
3839
call assert_true(has('sound'), 'Missing feature "sound"')
3940
call assert_true(has('terminal'), 'Missing feature "terminal"')
4041
call assert_true(has('xim'), 'Missing feature "xim"')

0 commit comments

Comments
 (0)