From 727e24ab35858866e483dd9bb96d2f10e2928f6a Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Wed, 22 Nov 2023 13:26:01 -0600 Subject: [PATCH] fixed: darwin compilation of random_get --- runtime/build.sh | 6 ++++++ runtime/src/ort_os.h | 6 +++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/runtime/build.sh b/runtime/build.sh index a5bd95c5..a4ba6aeb 100755 --- a/runtime/build.sh +++ b/runtime/build.sh @@ -7,9 +7,15 @@ case "$(uname)" in *) suffix='dll' ;; esac +FLAGS="" +if [ "$(uname)" = "Darwin" ]; then + FLAGS="$FLAGS -framework Security" +fi + echo "Compiling onyx_runtime.$suffix" $ONYX_CC -shared -fpic -w -O2 \ -o onyx_runtime.$suffix \ -I ../shared/include -I ../compiler/include \ ./onyx_runtime.c \ + $FLAGS \ -lpthread diff --git a/runtime/src/ort_os.h b/runtime/src/ort_os.h index e6ef5e88..001ff6f3 100644 --- a/runtime/src/ort_os.h +++ b/runtime/src/ort_os.h @@ -131,10 +131,14 @@ ONYX_DEF(__lookup_env, (WASM_I32, WASM_I32, WASM_I32, WASM_I32), (WASM_I32)) { ONYX_DEF(__random_get, (WASM_PTR, WASM_I32), ()) { - #if defined(_BH_LINUX) || defined(_BH_DARWIN) + #if defined(_BH_LINUX) getrandom(ONYX_PTR(params->data[0].of.i32), params->data[1].of.i32, 0); #endif + #if defined(_BH_DARWIN) + SecRandomCopyBytes(NULL, params->data[1].of.i32, ONYX_PTR(params->data[0].of.i32)); + #endif + #ifdef _BH_WINDOWS BCRYPT_ALG_HANDLE alg; BCryptOpenAlgorithmProvider(&alg, L"SHA256", NULL, 0); -- 2.25.1