|
1 | | -import org.apache.tools.ant.taskdefs.condition.Os |
2 | | -import net.jpountz.lz4.LZ4FrameOutputStream |
3 | | - |
4 | | -import java.nio.file.Files |
5 | | - |
6 | | -buildscript { |
7 | | - dependencies { |
8 | | - classpath 'at.yawk.lz4:lz4-java:1.11.0' |
9 | | - } |
10 | | -} |
11 | | - |
12 | 1 | plugins { |
13 | 2 | id 'multiloader-common' |
14 | 3 | id 'net.neoforged.moddev' |
15 | 4 | } |
16 | 5 |
|
17 | | -def mac(arch) { |
18 | | - [triple: "${arch}-apple-darwin", suffix: "", arch: arch, os: "macos", ext: "dylib", lib: true] |
19 | | -} |
20 | | - |
21 | | -def linux(arch) { |
22 | | - [triple: "${arch}-unknown-linux-gnu", suffix: ".2.17", arch: arch, os: "linux", ext: "so", lib: true] |
23 | | -} |
24 | | - |
25 | | -def freebsd(arch) { |
26 | | - [triple: "${arch}-unknown-freebsd", suffix: "", arch: arch, os: "freebsd", ext: "so", lib: true] |
27 | | -} |
28 | | - |
29 | | -def windows(arch) { |
30 | | - [triple: "${arch}-pc-windows-msvc", suffix: "", arch: arch, os: "windows", ext: "dll", lib: false] |
31 | | -} |
32 | | - |
33 | | -def supportedTargets = [ |
34 | | - mac("x86_64"), |
35 | | - mac("aarch64"), |
36 | | - linux("x86_64"), |
37 | | - linux("aarch64"), |
38 | | - windows("x86_64"), |
39 | | - windows("aarch64"), |
40 | | -// freebsd("x86_64"), |
41 | | - // freebsd("aarch64"), |
42 | | -] |
43 | | -def pinnedRustVersion = 'nightly-2026-01-29' |
44 | | -def rustRootDir = file("src/main/rust") |
45 | | -def rustProjectDir = file("$rustRootDir/rapier") |
46 | | -def nativesDir = file("src/main/resources/natives/sable_rapier") |
47 | | -def cargoCacheDir = project.layout.buildDirectory.file("cargo").get().asFile |
48 | | -def docker = Os.isFamily(Os.FAMILY_MAC) ? "/usr/local/bin/docker" : "docker" |
49 | | -def xWinImage = 'sable-build-xwin' |
50 | | -def zigbuildImage = 'sable-build-zigbuild' |
51 | | - |
52 | | -def baseDockerCommand = [ |
53 | | - docker, |
54 | | - 'run', |
55 | | - '--rm', |
56 | | - '-v', |
57 | | - "$rustRootDir:/io", |
58 | | - '-v', |
59 | | - "$cargoCacheDir/git:/usr/local/cargo/git", |
60 | | - '-v', |
61 | | - "$cargoCacheDir/registry:/usr/local/cargo/registry", |
62 | | - '-w', |
63 | | - '/io/rapier', |
64 | | -] |
65 | | -project.ext.zigbuildCargo = [baseDockerCommand, zigbuildImage, 'cargo'].flatten() |
66 | | -project.ext.xWinCargo = [baseDockerCommand, xWinImage, 'cargo'].flatten() |
67 | | - |
68 | | -tasks.register('createContainersDirectory') { |
69 | | - doLast { |
70 | | - if (!cargoCacheDir.exists()) { |
71 | | - cargoCacheDir.mkdirs() |
72 | | - } |
73 | | - } |
74 | | -} |
75 | | - |
76 | | - |
77 | | -tasks.register('buildZigbuildImage', Exec) { |
78 | | - group = 'rust' |
79 | | - workingDir rustRootDir |
80 | | - commandLine docker, 'build', '-t', zigbuildImage, 'container/zigbuild', '--build-arg', "RUST_VERSION=${pinnedRustVersion}" |
81 | | - dependsOn createContainersDirectory |
82 | | -} |
83 | | -tasks.register('buildXWinImage', Exec) { |
84 | | - group = 'rust' |
85 | | - workingDir rustRootDir |
86 | | - commandLine docker, 'build', '-t', xWinImage, 'container/xwin', '--build-arg', "RUST_VERSION=${pinnedRustVersion}" |
87 | | - dependsOn createContainersDirectory |
88 | | -} |
89 | | - |
90 | | -tasks.register('buildImages') { |
91 | | - group = 'rust' |
92 | | - dependsOn buildZigbuildImage, buildXWinImage |
93 | | -} |
94 | | - |
95 | | -tasks.register('cleanRust', Exec) { |
96 | | - group = 'rust' |
97 | | - workingDir rustProjectDir |
98 | | - commandLine project.ext.zigbuildCargo |
99 | | - // only need to use zigbuild cargo since both containers share the same target folder |
100 | | - args 'clean' |
101 | | - dependsOn createContainersDirectory |
102 | | -} |
103 | | - |
104 | | -def compileRustTaskName = { target -> |
105 | | - "compileRust-${target.os}-${target.arch}" |
106 | | -} |
107 | | - |
108 | | -def commandLineForTarget(target) { |
109 | | - if (target.triple.contains('msvc')) { |
110 | | - [project.ext.xWinCargo, 'xwin', 'build', '--target', target.triple + target.suffix].flatten() |
111 | | - // support meme platforms, this does nothing by default because the target is disabled |
112 | | - } else if (target.triple == 'aarch64-unknown-freebsd') { |
113 | | - [project.ext.zigbuildCargo, 'zigbuild', '-Z', 'build-std', '--target', target.triple + target.suffix].flatten() |
114 | | - } else { |
115 | | - [project.ext.zigbuildCargo, 'zigbuild', '--target', target.triple + target.suffix].flatten() |
116 | | - } |
117 | | -} |
118 | | - |
119 | | -def nativesNameForTarget(target) { |
120 | | - "sable_rapier_${target.arch}_${target.os}.${target.ext}" |
121 | | -} |
122 | | - |
123 | | -supportedTargets.forEach { target -> |
124 | | - tasks.register(compileRustTaskName(target), Exec) { |
125 | | - group = 'rust' |
126 | | - workingDir rustProjectDir |
127 | | - description = "Cross-compiles natives for the ${target.triple} target" |
128 | | - def commands= commandLineForTarget(target) |
129 | | - commands.add('--release') |
130 | | - commandLine = commands |
131 | | - } |
132 | | -} |
133 | | - |
134 | | -tasks.register("compileRustDev", Exec) { |
135 | | - group = 'rust' |
136 | | - workingDir rustProjectDir |
137 | | - description = "Compiles debug natives" |
138 | | - commandLine = [project.ext.zigbuildCargo, 'zigbuild'].flatten() |
139 | | -} |
140 | | - |
141 | | -tasks.register('buildRustNatives') { |
142 | | - group = 'build' |
143 | | - description = 'Compiles all Rust natives and moves them to resources.' |
144 | | - |
145 | | - dependsOn = supportedTargets.stream().map(compileRustTaskName).collect() |
146 | | - finalizedBy copyRustNatives |
147 | | -} |
148 | | - |
149 | | -tasks.register('buildRustNativesDev') { |
150 | | - group = 'build' |
151 | | - description = 'Compiles all Rust natives and moves them to resources.' |
152 | | - |
153 | | - dependsOn compileRustDev |
154 | | - finalizedBy copyRustNativesDev |
155 | | -} |
156 | | - |
157 | | -tasks.register('copyRustNatives', Copy) { |
158 | | - group = 'rust' |
159 | | - into nativesDir |
160 | | - mustRunAfter(buildRustNatives) |
161 | | - |
162 | | - supportedTargets.forEach { target -> |
163 | | - from(file("$rustRootDir/target/${target.triple}/release/${if (target.lib) { "lib" } else { "" }}sable_rapier.${target.ext}")) { |
164 | | - rename { nativesNameForTarget(target) } |
165 | | - } |
166 | | - } |
167 | | - finalizedBy packRustNatives |
168 | | -} |
169 | | - |
170 | | -tasks.register('copyRustNativesDev', Copy) { |
171 | | - group = 'rust' |
172 | | - into nativesDir |
173 | | - mustRunAfter(buildRustNativesDev) |
174 | | - |
175 | | - supportedTargets.forEach { target -> |
176 | | - var library = file("$rustRootDir/target/debug/${if (target.lib) { "lib" } else { "" }}sable_rapier.${target.ext}") |
177 | | - if (!library.exists()) return |
178 | | - |
179 | | - from(library) { |
180 | | - rename { nativesNameForTarget(target) } |
181 | | - } |
182 | | - } |
183 | | - finalizedBy packRustNatives |
184 | | -} |
185 | | -tasks.register('packRustNatives', Zip) { |
186 | | - group = 'rust' |
187 | | - archiveFile.set file("${nativesDir}/sable_rapier_binaries.zip.l4z") |
188 | | - entryCompression = ZipEntryCompression.STORED |
189 | | - into nativesDir |
190 | | - |
191 | | - mustRunAfter copyRustNatives, copyRustNativesDev |
192 | | - supportedTargets.forEach { target -> |
193 | | - var f = nativesNameForTarget(target) |
194 | | - // No, you can't use rename here in case you were wondering. |
195 | | - from(file("${nativesDir}/${f}")) { eachFile { setPath f } } |
196 | | - } |
197 | | - doLast { |
198 | | - byte[] bytes = Files.readAllBytes(getArchiveFile().get().asFile.toPath()) |
199 | | - try (var f = new FileOutputStream(getArchiveFile().get().asFile)) { |
200 | | - try (var x = new LZ4FrameOutputStream(f, LZ4FrameOutputStream.BLOCKSIZE.SIZE_4MB, bytes.length, LZ4FrameOutputStream.FLG.Bits.BLOCK_INDEPENDENCE)) { |
201 | | - x.write(bytes) |
202 | | - } |
203 | | - } |
204 | | - supportedTargets.forEach { t -> |
205 | | - delete(file("${nativesDir}/${nativesNameForTarget(t)}")) |
206 | | - } |
207 | | - } |
208 | | -} |
209 | | - |
210 | 6 | neoForge { |
211 | 7 | neoFormVersion = neo_form_version |
212 | 8 | // Automatically enable AccessTransformers if the file exists |
@@ -256,6 +52,6 @@ dependencies { |
256 | 52 | transitive = false |
257 | 53 | } |
258 | 54 |
|
259 | | - implementation "fuzs.forgeconfigapiport:forgeconfigapiport-common-neoforgeapi:${forgeconfigapiport_version}" |
260 | 55 | //source: https://github.com/Fuzss/forgeconfigapiport |
| 56 | + implementation "fuzs.forgeconfigapiport:forgeconfigapiport-common-neoforgeapi:${forgeconfigapiport_version}" |
261 | 57 | } |
0 commit comments