Skip to content

Instantly share code, notes, and snippets.

@kojix2
Created August 29, 2025 00:53
Show Gist options
  • Select an option

  • Save kojix2/c71ad7bcafe122b83eca90b263da859c to your computer and use it in GitHub Desktop.

Select an option

Save kojix2/c71ad7bcafe122b83eca90b263da859c to your computer and use it in GitHub Desktop.
# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4
PortSystem 1.0
PortGroup github 1.0
PortGroup makefile 1.0
github.setup crystal-lang crystal 1.17.1
github.tarball_from archive
revision 0
categories lang
supported_archs x86_64 arm64
license Apache-2
maintainers {makr @mohd-akram} openmaintainer
description Crystal programming language
long_description Crystal is a fast, compiled programming language with a \
Ruby-inspired syntax.
homepage https://crystal-lang.org
set llvm_version 20
depends_build path:bin/pkg-config:pkgconfig
depends_lib port:boehmgc \
port:libffi \
port:libiconv \
port:llvm-${llvm_version} \
port:pcre2
# Libraries used by the standard library; pkg-config is used when compiling user programs
depends_run port:gmp \
port:libevent \
port:libxml2 \
port:libyaml \
path:lib/libssl.dylib:openssl \
port:zlib \
path:bin/pkg-config:pkgconfig
# Bootstrap binaries use libpthread functions added in macOS 10.15
platforms {darwin >= 19}
# Use a prebuilt Crystal to build itself
set cr_ver ${version}
set cr_full_ver ${cr_ver}-1
master_sites-append https://github.com/crystal-lang/${name}/releases/download/${cr_ver}/:bootstrap
distfiles-append ${name}-${cr_full_ver}-${os.platform}-universal${extract.suffix}:bootstrap
checksums ${distname}${extract.suffix} \
rmd160 b9c37b4f3e49be14f6bfe708310d180ed782a9b0 \
sha256 f673c09577a7749d06aa56639dcf5f79bdd61ee195ab1c9b445e6f3880bd2910 \
size 3868937 \
${name}-${cr_full_ver}-${os.platform}-universal${extract.suffix} \
rmd160 032eaf538bff0e14d6463617829d1abbb07e1347 \
sha256 be1ddcc971e86a1dc978ee75bb731a0da50859e9db6841df5d27e00b2448eaae \
size 59541160
# Keep static linking behavior consistent with the current ports tree patches
patchfiles patch-static.diff
# Do NOT copy OpenBSD iconv stubs into Darwin; downstream hack removed.
# Ensure LLVM runtime can be found at run time
configure.ldflags-append -Wl,-rpath,${prefix}/libexec/llvm-${llvm_version}/lib
set llvm_config LLVM_CONFIG=llvm-config-mp-${llvm_version}
compiler.cxx_standard 2014
# Apply -Duse_libiconv consistently during all build stages
build.args release=1 interpreter=1 \
FLAGS="--no-debug -Duse_libiconv" \
CRYSTAL_CONFIG_LIBRARY_PATH=${prefix}/lib
# Also export CRYSTAL_OPTS so sub-invocations of the compiler inherit the flag
build.env ${llvm_config} \
CRYSTAL=${workpath}/${name}-${cr_full_ver}/bin/${name} \
CRYSTAL_OPTS="-Duse_libiconv"
post-build {
system -W ${worksrcpath} "${llvm_config} ${build.cmd} docs"
}
destroot.target-append install_docs
destroot.args -o docs
destroot.env ${llvm_config}
# Install a thin wrapper so end users don't need to set CRYSTAL_OPTS manually.
# The wrapper execs the real compiler from libexec and injects a default -Duse_libiconv.
post-destroot {
xinstall -d ${destroot}${prefix}/libexec/${name}
if {[file exists ${destroot}${prefix}/bin/${name}]} {
file rename -force ${destroot}${prefix}/bin/${name} \
${destroot}${prefix}/libexec/${name}/${name}-real
}
xinstall -d ${destroot}${prefix}/bin
set wrapper ${destroot}${prefix}/bin/${name}
set fd [open ${wrapper} "w"]
puts $fd "#!/bin/sh"
puts $fd ': \"${CRYSTAL_OPTS:=-Duse_libiconv}\"'
puts $fd 'export CRYSTAL_OPTS'
puts $fd "exec ${prefix}/libexec/${name}/${name}-real \"\$@\""
close $fd
file attributes ${wrapper} -permissions 0755
}
# Run tests with the same flag propagation to cover compiler re-invocations
test.run yes
test.target spec
test.args FLAGS="-Duse_libiconv"
test.env ${llvm_config} \
CRYSTAL_OPTS="-Duse_libiconv"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment