tech-pkg archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: A better method to require compiler features



Version 2 of the patch. Someone correctly pointed out that I forgot
the documentation.
Index: mk/bsd.prefs.mk
===================================================================
RCS file: /cvsroot/pkgsrc/mk/bsd.prefs.mk,v
retrieving revision 1.434
diff -u -p -u -r1.434 bsd.prefs.mk
--- mk/bsd.prefs.mk	27 Jun 2023 10:36:40 -0000	1.434
+++ mk/bsd.prefs.mk	14 Jul 2023 07:04:25 -0000
@@ -968,5 +968,13 @@ _LITTLEENDIANCPUS+=	${_ARMCPUS}
 BIGENDIANPLATFORMS=	${_BIGENDIANCPUS:S/^/*-*-/}
 LITTLEENDIANPLATFORMS=	${_LITTLEENDIANCPUS:S/^/*-*-/}
 
+#
+# Allow installing a newer C/C++ compiler to build a package
+# than what the system provides.
+#
+# Impact: allowing this can sometimes result in mismatches
+# with libstdc++ versions.
+#
+ALLOW_NEWER_COMPILER?=	yes
 
 .endif	# BSD_PKG_MK
Index: mk/compiler.mk
===================================================================
RCS file: /cvsroot/pkgsrc/mk/compiler.mk,v
retrieving revision 1.99
diff -u -p -u -r1.99 compiler.mk
--- mk/compiler.mk	23 Nov 2022 13:30:38 -0000	1.99
+++ mk/compiler.mk	14 Jul 2023 07:04:25 -0000
@@ -41,20 +41,47 @@
 #	If set to yes, fail early if the compiler.mk variables are not
 #	set correctly.
 #
+# ALLOW_NEWER_COMPILER
+#	If set to no, fail early if a package requires newer compiler
+#	features than supported by the system's compiler. If set to
+#	yes (the default), pkgsrc may attempt to build a newer compiler
+#	to use instead.
+#
 # The following variables may be set by a package:
 #
 # USE_LANGUAGES
-#	Declares the languages used in the source code of the package.
-#	This is used to determine the correct compilers to make
-#	visible to the build environment, installing them if
-#	necessary.  Flags such as -std=c++99 are also added.
+#	Declares the languages that should be made available via
+#	pkgsrc's compiler wrappers.
+#
+#	If the package assumes the compiler defaults to a specific
+#	language version, the USE_LANGUAGES variable can also be used
+#	to force the inclusion of flags such as -std=c++11. In this case,
+#	USE_CC_FEATURES/USE_CXX_FEATURES should also be set.
+#
 #	Valid values are: c, c99, gnu99, c11, gnu11, c17, gnu17, c++, c++03,
 #	gnu++03, c++0x, gnu++0x, c++11, gnu++11, c++14, gnu++14, c++17,
 #	gnu++17, c++20, gnu++20, fortran, fortran77, java, objc, obj-c++, ada.
+#
 #	The default is "c".
 #
-#       The above is partly aspirational.  As an example c++11 does
-#       not force a new enough version of gcc.
+# USE_CC_FEATURES
+#
+# 	Declares the C compiler features required by the package.
+#
+#	This is used to (optionally) install a newer compiler
+#	than provided by the system, or to skip building the package.
+#
+#	Valid values are: c11, c99, has_include.
+#
+# USE_CXX_FEATURES
+#
+# 	Declares the C++ compiler features required by the package.
+#
+#	This is used to (optionally) install a newer compiler
+#	than provided by the system, to or skip building the package.
+#
+#	Valid values are: c++11, c++14, c++17, c++20, has_include,
+#	regex, filesystem.
 #
 # The following variables are defined, and available for testing in
 # package Makefiles:
Index: mk/compiler/gcc.mk
===================================================================
RCS file: /cvsroot/pkgsrc/mk/compiler/gcc.mk,v
retrieving revision 1.253
diff -u -p -u -r1.253 gcc.mk
--- mk/compiler/gcc.mk	27 Jun 2023 10:27:21 -0000	1.253
+++ mk/compiler/gcc.mk	14 Jul 2023 07:04:25 -0000
@@ -150,6 +150,78 @@ GCC_REQD+=	2.8.0
 .  endif
 .endif
 
+#
+# Most of the time, GCC adds support for features of new C and C++
+# standards incrementally, so USE_CXX_FEATURES=	c++XX is for
+# establishing an idealistic baseline, usually based on compiler
+# versions shipped with NetBSD.
+#
+# Resources:
+# https://gcc.gnu.org/projects/cxx-status.html
+# https://gcc.gnu.org/wiki/C11Status
+# https://gcc.gnu.org/c99status.html
+#
+
+.if !empty(USE_CXX_FEATURES:Mc++20)
+# GCC 10 is chosen because it is planned to be shipped with NetBSD 10,
+# so is fairly battle-hardened with pkgsrc.
+#
+# We hope that it remains OK for most C++20 in the future...
+GCC_REQD+=	10
+.endif
+
+.if !empty(USE_CXX_FEATURES:Mc++17)
+# GCC 7 is chosen because it shipped with NetBSD 9, so is fairly
+# battle-hardened with pkgsrc.
+GCC_REQD+=	7
+.endif
+
+.if !empty(USE_CXX_FEATURES:Mc++14)
+# GCC 5 is chosen because it shipped with NetBSD 8, so is fairly
+# battle-hardened with pkgsrc.
+GCC_REQD+=	5
+.endif
+
+.if !empty(USE_CXX_FEATURES:Mc++11)
+# While gcc "technically" added experimental C++11 support earlier
+# (and there was previously a lot of cargo-culted GCC_REQD in pkgsrc
+# as a result), earlier compiler versions are not so well-tested any more.
+#
+# GCC 4.8 was the version shipped with NetBSD 7 and CentOS 7, so is fairly
+# battle-hardened with pkgsrc.
+#
+# Versions before GCC 4.7 do not accept -std=c++11.
+GCC_REQD+=	4.8
+.endif
+
+.if !empty(USE_CXX_FEATURES:Mhas_include) || \
+    !empty(USE_CC_FEATURES:Mhas_include)
+GCC_REQD+=	5
+.endif
+
+.if !empty(USE_CC_FEATURES:Mc99)
+GCC_REQD+=	3
+.endif
+
+.if !empty(USE_CC_FEATURES:Mc11)
+GCC_REQD+=	4.9
+.endif
+
+.if !empty(USE_CXX_FEATURES:Mregex)
+GCC_REQD+=	4.9
+.endif
+
+.if !empty(USE_CXX_FEATURES:Mfilesystem)
+# std::filesystem was "experimental" in gcc7 and NetBSD 9 shipped
+# GCC without the experimental C++ library headers (a break from
+# upstream).
+.  if ${OPSYS} == "NetBSD"
+GCC_REQD+=	8
+.  else
+GCC_REQD+=	7
+.  endif
+.endif
+
 # Only one compiler defined here supports Ada: lang/gcc6-aux
 # If the Ada language is requested, force lang/gcc6-aux to be selected
 .if !empty(USE_LANGUAGES:Mada)
@@ -304,6 +376,9 @@ _NEED_GCC6?=	no
 #USE_PKGSRC_GCC_RUNTIME=	yes
 #.    endif
 _NEED_GCC6=	yes
+.    if ${ALLOW_NEWER_COMPILER:tl} != "yes"
+PKG_FAIL_REASON+=	"Package requires at least gcc 6 to build"
+.    endif
 .  endif
 .endfor
 _NEED_GCC7?=	no
@@ -313,6 +388,9 @@ _NEED_GCC7?=	no
 USE_PKGSRC_GCC=		yes
 USE_PKGSRC_GCC_RUNTIME=	yes
 .    endif
+.    if ${ALLOW_NEWER_COMPILER:tl} != "yes"
+PKG_FAIL_REASON+=	"Package requires at least gcc 7 to build"
+.    endif
 _NEED_GCC7=	yes
 .  endif
 .endfor
@@ -323,6 +401,9 @@ _NEED_GCC8?=	no
 USE_PKGSRC_GCC=		yes
 USE_PKGSRC_GCC_RUNTIME=	yes
 .    endif
+.    if ${ALLOW_NEWER_COMPILER:tl} != "yes"
+PKG_FAIL_REASON+=	"Package requires at least gcc 8 to build"
+.    endif
 _NEED_GCC8=	yes
 .  endif
 .endfor
@@ -333,6 +414,9 @@ _NEED_GCC9?=	no
 USE_PKGSRC_GCC=		yes
 USE_PKGSRC_GCC_RUNTIME=	yes
 .    endif
+.    if ${ALLOW_NEWER_COMPILER:tl} != "yes"
+PKG_FAIL_REASON+=	"Package requires at least gcc 9 to build"
+.    endif
 _NEED_GCC9=	yes
 .  endif
 .endfor
@@ -343,18 +427,27 @@ _NEED_GCC10?=	no
 USE_PKGSRC_GCC=		yes
 USE_PKGSRC_GCC_RUNTIME=	yes
 .    endif
+.    if ${ALLOW_NEWER_COMPILER:tl} != "yes"
+PKG_FAIL_REASON+=	"Package requires at least gcc 10 to build"
+.    endif
 _NEED_GCC10=	yes
 .  endif
 .endfor
 _NEED_GCC12?=	no
 .for _pattern_ in ${_GCC12_PATTERNS}
 .  if !empty(_GCC_REQD:M${_pattern_})
+.    if ${ALLOW_NEWER_COMPILER:tl} != "yes"
+PKG_FAIL_REASON+=	"Package requires at least gcc 12 to build"
+.    endif
 _NEED_GCC12=	yes
 .  endif
 .endfor
 _NEED_GCC13?=	no
 .for _pattern_ in ${_GCC13_PATTERNS}
 .  if !empty(_GCC_REQD:M${_pattern_})
+.    if ${ALLOW_NEWER_COMPILER:tl} != "yes"
+PKG_FAIL_REASON+=	"Package requires at least gcc 13 to build"
+.    endif
 _NEED_GCC13=	yes
 .  endif
 .endfor
Index: doc/guide/files/fixes.xml
===================================================================
RCS file: /cvsroot/pkgsrc/doc/guide/files/fixes.xml,v
retrieving revision 1.185
diff -u -p -u -r1.185 fixes.xml
--- doc/guide/files/fixes.xml	13 Jul 2023 13:14:41 -0000	1.185
+++ doc/guide/files/fixes.xml	14 Jul 2023 07:04:25 -0000
@@ -1428,7 +1428,8 @@ MESON_ARGS+=	-Dx11=false
     is written in C and will hide all other compilers (via the wrapper
     framework, see <xref linkend="buildlink" />).</para>
 
-    <para>To declare which language's compiler a package needs, set
+    <para>To declare which languages should be made available through
+    pkgsrc's compiler wrappers, use 
     the <varname>USE_LANGUAGES</varname> variable. Allowed values
     currently are:
 <programlisting>
@@ -1439,7 +1440,27 @@ fortran77, java, objc, obj-c++, and ada.
     (and any combination).  The default is
     <quote>c</quote>.  Packages using GNU configure scripts, even if
     written in C++, usually need a C compiler for the configure
-    phase.</para>
+    phase.
+    Language variants like <literal>c++11</literal>
+    can be specified if the package does not explicitly set
+    <literal>-std=...</literal> when compiling (i.e. the package
+    assumes the compiler defaults to C++11 or some other standard).
+    This is a common bug in upstream build systems.</para>
+
+    <para>To declare which features a package requies from the
+    compiler, set either <varname>USE_CC_FEATURES</varname>
+    or <varname>USE_CXX_FEATURES</varname>. Allowed values for
+    <varname>USE_CC_FEATURES</varname> are currently:
+<programlisting>
+c11, c99, has_include
+</programlisting>
+    Allowed values for <varname>USE_CXX_FEATURES</varname> are
+    currently:
+<programlisting>
+c++11, c++14, c++17, c++20, has_include, regex, filesystem
+</programlisting>
+    .</para>
+    </para>
   </sect2>
 
   <sect2 id="java-programming-language">


Home | Main Index | Thread Index | Old Index