orca/src/platform/platform.h

127 lines
3.4 KiB
C
Raw Normal View History

2023-09-07 12:51:48 +00:00
/*************************************************************************
*
* Orca
* Copyright 2023 Martin Fouilleul and the Orca project contributors
* See LICENSE.txt for licensing information
*
**************************************************************************/
2023-03-05 15:05:43 +00:00
#ifndef __PLATFORM_H_
#define __PLATFORM_H_
//-----------------------------------------------------------------
// Compiler identification
//-----------------------------------------------------------------
#if defined(__clang__)
2023-08-19 12:49:23 +00:00
#define OC_COMPILER_CLANG 1
#if defined(__apple_build_version__)
#define OC_COMPILER_CLANG_APPLE 1
#elif defined(_MSC_VER)
#define OC_COMPILER_CLANG_CL 1
#endif
2023-03-05 15:05:43 +00:00
#elif defined(_MSC_VER)
2023-08-19 12:49:23 +00:00
#define OC_COMPILER_CL 1
2023-03-05 15:05:43 +00:00
#elif defined(__GNUC__)
2023-08-19 12:49:23 +00:00
#define OC_COMPILER_GCC 1
2023-03-05 15:05:43 +00:00
#else
2023-08-19 12:49:23 +00:00
#error "Can't identify compiler"
2023-03-05 15:05:43 +00:00
#endif
//-----------------------------------------------------------------
// OS identification
//-----------------------------------------------------------------
#if defined(_WIN64)
2023-08-19 12:49:23 +00:00
#define OC_PLATFORM_WINDOWS 1
2023-03-05 15:05:43 +00:00
#elif defined(_WIN32)
2023-08-19 12:49:23 +00:00
#error "Unsupported OS (32bit only version of Windows)"
2023-03-05 15:05:43 +00:00
#elif defined(__APPLE__) && defined(__MACH__)
2023-08-19 12:49:23 +00:00
#define OC_PLATFORM_MACOS 1
2023-03-05 15:05:43 +00:00
#elif defined(__gnu_linux__)
2023-08-19 12:49:23 +00:00
#define PLATFORM_LINUX 1
#elif defined(__ORCA__)
2023-08-19 12:49:23 +00:00
#define OC_PLATFORM_ORCA 1
2023-03-05 15:05:43 +00:00
#else
2023-08-19 12:49:23 +00:00
#error "Can't identify platform"
2023-03-05 15:05:43 +00:00
#endif
//-----------------------------------------------------------------
// Architecture identification
//-----------------------------------------------------------------
#if defined(OC_COMPILER_CL)
2023-08-19 12:49:23 +00:00
#if defined(_M_AMD64)
#define OC_ARCH_X64 1
#elif defined(_M_I86)
#define OC_ARCH_X86 1
#elif defined(_M_ARM64)
#define OC_ARCH_ARM64 1
#elif defined(_M_ARM)
#define OC_ARCH_ARM32 1
#else
#error "Can't identify architecture"
#endif
2023-03-05 15:05:43 +00:00
#else
2023-08-19 12:49:23 +00:00
#if defined(__x86_64__)
#define OC_ARCH_X64 1
#elif defined(__i386__)
#define OC_ARCH_X86 1
#elif defined(__arm__)
#define OC_ARCH_ARM32 1
#elif defined(__aarch64__)
#define OC_ARCH_ARM64 1
#elif defined(__ORCA__)
#define OC_ARCH_WASM32 1
#else
#error "Can't identify architecture"
#endif
2023-03-05 15:05:43 +00:00
#endif
//-----------------------------------------------------------------
// platform helper macros
//-----------------------------------------------------------------
#if defined(OC_COMPILER_CL)
2023-08-19 12:49:23 +00:00
#if defined(OC_BUILD_DLL)
#define ORCA_API __declspec(dllexport)
#else
#define ORCA_API __declspec(dllimport)
#endif
#elif defined(OC_COMPILER_GCC) || defined(OC_COMPILER_CLANG)
2023-08-19 12:49:23 +00:00
#define ORCA_API
#endif
2023-03-05 15:05:43 +00:00
#if OC_PLATFORM_ORCA
2023-08-19 12:49:23 +00:00
#define oc_thread_local // no tls (or threads) for now on wasm orca
#elif defined(OC_COMPILER_CL)
2023-08-19 12:49:23 +00:00
#define oc_thread_local __declspec(thread)
#elif defined(OC_COMPILER_GCC) || defined(OC_COMPILER_CLANG)
2023-08-19 12:49:23 +00:00
#define oc_thread_local __thread
2023-03-05 15:05:43 +00:00
#endif
#if OC_PLATFORM_ORCA
2023-08-19 12:49:23 +00:00
#define ORCA_IMPORT(f) __attribute__((import_name(#f))) f
This commit restructures the codebase to melt the milepost platform layer into the main orca codebase. Here's a list of commits squashed in this update: - move angle files to ext/ and pull includes/libs from there when needed - remove milepost/ext/angle_headers - Collapsed milepost/ext into ext - Collapse milepost/scripts into scripts/ - collapse milepost/resources into resources/. WARN: this temporarily breaks milepost's native examples - collapse milepost/test into test/ - renamed test/ to tests/ - build milepost directly into build/bin - remove unused GLES and KHR folders from sdk/ - reorganizing milepost directory tree into app, graphics, platfrom, ui, util - collapse milepost/src to src/ - Move all native examples to sketches/ and remove milepost repo - Moving sketches resources into their own shared folder separate from the runtime's resource folder - Moving all binding code to src/wasmbind - Moving all binding code to src/wasmbind - pong: fix typo in error log - fixing log parameter order - add error logs to mg_image_create_* - Fix build scripts on windows - fixed include mistake after rebase - collapsing milepost.{h|c|m} to orca.{h|c|m} and moving from sdk/ to src/ - rename orca_app.h/main.c to runtime.h/c - collapsed sdk/ to src/ - put old sdk files into their respective dirs - renamed canvas_api.json to surface_api.json - moved all stb headers in ext/stb/ - remove unused OpenSansLatinSubset.ttf font - moving cstdlib to src/wasmlibc and removing some duplicates with src/platform - move libc stdarg and string functions from platform/ to wasmlibc/ - rename wasmlibc to libc-shim to reflect non-completeness - Expose abort/assert variadic functions and macros to orca apps, and forward libc-shim abort/assert to these - move Orca API runtime implementations to runtime_xxx - fix missing math constants when including math.h with msvc in graphics_common.c - Change name of runtime to orca_runtime. When bundling on Windows, change name of runtime executable to the name of the app.
2023-08-09 11:06:32 +00:00
2023-08-19 12:49:23 +00:00
#if OC_COMPILER_CLANG
#define ORCA_EXPORT __attribute__((visibility("default")))
#else
#error "Orca apps can only be compiled with clang for now"
#endif
#endif
#ifdef __cplusplus
2023-09-07 12:51:48 +00:00
extern "C" {
#endif
2023-09-07 12:51:48 +00:00
typedef enum
{
OC_HOST_PLATFORM_MACOS,
OC_HOST_PLATFORM_WINDOWS,
} oc_host_platform;
2023-09-07 12:51:48 +00:00
ORCA_API oc_host_platform oc_get_host_platform();
#ifdef __cplusplus
} // extern "C"
#endif
2023-03-05 15:05:43 +00:00
#endif // __PLATFORM_H_