public inbox for gentoo-dev@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-dev] [PATCH] toolchain-funcs.eclass: Add tc-has-64bit-time_t
@ 2024-06-13 15:23 Michał Górny
  2024-06-13 16:44 ` James Le Cuirot
  2024-06-13 16:48 ` Ulrich Mueller
  0 siblings, 2 replies; 4+ messages in thread
From: Michał Górny @ 2024-06-13 15:23 UTC (permalink / raw
  To: gentoo-dev; +Cc: Michał Górny

Add a helper function to check whether time_t is 64-bit.  This could
be used e.g. to deselect tests that rely on timestamps exceeding Y2k38.
It is meant to be more future-proof than hardcoding a list of 32-bit
architectures, given the necessity of switching to 64-bit time_t
in the future.

Signed-off-by: Michał Górny <mgorny@gentoo.org>
---
 eclass/toolchain-funcs.eclass | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

Pull-Request: https://github.com/gentoo/gentoo/pull/37142

diff --git a/eclass/toolchain-funcs.eclass b/eclass/toolchain-funcs.eclass
index cde84e6f34c8..3e20e956e9c2 100644
--- a/eclass/toolchain-funcs.eclass
+++ b/eclass/toolchain-funcs.eclass
@@ -1,4 +1,4 @@
-# Copyright 2002-2023 Gentoo Authors
+# Copyright 2002-2024 Gentoo Authors
 # Distributed under the terms of the GNU General Public License v2
 
 # @ECLASS: toolchain-funcs.eclass
@@ -1251,4 +1251,14 @@ tc-is-lto() {
 	return 1
 }
 
+# @FUNCTION: tc-has-64bit-time_t
+# @RETURN: Shell true if time_t is at least 64 bits long, false otherwise
+tc-has-64bit-time_t() {
+	"$(tc-getCC)" ${CFLAGS} ${CPPFLAGS} -c -x c - -o /dev/null <<-EOF &>/dev/null
+		#include <sys/types.h>
+		int test[sizeof(time_t) >= 8 ? 1 : -1];
+	EOF
+	return $?
+}
+
 fi
-- 
2.45.2



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [gentoo-dev] [PATCH] toolchain-funcs.eclass: Add tc-has-64bit-time_t
  2024-06-13 15:23 [gentoo-dev] [PATCH] toolchain-funcs.eclass: Add tc-has-64bit-time_t Michał Górny
@ 2024-06-13 16:44 ` James Le Cuirot
  2024-06-13 17:06   ` Michał Górny
  2024-06-13 16:48 ` Ulrich Mueller
  1 sibling, 1 reply; 4+ messages in thread
From: James Le Cuirot @ 2024-06-13 16:44 UTC (permalink / raw
  To: gentoo-dev

[-- Attachment #1: Type: text/plain, Size: 1663 bytes --]

On Thu, 2024-06-13 at 17:23 +0200, Michał Górny wrote:
> Add a helper function to check whether time_t is 64-bit.  This could
> be used e.g. to deselect tests that rely on timestamps exceeding Y2k38.
> It is meant to be more future-proof than hardcoding a list of 32-bit
> architectures, given the necessity of switching to 64-bit time_t
> in the future.
> 
> Signed-off-by: Michał Górny <mgorny@gentoo.org>
> ---
>  eclass/toolchain-funcs.eclass | 12 +++++++++++-
>  1 file changed, 11 insertions(+), 1 deletion(-)
> 
> Pull-Request: https://github.com/gentoo/gentoo/pull/37142
> 
> diff --git a/eclass/toolchain-funcs.eclass b/eclass/toolchain-funcs.eclass
> index cde84e6f34c8..3e20e956e9c2 100644
> --- a/eclass/toolchain-funcs.eclass
> +++ b/eclass/toolchain-funcs.eclass
> @@ -1,4 +1,4 @@
> -# Copyright 2002-2023 Gentoo Authors
> +# Copyright 2002-2024 Gentoo Authors
>  # Distributed under the terms of the GNU General Public License v2
>  
>  # @ECLASS: toolchain-funcs.eclass
> @@ -1251,4 +1251,14 @@ tc-is-lto() {
>  	return 1
>  }
>  
> +# @FUNCTION: tc-has-64bit-time_t
> +# @RETURN: Shell true if time_t is at least 64 bits long, false otherwise
> +tc-has-64bit-time_t() {
> +	"$(tc-getCC)" ${CFLAGS} ${CPPFLAGS} -c -x c - -o /dev/null <<-EOF &>/dev/null
> +		#include <sys/types.h>
> +		int test[sizeof(time_t) >= 8 ? 1 : -1];
> +	EOF
> +	return $?
> +}
> +
>  fi

I take it this can't be done with tc-cpp-is-true because you need more than
just the preprocessor?

Please don't quote $(tc-getCC), CC can have additional arguments in some
cases. We don't quote $(tc-getTARGET_CPP) in tc-cpp-is-true.

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 858 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [gentoo-dev] [PATCH] toolchain-funcs.eclass: Add tc-has-64bit-time_t
  2024-06-13 15:23 [gentoo-dev] [PATCH] toolchain-funcs.eclass: Add tc-has-64bit-time_t Michał Górny
  2024-06-13 16:44 ` James Le Cuirot
@ 2024-06-13 16:48 ` Ulrich Mueller
  1 sibling, 0 replies; 4+ messages in thread
From: Ulrich Mueller @ 2024-06-13 16:48 UTC (permalink / raw
  To: Michał Górny; +Cc: gentoo-dev

[-- Attachment #1: Type: text/plain, Size: 279 bytes --]

>>>>> On Thu, 13 Jun 2024, Michał Górny wrote:

> +	"$(tc-getCC)" ${CFLAGS} ${CPPFLAGS} -c -x c - -o /dev/null <<-EOF &>/dev/null

IIUC, tc-getCC can return values like "x86_64-pc-linux-gnu-gcc -m32
-mfpmath=sse", so probably you want to lose the quotes there.

Ulrich

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 507 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [gentoo-dev] [PATCH] toolchain-funcs.eclass: Add tc-has-64bit-time_t
  2024-06-13 16:44 ` James Le Cuirot
@ 2024-06-13 17:06   ` Michał Górny
  0 siblings, 0 replies; 4+ messages in thread
From: Michał Górny @ 2024-06-13 17:06 UTC (permalink / raw
  To: gentoo-dev

[-- Attachment #1: Type: text/plain, Size: 1867 bytes --]

On Thu, 2024-06-13 at 17:44 +0100, James Le Cuirot wrote:
> On Thu, 2024-06-13 at 17:23 +0200, Michał Górny wrote:
> > Add a helper function to check whether time_t is 64-bit.  This could
> > be used e.g. to deselect tests that rely on timestamps exceeding Y2k38.
> > It is meant to be more future-proof than hardcoding a list of 32-bit
> > architectures, given the necessity of switching to 64-bit time_t
> > in the future.
> > 
> > Signed-off-by: Michał Górny <mgorny@gentoo.org>
> > ---
> >  eclass/toolchain-funcs.eclass | 12 +++++++++++-
> >  1 file changed, 11 insertions(+), 1 deletion(-)
> > 
> > Pull-Request: https://github.com/gentoo/gentoo/pull/37142
> > 
> > diff --git a/eclass/toolchain-funcs.eclass b/eclass/toolchain-funcs.eclass
> > index cde84e6f34c8..3e20e956e9c2 100644
> > --- a/eclass/toolchain-funcs.eclass
> > +++ b/eclass/toolchain-funcs.eclass
> > @@ -1,4 +1,4 @@
> > -# Copyright 2002-2023 Gentoo Authors
> > +# Copyright 2002-2024 Gentoo Authors
> >  # Distributed under the terms of the GNU General Public License v2
> >  
> >  # @ECLASS: toolchain-funcs.eclass
> > @@ -1251,4 +1251,14 @@ tc-is-lto() {
> >  	return 1
> >  }
> >  
> > +# @FUNCTION: tc-has-64bit-time_t
> > +# @RETURN: Shell true if time_t is at least 64 bits long, false otherwise
> > +tc-has-64bit-time_t() {
> > +	"$(tc-getCC)" ${CFLAGS} ${CPPFLAGS} -c -x c - -o /dev/null <<-EOF &>/dev/null
> > +		#include <sys/types.h>
> > +		int test[sizeof(time_t) >= 8 ? 1 : -1];
> > +	EOF
> > +	return $?
> > +}
> > +
> >  fi
> 
> I take it this can't be done with tc-cpp-is-true because you need more than
> just the preprocessor?
> 
> Please don't quote $(tc-getCC), CC can have additional arguments in some
> cases. We don't quote $(tc-getTARGET_CPP) in tc-cpp-is-true.

Right, thx.

-- 
Best regards,
Michał Górny


[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 512 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-06-13 17:06 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-13 15:23 [gentoo-dev] [PATCH] toolchain-funcs.eclass: Add tc-has-64bit-time_t Michał Górny
2024-06-13 16:44 ` James Le Cuirot
2024-06-13 17:06   ` Michał Górny
2024-06-13 16:48 ` Ulrich Mueller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox