Skip to content

Commit

Permalink
Forces use of libiconv when compiling for macOS
Browse files Browse the repository at this point in the history
Detect if macOS is the compilation target and forces libiconv usage
instead of macOS built-in iconv as is broken since 2023.

Ref:
* crystal-lang/crystal#14651 (comment)
  • Loading branch information
luislavena committed Aug 22, 2024
1 parent ff43afa commit 52b41fb
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions scripts/xbuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,18 @@ object_file="${TMPDIR:-/tmp}/$(basename "${filename%.*}-$target_platform.o")"

# capture output from build
pkg_config_libdir="$multiarch_root/$target_platform/lib/pkgconfig"
build_output=$(PKG_CONFIG_LIBDIR="$pkg_config_libdir" crystal build --release --no-debug --static --cross-compile --target "$target_platform" "$filename" -o "$object_file")
build_cmd="crystal build --release --no-debug --static --cross-compile --target $target_platform"

case $target_platform in
# forces usage of libiconv for macOS
# Ref: https://github.com/crystal-lang/crystal/pull/14651#issuecomment-2159357235
*-apple-darwin)
build_cmd="${build_cmd} -Duse_libiconv"
;;
*)
;;
esac
build_output=$(PKG_CONFIG_LIBDIR="$pkg_config_libdir" $build_cmd "$filename" -o "$object_file")

# check if build succeeded before proceeding
if [ $? -ne 0 ]; then
Expand All @@ -68,8 +79,8 @@ if [[ "$build_output" =~ "lssl" ]]; then
libs="${libs/crypto/ssl -lcrypto}"
fi

# when targeting `musl`, also include `unwind` as library
case $target_platform in
# when targeting `musl`, also include `unwind` as library
*-linux-musl)
libs="$libs -lunwind"
;;
Expand Down

0 comments on commit 52b41fb

Please sign in to comment.