From 1a92f7813ba6cfefafa3a08da522936146a1d5c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Isager=20Dalsgar=C3=B0?= Date: Fri, 28 Jun 2024 15:54:55 +0200 Subject: [PATCH 1/2] Add `Bare.simulator` --- README.md | 4 ++++ include/bare/target.h | 10 +++++++++- src/bare.js | 5 +++++ src/runtime.c | 7 +++++++ 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 381bb653..089b0196 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,10 @@ The identifier of the operating system for which Bare was compiled. The possible The identifier of the processor architecture for which Bare was compiled. The possible values are `arm`, `arm64`, `ia32`, and `x64`. +#### `Bare.simulator` + +Whether or not Bare was compiled for a simulator. + #### `Bare.argv` The command line arguments passed to the process when launched. diff --git a/include/bare/target.h b/include/bare/target.h index 3ccb4d4c..882d126a 100644 --- a/include/bare/target.h +++ b/include/bare/target.h @@ -6,9 +6,11 @@ #if TARGET_OS_IOS #define BARE_PLATFORM "ios" #define BARE_PLATFORM_IOS -#else +#elif TARGET_OS_MAC #define BARE_PLATFORM "darwin" #define BARE_PLATFORM_DARWIN +#else +#error Unsupported platform #endif #elif defined(__linux__) #if defined(__ANDROID__) @@ -41,6 +43,12 @@ #error Unsupported architecture #endif +#if defined(__APPLE__) +#define BARE_SIMULATOR TARGET_OS_SIMULATOR +#else +#define BARE_SIMULATOR 0 +#endif + #define BARE_TARGET BARE_PLATFORM "-" BARE_ARCH #endif // BARE_TARGET_H diff --git a/src/bare.js b/src/bare.js index 80ab628b..d74216f8 100644 --- a/src/bare.js +++ b/src/bare.js @@ -88,6 +88,10 @@ class Bare extends EventEmitter { return bare.arch } + get simulator () { + return bare.simulator + } + get argv () { return bare.argv } @@ -195,6 +199,7 @@ class Bare extends EventEmitter { platform: this.platform, arch: this.arch, + simulator: this.simulator, argv: this.argv, pid: this.pid, exitCode: this.exitCode, diff --git a/src/runtime.c b/src/runtime.c index 2b9a1cd9..6b55667a 100644 --- a/src/runtime.c +++ b/src/runtime.c @@ -1013,6 +1013,13 @@ bare_runtime_setup (uv_loop_t *loop, bare_process_t *process, bare_runtime_t *ru V("arch", BARE_ARCH); #undef V + js_value_t *simulator; + err = js_get_boolean(env, BARE_SIMULATOR, &simulator); + assert(err == 0); + + err = js_set_named_property(env, exports, "simulator", simulator); + assert(err == 0); + js_value_t *pid; err = js_create_int32(env, uv_os_getpid(), &pid); assert(err == 0); From 507195244fbc1bf581c51657c92a4c7cbb033f33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Isager=20Dalsgar=C3=B0?= Date: Fri, 28 Jun 2024 16:06:09 +0200 Subject: [PATCH 2/2] Append `-simulator` to `BARE_TARGET` and `Addon.host` --- include/bare/target.h | 10 +++++++++- src/addon.js | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/include/bare/target.h b/include/bare/target.h index 882d126a..c56062fb 100644 --- a/include/bare/target.h +++ b/include/bare/target.h @@ -49,6 +49,14 @@ #define BARE_SIMULATOR 0 #endif -#define BARE_TARGET BARE_PLATFORM "-" BARE_ARCH +#define BARE_TARGET_SYSTEM BARE_PLATFORM "-" BARE_ARCH + +#if BARE_SIMULATOR +#define BARE_TARGET_SIMULATOR "-simulator" +#else +#define BARE_TARGET_SIMULATOR +#endif + +#define BARE_TARGET BARE_TARGET_SYSTEM BARE_TARGET_SIMULATOR #endif // BARE_TARGET_H diff --git a/src/addon.js b/src/addon.js index dc74fa7b..927eaf0a 100644 --- a/src/addon.js +++ b/src/addon.js @@ -51,7 +51,7 @@ const Addon = module.exports = exports = class Addon { } static get host () { - return `${bare.platform}-${bare.arch}` + return `${bare.platform}-${bare.arch}${bare.simulator ? '-simulator' : ''}` } static load (url) {