meson.build (8899B)
1 project('quickjs-tart', 'c', 2 version : '0.0.1', 3 meson_version: '>=0.55.0', 4 default_options : [ 5 'warning_level=1', 6 'optimization=2', 7 ], 8 ) 9 10 flags = [ 11 '-D_GNU_SOURCE', 12 '-D_LARGEFILE_SOURCE', 13 '-D_FILE_OFFSET_BITS=64', 14 '-DCONFIG_VERSION="0.0.1"', 15 '-fno-omit-frame-pointer', 16 ] 17 18 add_project_arguments(flags, language : 'c') 19 add_project_arguments(flags, language : 'c', native : true) 20 21 if host_machine.system() == 'android' 22 add_project_link_arguments('-Wl,--hash-style=both', language : 'c') 23 endif 24 25 cc = meson.get_compiler('c') 26 27 m_dep = cc.find_library('m', required : false) 28 dl_dep = cc.find_library('dl', required : true) 29 thread_dep = dependency('threads') 30 31 cmake = import('cmake') 32 cmake_opts = cmake.subproject_options() 33 cmake_opts.add_cmake_defines({ 34 'CMAKE_POSITION_INDEPENDENT_CODE' : true, 35 'CMAKE_SUPPRESS_DEVELOPER_WARNINGS' : true, 36 'CMAKE_WARN_DEPRECATED' : false, 37 'ENABLE_TESTING' : false, 38 'ENABLE_PROGRAMS' : false}) 39 40 # TLS library 41 mbedtls_proj = cmake.subproject('mbedtls', required : true, options : cmake_opts) 42 mbedcrypto_dep = mbedtls_proj.dependency('mbedcrypto') 43 mbedtls_dep = mbedtls_proj.dependency('mbedtls') 44 mbedx509_dep = mbedtls_proj.dependency('mbedx509') 45 46 # Library for HTTP requests 47 if host_machine.system() != 'ios' and host_machine.system() != 'android' 48 curl_proj = subproject('curl', required : true) 49 curl_dep = curl_proj.get_variable('curl_dep') 50 endif 51 52 # Crypto library 53 sodium_proj = subproject('libsodium', required : true) 54 sodium_dep = sodium_proj.get_variable('sodium_dep') 55 56 # quickjs floating-point conversion library 57 dtoa = static_library('dtoa', 'quickjs/dtoa.c') 58 # regular expression library 59 libregexp = static_library('regexp', 'quickjs/libregexp.c') 60 # unicode 61 libunicode = static_library('unicode', 'quickjs/libunicode.c') 62 # general utilities 63 cutils = static_library('cutils', 'quickjs/cutils.c') 64 # standard library for quickjs (std and os modules) 65 # mobile apps use native networking 66 if host_machine.system() == 'ios' or host_machine.system() == 'android' 67 quickjs_libc = static_library('quickjs-libc', ['quickjs/quickjs-libc.c']) 68 else 69 quickjs_libc = static_library('quickjs-libc', ['quickjs/quickjs-libc.c', 'quickjs/quickjs-http.c'], dependencies : curl_dep) 70 endif 71 72 # base JS interpreter 73 quickjs = static_library('quickjs', 'quickjs/quickjs.c') 74 75 # for iOS use Apple's hand-optimized sqlite3 76 if host_machine.system() == 'ios' 77 sqlite3_dep = cc.find_library('sqlite3', required : true) 78 else 79 sqlite_cargs = [] 80 if host_machine.system() == 'android' 81 # flags taken from AOSP 82 sqlite_cargs += [ 83 '-DNDEBUG=1', 84 '-DHAVE_USLEEP=1', 85 '-DSQLITE_HAVE_ISNAN', 86 '-DSQLITE_DEFAULT_JOURNAL_SIZE_LIMIT=1048576', 87 '-DSQLITE_THREADSAFE=2', 88 '-DSQLITE_TEMP_STORE=3', 89 '-DSQLITE_POWERSAFE_OVERWRITE=1', 90 '-DSQLITE_DEFAULT_FILE_FORMAT=4', 91 '-DSQLITE_DEFAULT_AUTOVACUUM=1', 92 '-DSQLITE_ENABLE_MEMORY_MANAGEMENT=1', 93 '-DSQLITE_ENABLE_FTS3', 94 '-DSQLITE_ENABLE_FTS3_PARENTHESIS', 95 '-DSQLITE_ENABLE_FTS4', 96 '-DSQLITE_ENABLE_FTS4_PARENTHESIS', 97 '-DSQLITE_ENABLE_FTS5', 98 '-DSQLITE_ENABLE_FTS5_PARENTHESIS', 99 '-DSQLITE_ENABLE_JSON1', 100 '-DSQLITE_ENABLE_RTREE=1', 101 '-DSQLITE_UNTESTABLE', 102 '-DSQLITE_OMIT_COMPILEOPTION_DIAGS', 103 '-DSQLITE_DEFAULT_FILE_PERMISSIONS=0600', 104 '-DSQLITE_DEFAULT_MEMSTATUS=0', 105 '-DSQLITE_MAX_EXPR_DEPTH=0', 106 '-DSQLITE_USE_ALLOCA', 107 '-DSQLITE_ENABLE_BATCH_ATOMIC_WRITE', 108 ] 109 endif 110 111 sqlite3 = static_library('sqlite3', 'sqlite3/sqlite3.c', c_args : sqlite_cargs) 112 endif 113 114 # avoid warning but compile more slowly on non-cross builds 115 avoid_cross_warning = true 116 117 # native version of quickjs used by the qjsc (.js -> .c compiler), 118 # compiled for the build platform. 119 if avoid_cross_warning or meson.is_cross_build() 120 dtoa_native = static_library('dtoa_native', 'quickjs/dtoa.c', native : true) 121 libregexp_native = static_library('regexp_native', 'quickjs/libregexp.c', native : true) 122 libunicode_native = static_library('unicode_native', 'quickjs/libunicode.c', native : true) 123 cutils_native = static_library('cutils_native', 'quickjs/cutils.c', native : true) 124 quickjs_native = static_library('quickjs_native', 'quickjs/quickjs.c', native : true) 125 else 126 dtoa_native = dtoa 127 libregexp_native = libregexp 128 libunicode_native = libunicode 129 cutils_native = cutils 130 quickjs_libc_native = quickjs_libc 131 quickjs_native = quickjs 132 endif 133 134 # QuickJS compiler (.js -> C) 135 qjsc_exe = executable('qjsc', [ 136 'quickjs/qjsc.c', 137 'quickjs/quickjs-libc.c', 138 ], 139 # Just the compiler, no HTTP support required 140 c_args : ['-DNO_HTTP'], 141 link_with: [ 142 dtoa_native, 143 libregexp_native, 144 libunicode_native, 145 cutils_native, 146 quickjs_native, 147 ], 148 dependencies: [ 149 m_dep, 150 dl_dep, 151 thread_dep, 152 ], 153 native : true) 154 155 # JS implementation of the read-eval-print loop, 156 # just used for interactive testing 157 repl_c = custom_target('repl_c', 158 input : ['quickjs/repl.js'], 159 output : ['repl.c'], 160 command : [qjsc_exe, '-c', '-m', 161 '-o', '@OUTPUT@', 162 '@INPUT@']) 163 164 # Helper functions used by the wallet-core JS, 165 # compiled to C. 166 prelude_c = custom_target('prelude_c', 167 input : ['prelude.js'], 168 output : ['prelude.c'], 169 command : [qjsc_exe, '-c', '-m', '-M', 'tart', 170 '-o', '@OUTPUT@', 171 '@INPUT@']) 172 173 # Wallet core JS file, 174 # compiled to C. 175 wallet_core_c = custom_target('wallet_core_c', 176 input : ['taler-wallet-core-qjs.mjs'], 177 output : ['wallet_core.c'], 178 command : [qjsc_exe, '-c', '-m', '-M', 'tart', '-N', 'qjsc_wallet_core', 179 '-o', '@OUTPUT@', 180 '@INPUT@']) 181 182 # Static libraries from the generated C files 183 repl = static_library('repl', repl_c) 184 prelude = static_library('prelude', prelude_c) 185 wallet_core = static_library('wallet_core', wallet_core_c) 186 187 # Taler runtime ("tart") loadable JavaScript module 188 if host_machine.system() == 'ios' 189 tart = static_library('tart', 'tart_module.c', 190 dependencies : [ 191 m_dep, 192 mbedcrypto_dep, 193 mbedtls_dep, 194 mbedx509_dep, 195 sodium_dep, 196 sqlite3_dep 197 ]) 198 else 199 tart = static_library('tart', 'tart_module.c', 200 link_with : [sqlite3], 201 dependencies : [ 202 m_dep, 203 mbedcrypto_dep, 204 mbedtls_dep, 205 mbedx509_dep, 206 sodium_dep 207 ]) 208 endif 209 210 # Interactive JS interpreter with Taler-specific 211 # functions (crypto etc.) 212 if not meson.is_cross_build() 213 dependencies = [ 214 m_dep, 215 mbedcrypto_dep, 216 mbedtls_dep, 217 mbedx509_dep, 218 sodium_dep, 219 ] 220 221 # mobile apps use native networking 222 if host_machine.system() != 'ios' and host_machine.system() != 'android' 223 dependencies += [curl_dep] 224 endif 225 226 qtart_exe = executable('qtart', [ 227 'qtart.c', 228 ], 229 link_with: [ 230 dtoa, 231 libregexp, 232 libunicode , 233 cutils, 234 quickjs_libc, 235 quickjs, 236 repl, 237 wallet_core, 238 prelude, 239 tart, 240 ], 241 dependencies: dependencies) 242 endif 243 244 # Library that implements wallet-core, typically 245 # the only build output directly used by the UI layer. 246 if host_machine.system() == 'ios' 247 talerwalletcore_lib = static_library('talerwalletcore', 'taler_wallet_core_lib.c', 248 link_with : [ 249 dtoa, 250 libregexp, 251 libunicode, 252 cutils, 253 quickjs_libc, 254 quickjs, 255 tart, 256 wallet_core, 257 prelude, 258 ], 259 dependencies: [ 260 m_dep, 261 mbedcrypto_dep, 262 mbedtls_dep, 263 mbedx509_dep, 264 sodium_dep, 265 ], c_args : ['-DNO_CURL']) 266 else 267 talerwalletcore_cargs = [] 268 if host_machine.system() == 'android' 269 # no cURL, Android is using native networking 270 talerwalletcore_cargs += ['-DNO_CURL'] 271 endif 272 talerwalletcore_lib = shared_library('talerwalletcore', 'taler_wallet_core_lib.c', 273 link_with : [ 274 dtoa, 275 libregexp, 276 libunicode, 277 cutils, 278 quickjs_libc, 279 quickjs, 280 tart, 281 wallet_core, 282 prelude, 283 ], 284 dependencies: [ 285 m_dep, 286 mbedcrypto_dep, 287 mbedtls_dep, 288 mbedx509_dep, 289 sodium_dep, 290 ], c_args : talerwalletcore_cargs) 291 endif 292 293 # Example for using libtalerwalletcore.so 294 if not meson.is_cross_build() 295 wallet_client_example_exe = executable('wallet-client-example', 296 'wallet-client-example.c', 297 link_with : [talerwalletcore_lib]) 298 299 wallet_lifecycle_test = executable('test-wallet-lifecycle', 300 'tests/test_wallet_lifecycle.c', 301 link_with : [talerwalletcore_lib]) 302 303 test('prelude', qtart_exe, 304 args : [files('tests/test_prelude.js')]) 305 test('sqlite3', qtart_exe, 306 args : [files('tests/test_sqlite3_error.js')]) 307 test('tart-inputs', qtart_exe, 308 args : [files('tests/test_tart_inputs.js')]) 309 test('wallet-lifecycle', wallet_lifecycle_test, 310 timeout : 60) 311 312 openssl_exe = find_program('openssl', required : false) 313 if openssl_exe.found() 314 python = import('python').find_installation() 315 test('https', python, 316 args : [files('tests/test_https.py'), qtart_exe], 317 timeout : 60) 318 endif 319 endif