Skip to content

Commit

Permalink
ruby34: new port, version 3.4.1
Browse files Browse the repository at this point in the history
See:
https://www.ruby-lang.org/en/news/2024/12/25/ruby-3-4-1-released/

The upstream code already incorporates the fixes from v3.2.6, but not
the fixes from 3.2.6_1, which are included in the patchfile here.

The legacy-support threshold is updated for clock_gettime() support.

The upstream linker warning suppression hackery was changed in v3.4 to
somthing badly broken.  This reinstates the 3.3 version, which is
needed for builds to work with certain library mismatches.

Ruby 3.4 does not build with Xcode 10.1 clang 425 on 10.7, so this
blacklists clangs < 500 (in addition to the preexisting blacklisting
of clang 900).

Also cleans up a couple of long-standing Portfile issues.

TESTED:
Built successfully on OSX 10.4-10.5 ppc, 10.4-10.6 i386, 10.5-12.x
x86_64, and 11.x-15.x arm64.  Included all variants compatible with
available dependencies on the respective platforms.
  • Loading branch information
fhgwright authored Jan 13, 2025
1 parent 74156c3 commit 8b34ce8
Show file tree
Hide file tree
Showing 4 changed files with 338 additions and 0 deletions.
228 changes: 228 additions & 0 deletions lang/ruby34/Portfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,228 @@
# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:et:sw=4:ts=4:sts=4

PortSystem 1.0
PortGroup select 1.0
PortGroup openssl 1.0
PortGroup compiler_blacklist_versions 1.0
PortGroup legacysupport 1.1

# clock_gettime()
legacysupport.newest_darwin_requires_legacy 15

# Version updates should start by updating the fork noted below
# (or equivalent), verifying the propriety of the patches for the new version,
# and rederiving the patchfile from there.
#
# Also note that this port runs on all OS/CPU combinations.
# This property should be preserved.

set ruby_ver 3.4
set ruby_patch 1
set ruby_ver_nodot [string map {. {}} ${ruby_ver}]
name ruby${ruby_ver_nodot}
version ${ruby_ver}.${ruby_patch}
revision 0

categories lang ruby
maintainers {kimuraw @kimuraw} \
{fwright.net:fw @fhgwright} \
openmaintainer

description Powerful and clean object-oriented scripting language
long_description Ruby is the interpreted scripting language for quick \
and easy object-oriented programming. It has many \
features to process text files and to do system \
management tasks (as in Perl). It is simple, \
straightforward, extensible, and portable.

homepage https://www.ruby-lang.org/
license {Ruby BSD}

master_sites ruby:${ruby_ver}
distname ruby-${version}
dist_subdir ruby${ruby_ver_nodot}

checksums rmd160 3f699d5a37ebf715803c7bd2994a092be154c39a \
sha256 3d385e5d22d368b064c817a13ed8e3cc3f71a7705d7ed1bae78013c33aa7c87f \
size 23152739

# Universal builds don't currently work, including via the approach used
# in ruby30.
universal_variant no

# ruby/openssl since ruby-3.2 supports openssl-3
openssl.branch 3

depends_lib port:zlib \
port:libyaml \
port:libffi \
port:gdbm
depends_run port:ruby_select
depends_build port:pkgconfig port:cctools
depends_skip_archcheck pkgconfig

select.group ruby
select.file ${filespath}/ruby${ruby_ver_nodot}

# Patches derived from MacPorts-enhanced GitHub fork at
# github.com/fhgwright/ruby

# patch-sources.diff: fixes for various issues.
#
# This diff is from v3_4_1 vs. macports-3_4_1.
#
patchfiles-append patch-sources.diff

# patch-generated.diff: additional patches to generated files, which don't
# exist in the upstream git sources, and which must be patched after the
# source patches so that make doesn't regard them as outdated.
# At present, the only patched generated file is 'configure', to avoid
# the need to rerun autoconf, whose output has reproducibility issues.
#
# This diff is from tarball-3_4_1 vs. macports-tarball-3_4_1.
#
patchfiles-append patch-generated.diff

#-------------------------------------------------------------------------------
# Fix compilation on buildbots for 10.12 and earlier.
# Issue: 62183: error: use of undeclared identifier 'fmt'; did you mean 'fma'?
#
# This issue only appears in Xcode clang 9 (clang 900), not MacPorts clang 9
# (clang 901), so the blacklisting can be narrow.
#-------------------------------------------------------------------------------
compiler.blacklist-append { clang >= 900 < 901 }

# Ruby3.4 doesn't build with Xcode clang 425 on 10.7
compiler.blacklist-append { clang < 500 }

