@@ -2,9 +2,51 @@ sourceSets.main.java.srcDirs = ["src"]
22sourceSets. test. java. srcDirs = [" test" ]
33sourceSets. test. resources. srcDirs = [" test/resources" ]
44
5+ configurations {
6+ extraLibs
7+ }
8+
59dependencies {
610 testImplementation libraries. junit
711 testImplementation aproj(" :natives:natives-desktop" )
12+ testImplementation files(" unsafe/unsafe.jar" )
13+ // file generated from UnsafeBuffers.java
14+ compileOnly files(" unsafe/unsafe.jar" )
15+ extraLibs files(" unsafe/unsafe.jar" )
16+ }
17+
18+ jar {
19+ from{
20+ configurations. extraLibs. collect{ it. isDirectory() ? it : zipTree(it) }
21+ }
22+ }
23+
24+ // now, you may ask: why don't I make this a new module? why do I include JARs in the repository? why don't I make this a separate build step?
25+ // the reason is: I don't want to deal with compiler arguments, --add-opens, or whatever else Java throws at you these days
26+ // this just works and I don't want to touch it, it's a dependency that has already been compiled and won't explode as much as source compilation might
27+ // "why are you using unsafe, why aren't you using the new memory access APIs?" because they don't work on Android or iOS
28+ // and no, I cannot work with buffer put() because of Java's idiotic design making it so that you need to put()/limit()/position() to write memory, breaking multithreading
29+ // this makes Unsafe the only viable option - any "state independent" methods are Java-16 specific, and iOS/Android don't support those
30+
31+ tasks. register(" compileBuffersUnsafe" , Exec ){
32+ workingDir " unsafe"
33+ commandLine " javac --target 8 --source 8 -d . UnsafeBuffers.java" . split(" " )
34+ }
35+
36+ tasks. register(" compileBuffersSafe" , Exec ){
37+ workingDir " unsafe"
38+ commandLine " javac --target 16 --source 16 -d . Java16Buffers.java" . split(" " )
39+ }
40+
41+ tasks. register(" recompileUnsafe" , Exec ){
42+ dependsOn " compileBuffersUnsafe" , " compileBuffersSafe"
43+ workingDir " unsafe"
44+ commandLine " jar cvf unsafe.jar arc" . split(" " )
45+ doLast{
46+ delete{
47+ delete " unsafe/arc"
48+ }
49+ }
850}
951
1052test {
@@ -21,12 +63,13 @@ file("jni").mkdir()
2163jnigen {
2264 sharedLibName = " arc"
2365 temporaryDir = file(" build/target/native" ). absolutePath
24- libsDir = file( " libs" ) . absolutePath
66+ libsDir = " libs"
2567
2668 all{
2769 headerDirs + = [" soloud/include" ]
2870 cppIncludes = [" *.cpp" , " soloud/src/core/**" , " soloud/src/audiosource/wav/**" , " soloud/src/filter/**" ]
2971 cIncludes = [" *.c" , " soloud/src/core/**" , " soloud/src/audiosource/wav/**" , " soloud/src/filter/**" ]
72+ cppFlags = " -DSOLOUD_MAX_VOICE_COUNT=100 " + cppFlags
3073 }
3174 add(Linux , x64){
3275 cppIncludes + = [" soloud/src/backend/miniaudio/*.cpp" ]
@@ -47,65 +90,60 @@ jnigen{
4790 cppFlags = " -DWITH_OPENSLES " + cppFlags
4891 }
4992 add(MacOsX , x64){
50- cppIncludes + = [" soloud/src/backend/coreaudio/*.cpp " ]
93+ cppIncludes + = [" soloud/src/backend/coreaudio/*.mm " ]
5194 cppFlags = " -std=c++11 -DWITH_COREAUDIO " + cppFlags
5295 libraries + = " -Wl,-framework,CoreAudio -Wl,-framework,AudioToolbox"
5396 }
5497 add(MacOsX , x64, ARM ){
55- cppIncludes + = [" soloud/src/backend/coreaudio/*.cpp " ]
98+ cppIncludes + = [" soloud/src/backend/coreaudio/*.mm " ]
5699 cppFlags = " -std=c++11 -DWITH_COREAUDIO " + cppFlags. replace(" x86_64" , " arm64" )
57100 cFlags = cFlags. replace(" x86_64" , " arm64" )
58101 libraries + = " -Wl,-framework,CoreAudio -Wl,-framework,AudioToolbox"
59102 linkerFlags = linkerFlags. replace(" x86_64" , " arm64" )
60103 }
61104 add(IOS ){
62105 headerDirs + = [" iosgl" ]
63- cppIncludes + = [" soloud/src/backend/coreaudio/*.cpp " , " iosgl/**" ]
106+ cppIncludes + = [" soloud/src/backend/coreaudio/*.mm " , " iosgl/**" ]
64107 cppFlags = " -stdlib=libc++ -std=c++11 -DWITH_COREAUDIO " + cppFlags
65108 libraries + = " -Wl,-framework,CoreAudio -Wl,-framework,AudioToolbox"
66109 linkerFlags + = " -undefined dynamic_lookup "
67110 }
68111}
69112
70- task fixWrap {
71- doFirst{
72- println " --FIXING SCRIPTS--"
113+ tasks. register(' copyUnsafeStuff' ){
114+ doLast{
73115 copy{
74- from " ../natives/memcpy_wrap.c"
75- into " jni/"
76- }
77-
78- def f = file(" $rootDir /arc-core/jni/build-linux64.xml" );
79- if (f. exists()){
80- f. text = f. text. replace(" -Wl,-wrap,memcpy" , " -Wl,-wrap,memcpy,-wrap,pow,-wrap,powf,-wrap,log,-wrap,logf,-wrap,exp,-wrap,expf,-wrap,clock_gettime" )
116+ from zipTree(" unsafe/unsafe.jar" )
117+ into " build/classes/java/main"
118+ include ' **/*.class'
81119 }
82120 }
83121}
84122
85123getTasksByName(" jnigen" , true ). each {
86- it. finalizedBy fixWrap
124+ it. dependsOn copyUnsafeStuff
87125}
88126
89- task cleanNatives {
127+ tasks . register( ' cleanNatives' ) {
90128 doLast{
91- delete{delete " $rootDir /arc-core/jni" }
92- delete{delete " $rootDir /arc-core/libs" }
93- delete{delete " $rootDir /arc-core/csrc/soloud" }
94- delete{delete " $rootDir /arc-core/csrc/stb_image.h" }
129+ delete{ delete " $rootDir /arc-core/jni" }
130+ delete{ delete " $rootDir /arc-core/libs" }
131+ delete{ delete " $rootDir /arc-core/csrc/soloud" }
132+ delete{ delete " $rootDir /arc-core/csrc/stb_image.h" }
95133 }
96134}
97135
98- task preJni {
136+ tasks . register( ' preJni' ) {
99137 doFirst{
100138 if (! file(" csrc/stb_image.h" ). exists()){
101139 println " Fetching stb_image source..."
102140 // currently locked to a specific commit
103- " curl -o $rootDir /arc-core/csrc/stb_image.h https://raw.githubusercontent.com/nothings/stb/e140649ccf40818781b7e408f6228a486f6d254b /stb_image.h" . execute(). waitFor()
141+ " curl -o $rootDir /arc-core/csrc/stb_image.h https://raw.githubusercontent.com/nothings/stb/013ac3beddff3dbffafd5177e7972067cd2b5083 /stb_image.h" . execute(). waitFor()
104142 }
105143
106144 if (! file(" csrc/soloud" ). exists()){
107145 println " Fetching soloud source..."
108- " git clone --depth 1 --branch v0.11 https://github.com/Anuken/soloud.git $rootDir /arc-core/csrc/soloud" . execute(). waitFor()
146+ " git clone --depth 1 --branch 2025.12.01 https://github.com/Anuken/soloud.git $rootDir /arc-core/csrc/soloud" . execute(). waitFor()
109147 }
110148
111149 copy{
@@ -117,26 +155,26 @@ task preJni{
117155}
118156
119157// copies files into the right locations
120- task postJni {
158+ tasks . register( ' postJni' ) {
121159 doLast{
122160 copy{
123161 from " libs/linux64" , " libs/windows32" , " libs/windows64" , " libs/macosx64"
124- into " .. /natives/natives-desktop/libs"
162+ into " ${ project.rootDir } /natives/natives-desktop/libs"
125163 include " **"
126164 }
127165
128166 [" arm64-v8a" , " x86" , " x86_64" , " armeabi-v7a" ]. each{ p ->
129167 copy{
130168 from " libs/$p "
131- into " .. /natives/natives-android/libs/$p /"
169+ into " ${ project.rootDir } /natives/natives-android/libs/$p /"
132170 include " **"
133171 }
134172 }
135173
136174 [" .tvos" , " " ]. each{ p ->
137175 copy{
138176 from " libs/ios32/libarc.a$p "
139- into " .. /natives/natives-ios/libs/"
177+ into " ${ project.rootDir } /natives/natives-ios/libs/"
140178 include " **"
141179 }
142180 }
0 commit comments