Skip to content

Commit

Permalink
fix macos once and for all (?)
Browse files Browse the repository at this point in the history
Signed-off-by: Martmists <[email protected]>
  • Loading branch information
Martmists-GH committed Jul 19, 2024
1 parent 7e0c83f commit d6a70da
Show file tree
Hide file tree
Showing 11 changed files with 83 additions and 24 deletions.
34 changes: 19 additions & 15 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import org.gradle.kotlin.dsl.support.kotlinCompilerOptions
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinNativeCompile

plugins {
kotlin("multiplatform") version "2.0.0"
Expand Down Expand Up @@ -50,13 +52,6 @@ kotlin {
}
}

compilerOptions {
optIn = listOf(
"kotlin.experimental.ExperimentalNativeApi",
"kotlinx.cinterop.ExperimentalForeignApi",
)
}

compilations.named("main") {
val jni by cinterops.creating {
val javaHome = File(System.getProperty("java.home")!!)
Expand All @@ -78,15 +73,11 @@ kotlin {
extraOpts("-Xsource-compiler-option", "-std=c++20")
extraOpts("-Xsource-compiler-option", "-O2")

if (File("~/.konan/dependencies").exists()) {
for (file in File("~/.konan/dependencies").listFiles()!!) {
println(file)
}
}

if (target.name.startsWith("macos")) {
extraOpts("-Xsource-compiler-option", "-isystem~/.konan/dependencies/apple-llvm-20200714-macos-${if (System.getProperty("os.arch") in arrayOf("amd64", "x86_64")) "x64" else "aarch64"}-essentials/lib/clang/11.1.0/include")
extraOpts("-Xsource-compiler-option", "-isysroot/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk")
extraOpts("-Xsource-compiler-option", "-v")
extraOpts("-Xsource-compiler-option", "-isystem/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/")
extraOpts("-Xsource-compiler-option", "-isystem/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/")
extraOpts("-Xsource-compiler-option", "-isystem~/.konan/dependencies/apple-llvm-20200714-macos-${if (System.getProperty("os.arch") in arrayOf("amd64", "x86_64")) "x64" else "aarch64"}-essentials/lib/clang/11.1.0/include/")
}

val cppSource = projectDir.resolve("src/lib/cpp").listFiles().filter { it.extension == "cpp" }.map { it.absolutePath }
Expand All @@ -105,6 +96,19 @@ kotlin {
}

tasks {
withType<KotlinNativeCompile> {
compilerOptions {
if (!target.startsWith("mingw")) {
freeCompilerArgs.add("-Xbinary=sourceinfoType=libbacktrace")
}

optIn = listOf(
"kotlin.experimental.ExperimentalNativeApi",
"kotlinx.cinterop.ExperimentalForeignApi",
)
}
}

val jvmProcessResources by existing(Copy::class) {
val binaryName = if (project.hasProperty("production")) {
"releaseShared"
Expand Down
1 change: 0 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@ kotlin.code.style=official
kotlin.native.ignoreDisabledTargets=true
kotlin.mpp.enableCInteropCommonization=true
kotlin.mpp.enableCInteropCommonization.nowarn=true
kotlin.native.binary.sourceInfoType=libbacktrace

kotlin.native.cacheKind.linuxX64=none
8 changes: 8 additions & 0 deletions src/lib/public/arithmetic.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#pragma once

#ifdef __cplusplus
extern "C" {
#endif

void vec_add_vec(double* arr, double* b, int n);
void vec_add_scalar(double* arr, double b, int n);
void vec_sub_vec(double* arr, double* b, int n);
Expand All @@ -10,3 +14,7 @@ void vec_div_vec(double* arr, double* b, int n);
void vec_div_scalar(double* arr, double b, int n);
void vec_negate(double* arr, int n);
void vec_abs(double* arr, int n);

#ifdef __cplusplus
}
#endif
8 changes: 8 additions & 0 deletions src/lib/public/bitwise.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#pragma once

#ifdef __cplusplus
extern "C" {
#endif

void vec_and_vec(double* arr, double* b, int n);
void vec_and_scalar(double* arr, int b, int n);
void vec_or_vec(double* arr, double* b, int n);
Expand All @@ -11,3 +15,7 @@ void vec_lshift_vec(double* arr, double* b, int n);
void vec_lshift_scalar(double* arr, int b, int n);
void vec_rshift_vec(double* arr, double* b, int n);
void vec_rshift_scalar(double* arr, int b, int n);

#ifdef __cplusplus
}
#endif
8 changes: 8 additions & 0 deletions src/lib/public/compare.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#pragma once

#ifdef __cplusplus
extern "C" {
#endif

void vec_eq_vec(double* arr, double* b, int n);
void vec_eq_scalar(double* arr, double b, int n);
void vec_neq_vec(double* arr, double* b, int n);
Expand All @@ -8,3 +12,7 @@ void vec_lt_vec(double* arr, double* b, int n);
void vec_lt_scalar(double* arr, double b, int n);
void vec_gt_vec(double* arr, double* b, int n);
void vec_gt_scalar(double* arr, double b, int n);

#ifdef __cplusplus
}
#endif
8 changes: 0 additions & 8 deletions src/lib/public/lib.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
#pragma once

#ifdef __cplusplus
extern "C" {
#endif

#include "arithmetic.h"
#include "bitwise.h"
#include "compare.h"
Expand All @@ -12,7 +8,3 @@ extern "C" {
#include "procedure.h"
#include "trigonometry.h"
#include "vector.h"

#ifdef __cplusplus
}
#endif
8 changes: 8 additions & 0 deletions src/lib/public/math.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#pragma once

#ifdef __cplusplus
extern "C" {
#endif

void vec_sqrt(double* arr, int n);
void vec_pow(double* arr, double b, int n);
void vec_ipow(double* arr, double b, int n);
Expand All @@ -11,3 +15,7 @@ void vec_expm1(double* arr, int n);
void vec_log1p(double* arr, int n);
void vec_log2(double* arr, int n);
void vec_log10(double* arr, int n);

#ifdef __cplusplus
}
#endif
8 changes: 8 additions & 0 deletions src/lib/public/misc.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
#pragma once

#ifdef __cplusplus
extern "C" {
#endif

void vec_copy(double* arr, double* b, int n);
int get_simd_size();

#ifdef __cplusplus
}
#endif
8 changes: 8 additions & 0 deletions src/lib/public/procedure.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#pragma once

#ifdef __cplusplus
extern "C" {
#endif

double vec_sum(double* arr, int n);
double vec_min(double* arr, int n);
double vec_max(double* arr, int n);
Expand All @@ -10,3 +14,7 @@ double vec_var(double* arr, int n);
double vec_std(double* arr, int n);

void vec_coerce(double* arr, int n, double min, double max);

#ifdef __cplusplus
}
#endif
8 changes: 8 additions & 0 deletions src/lib/public/trigonometry.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#pragma once

#ifdef __cplusplus
extern "C" {
#endif

void vec_sin(double* arr, int n);
void vec_cos(double* arr, int n);
void vec_tan(double* arr, int n);
Expand All @@ -14,3 +18,7 @@ void vec_asinh(double* arr, int n);
void vec_acosh(double* arr, int n);
void vec_atanh(double* arr, int n);
void vec_hypot(double* arr, double* b, int n);

#ifdef __cplusplus
}
#endif
8 changes: 8 additions & 0 deletions src/lib/public/vector.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
#pragma once

#ifdef __cplusplus
extern "C" {
#endif

double vec_dot(double* a, double* b, int n);
void vec_matmul(double* a, double* b, double* c, int n, int m, int p);

#ifdef __cplusplus
}
#endif

0 comments on commit d6a70da

Please sign in to comment.