Skip to content

(Partially) fix compilation for OpenBSD #101588

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions core/variant/variant.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@
#include "core/variant/callable.h"
#include "core/variant/dictionary.h"

#include <type_traits>

class Object;
class RefCounted;

Expand Down Expand Up @@ -488,6 +490,20 @@ class Variant {
Object *get_validated_object() const;
Object *get_validated_object_with_check(bool &r_previously_freed) const;

// Template constructor for integral types.
// _should_ maintain platform compatibility _and_ fix
// OpenBSD's "ambiguous" conversion errors.
template <typename T, typename = typename std::enable_if<std::is_integral<T>::value>::type>
Variant(T p_val) {
if constexpr (std::is_same<T, bool>::value) {
type = BOOL;
_data._bool = p_val;
} else {
type = INT;
_data._int = static_cast<int64_t>(p_val);
}
}

Variant(bool p_bool);
Variant(int64_t p_int64);
Variant(int32_t p_int32);
Expand Down
3 changes: 2 additions & 1 deletion modules/camera/config.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
def can_build(env, platform):
import sys

if sys.platform.startswith("freebsd"):
# Camera module not supported on BSDs
if "bsd" in sys.platform.lower():
return False
return platform == "macos" or platform == "windows" or platform == "linuxbsd"

Expand Down
4 changes: 2 additions & 2 deletions modules/openxr/SCsub
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ elif env["platform"] == "linuxbsd":
env_openxr.AppendUnique(CPPDEFINES=["XR_USE_PLATFORM_EGL"])

# FIXME: Review what needs to be set for Android and macOS.
# FreeBSD uses non-standard getenv functions.
if not sys.platform.startswith("freebsd"):
# BSDs use non-standard getenv functions.
if "bsd" not in sys.platform.lower():
env_openxr.AppendUnique(CPPDEFINES=["HAVE_SECURE_GETENV"])
elif env["platform"] == "windows":
env_openxr.AppendUnique(CPPDEFINES=["XR_OS_WINDOWS", "NOMINMAX", "XR_USE_PLATFORM_WIN32"])
Expand Down
5 changes: 5 additions & 0 deletions modules/raycast/config.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
def can_build(env, platform):
import sys

# Supported architectures and platforms depend on the Embree library.
if env["arch"] == "arm64" and platform == "windows" and env.msvc:
return False
# OpenBSD doesn't have the required headers.
if sys.platform.startswith("openbsd"):
return False
if env["arch"] in ["x86_64", "arm64", "wasm32"]:
return True
if env["arch"] == "x86_32" and platform == "windows":
Expand Down
6 changes: 6 additions & 0 deletions platform/linuxbsd/wayland/detect_prime_egl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@

#include <stdlib.h>

#ifdef __OpenBSD__
// Map `quick_exit` to `_Exit`
// See reason in: GH-92130#issuecomment-2127135908
#define quick_exit _Exit
#endif

#include <cstring>

#include <sys/types.h>
Expand Down
1 change: 0 additions & 1 deletion platform/linuxbsd/wayland/wayland_thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
#ifdef __FreeBSD__
#include <dev/evdev/input-event-codes.h>
#else
// Assume Linux.
#include <linux/input-event-codes.h>
#endif

Expand Down
7 changes: 7 additions & 0 deletions platform/linuxbsd/x11/detect_prime_x11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@
#endif

#include <stdlib.h>

#ifdef __OpenBSD__
// Map `quick_exit` to `_Exit`
// See reason in: GH-92130#issuecomment-2127135908
#define quick_exit _Exit
#endif

#include <string.h>
#include <sys/types.h>
#include <sys/wait.h>
Expand Down
4 changes: 3 additions & 1 deletion thirdparty/jolt_physics/Jolt/Core/Core.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@
#define JPH_PLATFORM_LINUX
#elif defined(__FreeBSD__)
#define JPH_PLATFORM_FREEBSD
#elif defined(__OpenBSD__)
#define JPH_PLATFORM_OPENBSD
#elif defined(__APPLE__)
Comment on lines +88 to 90
Copy link
Member

@fire fire Jan 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At some point upstream these changes to jolt.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#include <TargetConditionals.h>
#if defined(TARGET_OS_IPHONE) && !TARGET_OS_IPHONE
Expand Down Expand Up @@ -390,7 +392,7 @@
// Creating one should only be a couple of minutes of work if you have the documentation for the platform
// (you only need to define JPH_BREAKPOINT, JPH_PLATFORM_BLUE_GET_TICKS, JPH_PLATFORM_BLUE_MUTEX*, JPH_PLATFORM_BLUE_RWLOCK* and include the right header).
#include <Jolt/Core/PlatformBlue.h>
#elif defined(JPH_PLATFORM_LINUX) || defined(JPH_PLATFORM_ANDROID) || defined(JPH_PLATFORM_MACOS) || defined(JPH_PLATFORM_IOS) || defined(JPH_PLATFORM_FREEBSD)
#elif defined(JPH_PLATFORM_LINUX) || defined(JPH_PLATFORM_ANDROID) || defined(JPH_PLATFORM_MACOS) || defined(JPH_PLATFORM_IOS) || defined(JPH_PLATFORM_FREEBSD) || defined(JPH_PLATFORM_OPENBSD)
#if defined(JPH_CPU_X86)
#define JPH_BREAKPOINT __asm volatile ("int $0x3")
#elif defined(JPH_CPU_ARM) || defined(JPH_CPU_RISCV) || defined(JPH_CPU_E2K) || defined(JPH_CPU_PPC) || defined(JPH_CPU_LOONGARCH)
Expand Down
2 changes: 1 addition & 1 deletion thirdparty/linuxbsd_headers/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ Patches in the `patches` directory should be re-applied after updates.
## X11

- Upstream: https://x.org/wiki/
- Version:
- Version:
* Xcursor: 1.2.0
* Xext: 1.3.5
* Xinerama: 1.1.4
Expand Down