playground support (#220)
Currently, if a package imports purego in the playground even if none of the functions are called the run will fail with a complaint about unable to link in libdl.so.2. This commit circumvents this by stubbing out the dynamic linking pragmas for the go playground (//go:build faketime). This allows building and running apps in the playground that import purego but doesn't allow actually calling any of the functions. Currently, it will just die very ungracefully.
- commit
- 05c9a4c9920cb33c831a1294362f858ce11579ac
- author
- TotallyGamerJet · · 2024-03-28 02:55 UTC
- committer
- GitHub · · 2024-03-28 02:55 UTC
- parent
- 1673152
- signature
- GPG Unverified
B5690EEEBB952194The key is unknown
2 files · +21 -1
M dlfcn_nocgo_linux.go +1 -1
| @@ -1,7 +1,7 @@ | |||
| 1 | 1 | // SPDX-License-Identifier: Apache-2.0 | |
| 2 | 2 | // SPDX-FileCopyrightText: 2022 The Ebitengine Authors | |
| 3 | 3 | ||
| 4 | - | //go:build !cgo | |
| 4 | + | //go:build !cgo && !faketime | |
| 5 | 5 | ||
| 6 | 6 | package purego | |
| 7 | 7 | ||
| @@ -1,7 +1,7 @@ | |||||
| 1 | // SPDX-License-Identifier: Apache-2.0 | 1 | // SPDX-License-Identifier: Apache-2.0 | ||
| 2 | // SPDX-FileCopyrightText: 2022 The Ebitengine Authors | 2 | // SPDX-FileCopyrightText: 2022 The Ebitengine Authors | ||
| 3 | 3 | ||||
| 4 | - | //go:build !cgo | 4 | + | //go:build !cgo && !faketime |
| 5 | 5 | ||||
| 6 | package purego | 6 | package purego | ||
| 7 | 7 | ||||
A dlfcn_playground.go +20 -0
| @@ -0,0 +1,20 @@ | |||
| 1 | + | // SPDX-License-Identifier: Apache-2.0 | |
| 2 | + | // SPDX-FileCopyrightText: 2024 The Ebitengine Authors | |
| 3 | + | ||
| 4 | + | //go:build faketime | |
| 5 | + | ||
| 6 | + | package purego | |
| 7 | + | ||
| 8 | + | import _ "unsafe" | |
| 9 | + | ||
| 10 | + | // The playground doesn't support dynamic linking so just stub out the addresses | |
| 11 | + | var ( | |
| 12 | + | //go:linkname purego_dlopen purego_dlopen | |
| 13 | + | purego_dlopen uintptr | |
| 14 | + | //go:linkname purego_dlsym purego_dlsym | |
| 15 | + | purego_dlsym uintptr | |
| 16 | + | //go:linkname purego_dlerror purego_dlerror | |
| 17 | + | purego_dlerror uintptr | |
| 18 | + | //go:linkname purego_dlclose purego_dlclose | |
| 19 | + | purego_dlclose uintptr | |
| 20 | + | ) | |
| @@ -0,0 +1,20 @@ | |||||
| 1 | + | // SPDX-License-Identifier: Apache-2.0 | |||
| 2 | + | // SPDX-FileCopyrightText: 2024 The Ebitengine Authors | |||
| 3 | + | ||||
| 4 | + | //go:build faketime | |||
| 5 | + | ||||
| 6 | + | package purego | |||
| 7 | + | ||||
| 8 | + | import _ "unsafe" | |||
| 9 | + | ||||
| 10 | + | // The playground doesn't support dynamic linking so just stub out the addresses | |||
| 11 | + | var ( | |||
| 12 | + | //go:linkname purego_dlopen purego_dlopen | |||
| 13 | + | purego_dlopen uintptr | |||
| 14 | + | //go:linkname purego_dlsym purego_dlsym | |||
| 15 | + | purego_dlsym uintptr | |||
| 16 | + | //go:linkname purego_dlerror purego_dlerror | |||
| 17 | + | purego_dlerror uintptr | |||
| 18 | + | //go:linkname purego_dlclose purego_dlclose | |||
| 19 | + | purego_dlclose uintptr | |||
| 20 | + | ) | |||