siwin.nimble 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. version = "0.9.2"
  2. author = "levovix0"
  3. description = "Simple Window Maker"
  4. license = "MIT"
  5. srcDir = "src"
  6. requires "nim >= 2.0"
  7. requires "chroma >= 0.2.6"
  8. requires "vmath >= 1.1.4"
  9. # note: require platform dependencies only if it is the platform on which userprogrammer works.
  10. # ask a userprogrammer to install specific platform dependencies if cross compiling.
  11. when defined(linux):
  12. requires "x11 >= 1.1"
  13. when defined(windows):
  14. requires "winim >= 3.6"
  15. when defined(android):
  16. requires "jnim >= 0.5.2"
  17. requires "https://github.com/yglukhov/android"
  18. import strformat, os
  19. proc createZigccIfNeeded =
  20. let code = "import std/[os, osproc]; quit startProcess(\"/usr/bin/zig\", args = @[\"cc\"] & commandLineParams(), options = {poParentStreams}).waitForExit"
  21. if not fileExists("build/zigcc.nim"):
  22. writeFile "build/zigcc.nim", code
  23. if not fileExists("build/zigcc"):
  24. exec "nim c build/zigcc.nim"
  25. proc buildBasiaIfNeeded =
  26. if not dirExists "build/basia":
  27. withDir "build":
  28. exec "git clone https://github.com/akavel/basia"
  29. withDir "basia":
  30. exec "go build"
  31. proc downloadAndroidNdkIfNeeded() =
  32. if not dirExists "build/android-ndk-r25c":
  33. withDir "build":
  34. exec "wget https://dl.google.com/android/repository/android-ndk-r25c-linux.zip"
  35. exec "unzip android-ndk-r25c-linux.zip"
  36. rmFile "android-ndk-r25c-linux.zip"
  37. task installTestDeps, "install test dependencies":
  38. exec "nimble install opengl"
  39. exec "nimble install nimgl"
  40. exec "nimble install pixie"
  41. createZigccIfNeeded()
  42. task installAndroidDeps, "install android dependencies":
  43. exec "nimble install https://github.com/levovix0/dali"
  44. exec "nimble install https://github.com/levovix0/marco@0.1.2"
  45. downloadAndroidNdkIfNeeded()
  46. # note: requires androids sdk also!
  47. buildBasiaIfNeeded()
  48. const testTargets = ["t_opengl_es", "t_opengl", "tests", "t_vulkan", "t_offscreen"]
  49. proc runTests(args: string) =
  50. withDir "tests":
  51. for target in testTargets:
  52. try: exec "nim c " & args & " --hints:off -r " & target
  53. except: discard
  54. task test, "test":
  55. runTests ""
  56. task testRefc, "test with --mm:refc":
  57. runTests "--mm:refc"
  58. task testWindows, "test windows version with wine on linux":
  59. 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"
  60. task testRefcWindows, "test windows version with wine on linux with --mm:refc":
  61. 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"
  62. task testMacos, "test macos":
  63. createZigccIfNeeded()
  64. let pwd = getCurrentDir()
  65. let target = "x86_64-macos-none"
  66. withDir "tests":
  67. for file in testTargets:
  68. try:
  69. 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}"
  70. exec &"echo ./{file}-macos | darling shell"
  71. except: discard
  72. proc buildAndroid() =
  73. let pwd = getCurrentDir()
  74. mkdir "build/android"
  75. mkdir "build/android/apk"
  76. var androidSdk = getEnv("ANDROID_SDK_ROOT")
  77. if androidSdk == "":
  78. androidSdk = getHomeDir() / "Android/Sdk"
  79. let packageName = "com.levovix.siwintest"
  80. 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"
  81. 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"
  82. # compile manifest
  83. writeFile "build/android/AndroidManifest.xml", &"""
  84. <?xml version="1.0" encoding="utf-8"?>
  85. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  86. package="{packageName}"
  87. android:versionCode="1" android:versionName="1.0"
  88. >
  89. <uses-feature android:glEsVersion="0x00020000" android:required="true" />
  90. <uses-sdk android:minSdkVersion="1" android:targetSdkVersion="33" />
  91. <application android:label="Siwin test">
  92. <activity android:name="Jnim$SiwinActivity">
  93. <intent-filter>
  94. <action android:name="android.intent.action.MAIN" />
  95. <category android:name="android.intent.category.LAUNCHER" />
  96. </intent-filter>
  97. </activity>
  98. </application>
  99. </manifest>"""
  100. # https://github.com/akavel/marco
  101. exec "marco -i=build/android/AndroidManifest.xml -o=build/android/apk/AndroidManifest.xml"
  102. # cpFile "build/android/AndroidManifest.xml", "build/android/apk/AndroidManifest.xml"
  103. # build so
  104. # 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"
  105. # 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"
  106. 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"
  107. 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"
  108. # compile java
  109. mkdir "build/android/java"
  110. mvFile "Jnim.java", "build/android/java/Jnim.java"
  111. withDir "build/android/java":
  112. exec &"javac --release 8 -cp \".:{androidSdk}/platforms/android-33/android.jar\" ../java/Jnim.java"
  113. exec "d8 *.class"
  114. cpFile "build/android/java/classes.dex", "build/android/apk/classes.dex"
  115. # compile java using https://github.com/akavel/dali, the alternative way
  116. # withDir "build/android":
  117. # writeFile("siwin_gen_dex.nim", readFile("siwin_gen_dex.nim").replace("@@[", "@[")) #? idk wtf
  118. # exec "nim c -r siwin_gen_dex.nim apk/classes.dex libsiwintest.so"
  119. # pack apk and (incorrectly) sign it
  120. writeFile "build/android/cert.x509.pem", """
  121. -----BEGIN CERTIFICATE-----
  122. MIGgMIGVAgEBMAMGAQEwCTEHMAUGAQETADAaFwsxNzEwMTAyMjUwWhcLMTcxMDEw
  123. MjI1MFowCTEHMAUGAQETADBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABLAoWrpy
  124. dzdU6PN096BcSaDRFuC+/8MjLhgeFUiogqlrZFocHudWRHJALK08ge+x0n3nwCVB
  125. wJ4Ybfhm0sf9nowwAwYBAQMBAA==
  126. -----END CERTIFICATE-----"""
  127. 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"
  128. withDir "build/android":
  129. exec "../basia/basia -i=apk/ -c=cert.x509.pem -k=key.pk8 -o=siwintest.apk"
  130. # sign apk
  131. withDir "build/android":
  132. if not fileExists("my.keystore"):
  133. exec "keytool -genkey -v -keystore my.keystore -keyalg RSA -keysize 2048 -validity 10000 -alias app"
  134. # apksigner from android-sdk-build-tools (AUR)
  135. exec "apksigner sign --ks my.keystore --ks-key-alias app siwintest.apk"
  136. task testAndroid, "test android":
  137. buildAndroid()
  138. try: exec "adb uninstall com.levovix.siwintest"
  139. except: discard
  140. exec "adb install -r build/android/siwintest.apk"
  141. task testAll, "run all tests":
  142. runTests ""
  143. runTests "--mm:refc"
  144. 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"
  145. 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"
  146. task testIc, "test incremental compilation":
  147. exec "nim c -r --mm:refc --incremental:on tests/et_ic.nim"