# Ensure that the correct dsymutil is used.
if { [string match macports-clang-* ${configure.compiler}] } {
# clang-mp-14 => dsymutil-mp-14; fix POSTLINK
configure.env-append dsymutil=[string map {clang dsymutil} ${configure.cc}]
}

compiler.thread_local_storage yes

# At least one version of clang doesn't offer cstdbool (introduced in C++11)
# with -stdlib=libstc++ but still reports as C++14. This causes an include
# failure in include/ruby/internal/stdbool.h when built as C++. Setting the
# standard to C++03 removes the expectation that cstdbool is available.
#
# This has only been observed when building for 10.5, and in fact, ruby
# makes very little use of C++, and would probably be fine if this were
# unconditional. Nevertheless, we limit it to the failing case.
#
if {[string match *clang* ${configure.compiler}] \
&& ${configure.cxx_stdlib} eq "libstdc++"} {
configure.cxxflags-append -std=c++03
}

configure.args --enable-shared \
--enable-install-static-library \
--disable-install-doc \
--mandir="${prefix}/share/man" \
--enable-pthread \
--disable-yjit \
--disable-rjit \
--without-gmp \
--enable-mkmf-verbose \
--with-opt-dir="${prefix}" \
--program-suffix=${ruby_ver} \
--with-rubyhdrdir=${prefix}/include/ruby-${version} \
--with-rubylibprefix="${prefix}/lib/ruby${ruby_ver}" \
--with-openssl-dir=[openssl::install_area] \
--without-baseruby
# prefer Apple cctools to GNU binutils, build with binutils may fail.
configure.args-append AR=${prefix}/bin/ar RANLIB=${prefix}/bin/ranlib

# Add the architecture flag as required
if {[info exists build_arch] && ${build_arch} != ""} {
configure.args-append "--with-arch=${build_arch}"
}

post-patch {
# Ensure that generated files have clearly later mtimes than sources,
# to avoid gratuitous rebuilds by make.
# This is already nominally true based on the patching order, but
# one-second resolution on timestamps may cover it up.
#
# The list of files here should match the list of files patched by
# patch-generated.diff.
#
# Increment the mtime(s) by one second.
foreach genfile [list configure] {
set genfull ${worksrcpath}/${genfile}
file mtime ${genfull} [expr [file mtime ${genfull}] + 1]
}
}

post-destroot {
foreach type {site vendor} {
set libdir ${destroot}${prefix}/lib/ruby${ruby_ver}/${type}_ruby/${version}
xinstall -m 0755 -d ${libdir}
foreach subdir [exec find ${libdir} -type d -empty] {
destroot.keepdirs-append ${subdir}
}
}

# install destination of commands from port:rb34*
xinstall -m 0755 -d ${destroot}${prefix}/libexec/ruby${ruby_ver}
destroot.keepdirs-append ${destroot}${prefix}/libexec/ruby${ruby_ver}
}

notes-append "
To make this the default Ruby (i.e., the version run by\
the 'ruby', 'gem' or 'bundle' commands), run:
sudo port select --set ruby $name
"

variant doc description "Install rdoc indexes and C API documents" {
configure.args-delete --disable-install-doc
}

variant gmp description "use gmp" {
configure.args-delete --without-gmp
depends_lib-append port:gmp
}

variant jemalloc description "use jemalloc" {
configure.args-replace --without-jemalloc --with-jemalloc
depends_lib-append port:jemalloc
}

variant yjit description "enable YJIT (requires rust)" {
configure.args-replace --disable-yjit --enable-yjit
depends_build-append port:rust
}
# yjit supports x86_64 or arm64
if {${os.platform} eq "darwin" && ${os.major} >= 19 \
&& [info exists build_arch]} {
if {$build_arch in [list x86_64 arm64]} {
default_variants-append +yjit
}
}

variant relative description "Enable relative loading of libraries to allow for relocation of binaries." {
#enable relative loading
configure.args-append --enable-load-relative
}

# legacy systems support
platform darwin {
if {${os.major} < 11} {
depends_build-append port:gmake
build.cmd ${prefix}/bin/gmake
configure.args-append --disable-dtrace
}

if {${os.major} == 8} {
configure.cppflags-append -DCPU_SUBTYPE_MASK=0xff000000
}
}

test.run yes
test.target check

livecheck.type regex
livecheck.url https://cache.ruby-lang.org/pub/ruby/${ruby_ver}/
livecheck.regex ruby-(3\\.4\\.\\d+)[quotemeta ${extract.suffix}]
12 changes: 12 additions & 0 deletions lang/ruby34/files/patch-generated.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
--- configure.orig 2024-12-24 23:43:22.000000000 -0800
+++ configure 2025-01-09 14:37:14.000000000 -0800
@@ -8505,7 +8505,8 @@ printf %s "checking for $CC linker warni
>/dev/null
then :

- suppress_ld_waring=yes
+ CC_WRAPPER=`cd -P "${tooldir}" && pwd`/darwin-cc
+ CC="$CC_WRAPPER $CC"

fi
rm -fr conftest*
78 changes: 78 additions & 0 deletions lang/ruby34/files/patch-sources.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
--- configure.ac.orig 2024-12-24 23:43:20.000000000 -0800
+++ configure.ac 2025-01-09 14:37:13.000000000 -0800
@@ -446,7 +446,8 @@ AS_CASE(["$build_os"],
-e '^ld: warning: text-based stub file' \
-e '^ld: warning: -multiply_defined is obsolete' \
>/dev/null], [
- suppress_ld_waring=yes
+ CC_WRAPPER=`cd -P "${tooldir}" && pwd`/darwin-cc
+ CC="$CC_WRAPPER $CC"
])
rm -fr conftest*
test $suppress_ld_waring = yes && warnflags="${warnflags:+${warnflags} }-Wl,-w"
--- file.c.orig 2024-12-24 23:43:20.000000000 -0800
+++ file.c 2025-01-09 14:37:13.000000000 -0800
@@ -275,9 +275,27 @@ static CFMutableStringRef
mutable_CFString_new(CFStringRef *s, const char *ptr, long len)
{
const CFAllocatorRef alloc = kCFAllocatorDefault;
+
+/*
+ * The 'NoCopy' version of CFStringCreateWithBytes didn't appear until
+ * 10.5, though the original CFStringCreateWithBytes has been available
+ * since 10.0. Hence, we need to use CFStringCreateWithBytes on OS versions
+ * earlier than 10.5.
+ *
+ * There's probably no significant benefit to using the 'NoCopy' version
+ * in this context, so making that substitution unconditionally would
+ * probably be fine (and simpler), but by the principle of least change,
+ * we limit the substitution to earlier OS versions (i.e., 10.4).
+ */
+# if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 1050
*s = CFStringCreateWithBytesNoCopy(alloc, (const UInt8 *)ptr, len,
kCFStringEncodingUTF8, FALSE,
kCFAllocatorNull);
+# else /* 10.4 */
+ *s = CFStringCreateWithBytes(alloc, (const UInt8 *)ptr, len,
+ kCFStringEncodingUTF8, FALSE);
+# endif /* 10.4 */
+
return CFStringCreateMutableCopy(alloc, len, *s);
}

--- lib/bundler/gem_helper.rb.orig 2024-12-24 23:43:20.000000000 -0800
+++ lib/bundler/gem_helper.rb 2025-01-09 14:37:13.000000000 -0800
@@ -231,7 +231,7 @@ module Bundler
end

def gem_command
- ENV["GEM_COMMAND"]&.shellsplit || ["gem"]
+ ENV["GEM_COMMAND"]&.shellsplit || ["gem3.4"]
end
end
end
--- thread_pthread.c.orig 2024-12-24 23:43:20.000000000 -0800
+++ thread_pthread.c 2025-01-09 14:37:13.000000000 -0800
@@ -43,6 +43,22 @@

#if defined __APPLE__
# include <AvailabilityMacros.h>
+
+/*
+ * This code is built with _XOPEN_SOURCE=1 and _DARWIN_C_SOURCE=1, which
+ * blocks the declaration of pthread_mach_thread_np() in pthread.h on 10.4.
+ * Overriding this by also defining _DARWIN_C_SOURCE didn't become available
+ * until 10.5. The missing prototype went unnoticed until gcc14 started
+ * calling it an error.
+ *
+ * Note that many uses of Apple-specific functions with these settings are
+ * illegal (on 10.4), but for now we just fix the immediate problem by
+ * duplicating the missing declaration. There's no need to make this
+ * conditional, since redundant prototypes are legal.
+ */
+#include <mach/port.h>
+mach_port_t pthread_mach_thread_np(pthread_t);
+
#endif

#if defined(HAVE_SYS_EVENTFD_H) && defined(HAVE_EVENTFD)
20 changes: 20 additions & 0 deletions lang/ruby34/files/ruby34
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
bin/erb3.4
bin/gem3.4
bin/irb3.4
bin/rake3.4
bin/rdoc3.4
bin/ri3.4
bin/ruby3.4
-
share/man/man1/erb3.4.1.gz
share/man/man1/irb3.4.1.gz
-
share/man/man1/ri3.4.1.gz
share/man/man1/ruby3.4.1.gz
bin/bundle3.4
bin/bundler3.4
-
bin/racc3.4
bin/typeprof3.4
bin/rbs3.4
bin/rdbg3.4

0 comments on commit 8b34ce8

Please sign in to comment.