-
Notifications
You must be signed in to change notification settings - Fork 3
/
siwin.nimble
193 lines (147 loc) · 8.02 KB
/
siwin.nimble
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
version = "0.9.2"
author = "levovix0"
description = "Simple Window Maker"
license = "MIT"
srcDir = "src"
requires "nim >= 2.0"
requires "chroma >= 0.2.6"
requires "vmath >= 1.1.4"
# note: require platform dependencies only if it is the platform on which userprogrammer works.
# ask a userprogrammer to install specific platform dependencies if cross compiling.
when defined(linux):
requires "x11 >= 1.1"
when defined(windows):
requires "winim >= 3.6"
when defined(android):
requires "jnim >= 0.5.2"
requires "https://github.com/yglukhov/android"
import strformat, os
proc createZigccIfNeeded =
let code = "import std/[os, osproc]; quit startProcess(\"/usr/bin/zig\", args = @[\"cc\"] & commandLineParams(), options = {poParentStreams}).waitForExit"
if not fileExists("build/zigcc.nim"):
writeFile "build/zigcc.nim", code
if not fileExists("build/zigcc"):
exec "nim c build/zigcc.nim"
proc buildBasiaIfNeeded =
if not dirExists "build/basia":
withDir "build":
exec "git clone https://github.com/akavel/basia"
withDir "basia":
exec "go build"
proc downloadAndroidNdkIfNeeded() =
if not dirExists "build/android-ndk-r25c":
withDir "build":
exec "wget https://dl.google.com/android/repository/android-ndk-r25c-linux.zip"
exec "unzip android-ndk-r25c-linux.zip"
rmFile "android-ndk-r25c-linux.zip"
task installTestDeps, "install test dependencies":
exec "nimble install opengl"
exec "nimble install nimgl"
exec "nimble install pixie"
createZigccIfNeeded()
task installAndroidDeps, "install android dependencies":
exec "nimble install https://github.com/levovix0/dali"
exec "nimble install https://github.com/levovix0/[email protected]"
downloadAndroidNdkIfNeeded()
# note: requires androids sdk also!
buildBasiaIfNeeded()
const testTargets = ["t_opengl_es", "t_opengl", "tests", "t_vulkan", "t_offscreen"]
proc runTests(args: string) =
withDir "tests":
for target in testTargets:
try: exec "nim c " & args & " --hints:off -r " & target
except: discard
task test, "test":
runTests ""
task testRefc, "test with --mm:refc":
runTests "--mm:refc"
task testWindows, "test windows version with wine on linux":
runTests "-d:mingw --os:windows --cc:gcc --gcc.exe:/usr/bin/x86_64-w64-mingw32-gcc --gcc.linkerexe:/usr/bin/x86_64-w64-mingw32-gcc"
task testRefcWindows, "test windows version with wine on linux with --mm:refc":
runTests "-d:mingw --os:windows --cc:gcc --gcc.exe:/usr/bin/x86_64-w64-mingw32-gcc --gcc.linkerexe:/usr/bin/x86_64-w64-mingw32-gcc --mm:refc"
task testMacos, "test macos":
createZigccIfNeeded()
let pwd = getCurrentDir()
let target = "x86_64-macos-none"
withDir "tests":
for file in testTargets:
try:
exec &"nim c --os:macosx --cc:clang --clang.exe:{pwd}/build/zigcc --clang.linkerexe:{pwd}/build/zigcc --passc:--target={target} --passl:--target={target} --hints:off -o:{file}-macos {file}"
exec &"echo ./{file}-macos | darling shell"
except: discard
proc buildAndroid() =
let pwd = getCurrentDir()
mkdir "build/android"
mkdir "build/android/apk"
var androidSdk = getEnv("ANDROID_SDK_ROOT")
if androidSdk == "":
androidSdk = getHomeDir() / "Android/Sdk"
let packageName = "com.levovix.siwintest"
let compiler32 = &"--arm.android.clang.path:{pwd}/build/android-ndk-r25c/toolchains/llvm/prebuilt/linux-x86_64/bin/ --arm.android.clang.exe:armv7a-linux-androideabi24-clang --arm.android.clang.linkerexe:armv7a-linux-androideabi24-clang"
let compiler64 = &"--arm64.android.clang.path:{pwd}/build/android-ndk-r25c/toolchains/llvm/prebuilt/linux-x86_64/bin/ --arm64.android.clang.exe:aarch64-linux-android24-clang --arm64.android.clang.linkerexe:aarch64-linux-android24-clang"
# compile manifest
writeFile "build/android/AndroidManifest.xml", &"""
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="{packageName}"
android:versionCode="1" android:versionName="1.0"
>
<uses-feature android:glEsVersion="0x00020000" android:required="true" />
<uses-sdk android:minSdkVersion="1" android:targetSdkVersion="33" />
<application android:label="Siwin test">
<activity android:name="Jnim$SiwinActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>"""
# https://github.com/akavel/marco
exec "marco -i=build/android/AndroidManifest.xml -o=build/android/apk/AndroidManifest.xml"
# cpFile "build/android/AndroidManifest.xml", "build/android/apk/AndroidManifest.xml"
# build so
# exec &"nim c --noMain --app:lib --os:android --cpu=arm --threads:on --tlsEmulation:off -d:noSignalHandler {compiler32} -d:JnimPackageName={packageName} -d:jnimGenDex -d:siwin_generateDex_out=build/android/siwin_gen_dex.nim -o:build/android/apk/lib/armeabi-v7a/libsiwintest.so src/siwin/platforms/android/window.nim"
# exec &"nim c --noMain --app:lib --os:android --cpu=arm64 --threads:on --tlsEmulation:off -d:noSignalHandler {compiler64} -d:JnimPackageName={packageName} -d:jnimGenDex -d:siwin_generateDex_out=build/android/siwin_gen_dex.nim -o:build/android/apk/lib/arm64-v8a/libsiwintest.so src/siwin/platforms/android/window.nim"
exec &"nim c --noMain --app:lib --os:android --cpu=arm --threads:on --tlsEmulation:off -d:noSignalHandler {compiler32} -d:JnimPackageName={packageName} -o:build/android/apk/lib/armeabi-v7a/libsiwintest.so tests/et_android.nim"
exec &"nim c --noMain --app:lib --os:android --cpu=arm64 --threads:on --tlsEmulation:off -d:noSignalHandler {compiler64} -d:JnimPackageName={packageName} -o:build/android/apk/lib/arm64-v8a/libsiwintest.so tests/et_android.nim"
# compile java
mkdir "build/android/java"
mvFile "Jnim.java", "build/android/java/Jnim.java"
withDir "build/android/java":
exec &"javac --release 8 -cp \".:{androidSdk}/platforms/android-33/android.jar\" ../java/Jnim.java"
exec "d8 *.class"
cpFile "build/android/java/classes.dex", "build/android/apk/classes.dex"
# compile java using https://github.com/akavel/dali, the alternative way
# withDir "build/android":
# writeFile("siwin_gen_dex.nim", readFile("siwin_gen_dex.nim").replace("@@[", "@[")) #? idk wtf
# exec "nim c -r siwin_gen_dex.nim apk/classes.dex libsiwintest.so"
# pack apk and (incorrectly) sign it
writeFile "build/android/cert.x509.pem", """
-----BEGIN CERTIFICATE-----
MIGgMIGVAgEBMAMGAQEwCTEHMAUGAQETADAaFwsxNzEwMTAyMjUwWhcLMTcxMDEw
MjI1MFowCTEHMAUGAQETADBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABLAoWrpy
dzdU6PN096BcSaDRFuC+/8MjLhgeFUiogqlrZFocHudWRHJALK08ge+x0n3nwCVB
wJ4Ybfhm0sf9nowwAwYBAQMBAA==
-----END CERTIFICATE-----"""
writeFile "build/android/key.pk8", "\048\065\002\001\000\048\019\006\007\042\134\072\206\061\002\001\006\008\042\134\072\206\061\003\001\007\004\039\048\037\002\001\001\004\032\175\054\219\048\021\044\088\163\189\252\173\147\060\181\180\015\079\156\008\002\164\135\157\116\026\081\082\187\046\240\155\207"
withDir "build/android":
exec "../basia/basia -i=apk/ -c=cert.x509.pem -k=key.pk8 -o=siwintest.apk"
# sign apk
withDir "build/android":
if not fileExists("my.keystore"):
exec "keytool -genkey -v -keystore my.keystore -keyalg RSA -keysize 2048 -validity 10000 -alias app"
# apksigner from android-sdk-build-tools (AUR)
exec "apksigner sign --ks my.keystore --ks-key-alias app siwintest.apk"
task testAndroid, "test android":
buildAndroid()
try: exec "adb uninstall com.levovix.siwintest"
except: discard
exec "adb install -r build/android/siwintest.apk"
task testAll, "run all tests":
runTests ""
runTests "--mm:refc"
runTests "-d:mingw --os:windows --cc:gcc --gcc.exe:/usr/bin/x86_64-w64-mingw32-gcc --gcc.linkerexe:/usr/bin/x86_64-w64-mingw32-gcc"
runTests "-d:mingw --os:windows --cc:gcc --gcc.exe:/usr/bin/x86_64-w64-mingw32-gcc --gcc.linkerexe:/usr/bin/x86_64-w64-mingw32-gcc --mm:refc"
task testIc, "test incremental compilation":
exec "nim c -r --mm:refc --incremental:on tests/et_ic.nim"