From 98301502972af8c45cc37db817c6e8d0cdc27e6e Mon Sep 17 00:00:00 2001 From: forgejo-backport-action <forgejo-backport-action@noreply.codeberg.org> Date: Sat, 15 Mar 2025 16:03:19 +0000 Subject: [PATCH] [v7.0/forgejo] chore: Make Forgejo build with go1.24 (#7233) **Backport:** https://codeberg.org/forgejo/forgejo/pulls/6299 - [Go 1.24](https://groups.google.com/g/golang-announce/c/vYMfuq_XO6w) is currently out for rc1. - Using it to test unit tests and integration testing it failed horriblywith strange panics and errors, it is caused by https://github.com/golang/go/commit/ca63101df47a4467bc80faa654fc19d68e583952 and Forgejo trying to access the wrong internal data structures that have been changed in Go 1.24. - Use the new data structure for Go 1.24 and above. Co-authored-by: Gusted <postmaster@gusted.xyz> Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/7233 Reviewed-by: Gusted <gusted@noreply.codeberg.org> Co-authored-by: forgejo-backport-action <forgejo-backport-action@noreply.codeberg.org> Co-committed-by: forgejo-backport-action <forgejo-backport-action@noreply.codeberg.org> --- modules/log/groutinelabel.go | 2 ++ modules/log/groutinelabel_go1.24.go | 38 +++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 modules/log/groutinelabel_go1.24.go diff --git a/modules/log/groutinelabel.go b/modules/log/groutinelabel.go index 56d7af42da..cd5fb96d52 100644 --- a/modules/log/groutinelabel.go +++ b/modules/log/groutinelabel.go @@ -1,3 +1,5 @@ +//go:build !go1.24 + // Copyright 2022 The Gitea Authors. All rights reserved. // SPDX-License-Identifier: MIT diff --git a/modules/log/groutinelabel_go1.24.go b/modules/log/groutinelabel_go1.24.go new file mode 100644 index 0000000000..e849811bc2 --- /dev/null +++ b/modules/log/groutinelabel_go1.24.go @@ -0,0 +1,38 @@ +//go:build go1.24 + +// Copyright 2024 The Forgejo Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package log + +import "unsafe" + +//go:linkname runtime_getProfLabel runtime/pprof.runtime_getProfLabel +func runtime_getProfLabel() unsafe.Pointer //nolint + +// Struct definitions copied from: https://github.com/golang/go/blob/ca63101df47a4467bc80faa654fc19d68e583952/src/runtime/pprof/label.go +type label struct { + key string + value string +} + +type LabelSet struct { + list []label +} + +type labelMap struct { + LabelSet +} + +func getGoroutineLabels() map[string]string { + l := (*labelMap)(runtime_getProfLabel()) + if l == nil { + return nil + } + + m := make(map[string]string, len(l.list)) + for _, label := range l.list { + m[label.key] = label.value + } + return m +}