macOS by default uses clang on 10.7+, which implies libc++ (macOS < 10.7 should use libstdc++). However, the build tries to link against libstdc++ on 10.7–10.12, which fails, since the library simply is not there. And even if it was present, it should not be used with clang.
An example of the log:
https://build.macports.org/builders/ports-10.12_x86_64-builder/builds/262674
Building native extensions. This could take a while...
ERROR: Error installing /opt/local/var/macports/build/_opt_bblocal_var_buildworker_ports_build_ports_ruby_rb-unf_ext/rb31-unf_ext/work/unf_ext-0.0.9.1/unf_ext.gem:
ERROR: Failed to build gem native extension.
current directory: /opt/local/var/macports/build/_opt_bblocal_var_buildworker_ports_build_ports_ruby_rb-unf_ext/rb31-unf_ext/work/destroot/opt/local/lib/ruby3.1/gems/3.1.0/gems/unf_ext-0.0.9.1/ext/unf_ext
/opt/local/bin/ruby3.1 -I /opt/local/lib/ruby3.1/3.1.0 extconf.rb
checking for -lstdc++... *** extconf.rb failed ***