ソースを参照

jerryscript: add package (#5941)

* jerryscript: add package

* jerryscript: add CMP0057

* jerryscript: disable shared

* jerryscript: use git versioning

* jerryscript: add enum cast patch

* jerryscript: update patch

* jerryscript: update patch

* jerryscript: update patch

* jerryscript: update patch

* jerryscript: add no-deprecated-enum-enum-conversion

* jerryscript: add flag patch

* jerryscript: fix path

* jerryscript: test wasm

* jerryscript: update patch

* jerryscript: update patch

* jerryscript: update patch

* jerryscript: update patch hash

* jerryscript: add limits

* jerryscript: fix patch

* jerryscript: add limits

* Revert "jerryscript: fix patch"

This reverts commit 0a6fd56bf0029906721f280fcb2a563f0160e6c4.

* jerryscript: update patch

* jerryscript: enable clang

* jerryscript: disable clang

* jerryscript: use `has_runtime`

* jerryscript: add MTd

* Update xmake.lua

---------

Co-authored-by: ruki <[email protected]>
Chi Huu Huynh 7 ヶ月 前
コミット
28d2d63ca7

+ 189 - 0
packages/j/jerryscript/patches/2024.12.03/enum.patch

@@ -0,0 +1,189 @@
+diff --git a/CMakeLists.txt b/CMakeLists.txt
+index dd198286..2be84c5f 100644
+--- a/CMakeLists.txt
++++ b/CMakeLists.txt
+@@ -235,7 +235,7 @@ if(USING_GCC)
+ endif()
+ 
+ if(USING_CLANG)
+-  jerry_add_compile_flags(-Wno-nested-anon-types -Wno-static-in-inline)
++  jerry_add_compile_flags(-Wno-nested-anon-types -Wno-static-in-inline -Wno-enum-enum-conversion)
+ endif()
+ 
+ if(USING_TI)
+diff --git a/jerry-core/api/jerryscript.c b/jerry-core/api/jerryscript.c
+index 60f8023f..59cbcb4c 100644
+--- a/jerry-core/api/jerryscript.c
++++ b/jerry-core/api/jerryscript.c
+@@ -82,13 +82,13 @@ JERRY_STATIC_ASSERT ((int) ECMA_PROMISE_IS_PENDING == (int) JERRY_PROMISE_STATE_
+ /**
+  * Offset between internal and external arithmetic operator types
+  */
+-#define ECMA_NUMBER_ARITHMETIC_OP_API_OFFSET (JERRY_BIN_OP_SUB - NUMBER_ARITHMETIC_SUBTRACTION)
++#define ECMA_NUMBER_ARITHMETIC_OP_API_OFFSET ((int) JERRY_BIN_OP_SUB - (int) NUMBER_ARITHMETIC_SUBTRACTION)
+ 
+-JERRY_STATIC_ASSERT (((NUMBER_ARITHMETIC_SUBTRACTION + ECMA_NUMBER_ARITHMETIC_OP_API_OFFSET) == JERRY_BIN_OP_SUB)
+-                       && ((NUMBER_ARITHMETIC_MULTIPLICATION + ECMA_NUMBER_ARITHMETIC_OP_API_OFFSET)
+-                           == JERRY_BIN_OP_MUL)
+-                       && ((NUMBER_ARITHMETIC_DIVISION + ECMA_NUMBER_ARITHMETIC_OP_API_OFFSET) == JERRY_BIN_OP_DIV)
+-                       && ((NUMBER_ARITHMETIC_REMAINDER + ECMA_NUMBER_ARITHMETIC_OP_API_OFFSET) == JERRY_BIN_OP_REM),
++JERRY_STATIC_ASSERT ((((int) NUMBER_ARITHMETIC_SUBTRACTION + (int) ECMA_NUMBER_ARITHMETIC_OP_API_OFFSET) == (int) JERRY_BIN_OP_SUB)
++                       && (((int) NUMBER_ARITHMETIC_MULTIPLICATION + (int) ECMA_NUMBER_ARITHMETIC_OP_API_OFFSET)
++                           == (int) JERRY_BIN_OP_MUL)
++                       && (((int) NUMBER_ARITHMETIC_DIVISION + (int) ECMA_NUMBER_ARITHMETIC_OP_API_OFFSET) == (int) JERRY_BIN_OP_DIV)
++                       && (((int) NUMBER_ARITHMETIC_REMAINDER + (int) ECMA_NUMBER_ARITHMETIC_OP_API_OFFSET) == (int) JERRY_BIN_OP_REM),
+                      number_arithmetics_operation_type_matches_external);
+ 
+ #if !JERRY_PARSER && !JERRY_SNAPSHOT_EXEC
+@@ -1841,7 +1841,7 @@ jerry_binary_op (jerry_binary_op_t operation, /**< operation */
+     case JERRY_BIN_OP_DIV:
+     case JERRY_BIN_OP_REM:
+     {
+-      return jerry_return (do_number_arithmetic (operation - ECMA_NUMBER_ARITHMETIC_OP_API_OFFSET, lhs, rhs));
++      return jerry_return (do_number_arithmetic (operation - (int) ECMA_NUMBER_ARITHMETIC_OP_API_OFFSET, lhs, rhs));
+     }
+     default:
+     {
+@@ -4854,7 +4854,7 @@ jerry_symbol (jerry_well_known_symbol_t symbol) /**< jerry_well_known_symbol_t e
+ {
+   jerry_assert_api_enabled ();
+ 
+-  lit_magic_string_id_t id = (lit_magic_string_id_t) (LIT_GLOBAL_SYMBOL__FIRST + symbol);
++  lit_magic_string_id_t id = (lit_magic_string_id_t) ((int) LIT_GLOBAL_SYMBOL__FIRST + (int) symbol);
+ 
+   if (!LIT_IS_GLOBAL_SYMBOL (id))
+   {
+diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-regexp-prototype.c b/jerry-core/ecma/builtin-objects/ecma-builtin-regexp-prototype.c
+index 94c0384d..98c25eae 100644
+--- a/jerry-core/ecma/builtin-objects/ecma-builtin-regexp-prototype.c
++++ b/jerry-core/ecma/builtin-objects/ecma-builtin-regexp-prototype.c
+@@ -251,7 +251,7 @@ ecma_builtin_regexp_prototype_compile (ecma_value_t this_arg, /**< this */
+     ecma_value_t status = ecma_builtin_helper_def_prop (this_obj_p,
+                                                         ecma_get_magic_string (LIT_MAGIC_STRING_LASTINDEX_UL),
+                                                         ecma_make_uint32_value (0),
+-                                                        ECMA_PROPERTY_FLAG_WRITABLE | JERRY_PROP_SHOULD_THROW);
++                                                        (int) ECMA_PROPERTY_FLAG_WRITABLE | (int) JERRY_PROP_SHOULD_THROW);
+ 
+     ecma_bytecode_deref ((ecma_compiled_code_t *) old_bc_p);
+ 
+diff --git a/jerry-core/ecma/operations/ecma-bigint.c b/jerry-core/ecma/operations/ecma-bigint.c
+index 7a4464e0..5f291a57 100644
+--- a/jerry-core/ecma/operations/ecma-bigint.c
++++ b/jerry-core/ecma/operations/ecma-bigint.c
+@@ -1584,14 +1584,14 @@ ecma_bigint_and (ecma_value_t left_value, /**< left BigInt value */
+     }
+ 
+     /* x & (-y) == x & ~(y-1) == x &~ (y-1) */
+-    uint32_t operation_and_options = ECMA_BIG_UINT_BITWISE_AND_NOT | ECMA_BIG_UINT_BITWISE_DECREASE_RIGHT;
++    uint32_t operation_and_options = (uint32_t) ECMA_BIG_UINT_BITWISE_AND_NOT | (uint32_t) ECMA_BIG_UINT_BITWISE_DECREASE_RIGHT;
+     return ecma_bigint_bitwise_op (operation_and_options, left_p, right_p);
+   }
+ 
+   if (!(right_p->u.bigint_sign_and_size & ECMA_BIGINT_SIGN))
+   {
+     /* (-x) & y == ~(x-1) & y == y &~ (x-1) */
+-    uint32_t operation_and_options = ECMA_BIG_UINT_BITWISE_AND_NOT | ECMA_BIG_UINT_BITWISE_DECREASE_RIGHT;
++    uint32_t operation_and_options = (uint32_t) ECMA_BIG_UINT_BITWISE_AND_NOT | (uint32_t) ECMA_BIG_UINT_BITWISE_DECREASE_RIGHT;
+     return ecma_bigint_bitwise_op (operation_and_options, right_p, left_p);
+   }
+ 
+@@ -1633,7 +1633,7 @@ ecma_bigint_or (ecma_value_t left_value, /**< left BigInt value */
+ 
+     /* x | (-y) == x | ~(y-1) == ~((y-1) &~ x) == -(((y-1) &~ x) + 1) */
+     uint32_t operation_and_options =
+-      (ECMA_BIG_UINT_BITWISE_AND_NOT | ECMA_BIG_UINT_BITWISE_DECREASE_LEFT | ECMA_BIG_UINT_BITWISE_INCREASE_RESULT);
++      ((uint32_t) ECMA_BIG_UINT_BITWISE_AND_NOT | (uint32_t) ECMA_BIG_UINT_BITWISE_DECREASE_LEFT | (uint32_t) ECMA_BIG_UINT_BITWISE_INCREASE_RESULT);
+     return ecma_bigint_bitwise_op (operation_and_options, right_p, left_p);
+   }
+ 
+@@ -1641,13 +1641,13 @@ ecma_bigint_or (ecma_value_t left_value, /**< left BigInt value */
+   {
+     /* (-x) | y == ~(x-1) | y == ~((x-1) &~ y) == -(((x-1) &~ y) + 1) */
+     uint32_t operation_and_options =
+-      (ECMA_BIG_UINT_BITWISE_AND_NOT | ECMA_BIG_UINT_BITWISE_DECREASE_LEFT | ECMA_BIG_UINT_BITWISE_INCREASE_RESULT);
++      ((uint32_t) ECMA_BIG_UINT_BITWISE_AND_NOT | (uint32_t) ECMA_BIG_UINT_BITWISE_DECREASE_LEFT | (uint32_t) ECMA_BIG_UINT_BITWISE_INCREASE_RESULT);
+     return ecma_bigint_bitwise_op (operation_and_options, left_p, right_p);
+   }
+ 
+   /* (-x) | (-y) == ~(x-1) | ~(y-1) == ~((x-1) & (y-1)) = -(((x-1) & (y-1)) + 1) */
+   uint32_t operation_and_options =
+-    (ECMA_BIG_UINT_BITWISE_AND | ECMA_BIG_UINT_BITWISE_DECREASE_BOTH | ECMA_BIG_UINT_BITWISE_INCREASE_RESULT);
++    ((uint32_t) ECMA_BIG_UINT_BITWISE_AND | (uint32_t) ECMA_BIG_UINT_BITWISE_DECREASE_BOTH | (uint32_t) ECMA_BIG_UINT_BITWISE_INCREASE_RESULT);
+   return ecma_bigint_bitwise_op (operation_and_options, left_p, right_p);
+ } /* ecma_bigint_or */
+ 
+@@ -1683,7 +1683,7 @@ ecma_bigint_xor (ecma_value_t left_value, /**< left BigInt value */
+ 
+     /* x ^ (-y) == x ^ ~(y-1) == ~(x ^ (y-1)) == -((x ^ (y-1)) + 1) */
+     uint32_t operation_and_options =
+-      (ECMA_BIG_UINT_BITWISE_XOR | ECMA_BIG_UINT_BITWISE_DECREASE_RIGHT | ECMA_BIG_UINT_BITWISE_INCREASE_RESULT);
++      ((int) ECMA_BIG_UINT_BITWISE_XOR | (int) ECMA_BIG_UINT_BITWISE_DECREASE_RIGHT | (int) ECMA_BIG_UINT_BITWISE_INCREASE_RESULT);
+     return ecma_bigint_bitwise_op (operation_and_options, left_p, right_p);
+   }
+ 
+@@ -1691,7 +1691,7 @@ ecma_bigint_xor (ecma_value_t left_value, /**< left BigInt value */
+   {
+     /* (-x) | y == ~(x-1) ^ y == ~((x-1) ^ y) == -(((x-1) ^ y) + 1) */
+     uint32_t operation_and_options =
+-      (ECMA_BIG_UINT_BITWISE_XOR | ECMA_BIG_UINT_BITWISE_DECREASE_LEFT | ECMA_BIG_UINT_BITWISE_INCREASE_RESULT);
++      ((int) ECMA_BIG_UINT_BITWISE_XOR | (int) ECMA_BIG_UINT_BITWISE_DECREASE_LEFT | (int) ECMA_BIG_UINT_BITWISE_INCREASE_RESULT);
+     return ecma_bigint_bitwise_op (operation_and_options, left_p, right_p);
+   }
+ 
+diff --git a/jerry-core/ecma/operations/ecma-regexp-object.c b/jerry-core/ecma/operations/ecma-regexp-object.c
+index e5b276ae..5e8f2251 100644
+--- a/jerry-core/ecma/operations/ecma-regexp-object.c
++++ b/jerry-core/ecma/operations/ecma-regexp-object.c
+@@ -164,7 +164,7 @@ ecma_op_regexp_alloc (ecma_object_t *ctr_obj_p) /**< constructor object pointer
+   ecma_value_t status = ecma_builtin_helper_def_prop (new_object_p,
+                                                       ecma_get_magic_string (LIT_MAGIC_STRING_LASTINDEX_UL),
+                                                       ecma_make_uint32_value (0),
+-                                                      ECMA_PROPERTY_FLAG_WRITABLE | JERRY_PROP_SHOULD_THROW);
++                                                      (uint32_t) ECMA_PROPERTY_FLAG_WRITABLE | (uint32_t) JERRY_PROP_SHOULD_THROW);
+ 
+   JERRY_ASSERT (ecma_is_value_true (status));
+ 
+diff --git a/jerry-core/ecma/operations/ecma-typedarray-object.c b/jerry-core/ecma/operations/ecma-typedarray-object.c
+index 40b42bb6..c455dc92 100644
+--- a/jerry-core/ecma/operations/ecma-typedarray-object.c
++++ b/jerry-core/ecma/operations/ecma-typedarray-object.c
+@@ -741,7 +741,7 @@ ecma_typedarray_helper_is_typedarray (ecma_builtin_id_t builtin_id) /**< the bui
+ ecma_builtin_id_t
+ ecma_typedarray_helper_get_prototype_id (ecma_typedarray_type_t typedarray_id) /**< the id of the typedarray **/
+ {
+-  return (ecma_builtin_id_t) (ECMA_FIRST_TYPEDARRAY_BUILTIN_PROTOTYPE_ID + typedarray_id);
++  return (ecma_builtin_id_t) ((uint32_t) ECMA_FIRST_TYPEDARRAY_BUILTIN_PROTOTYPE_ID + (uint32_t) typedarray_id);
+ } /* ecma_typedarray_helper_get_prototype_id */
+ 
+ /**
+@@ -752,7 +752,7 @@ ecma_typedarray_helper_get_prototype_id (ecma_typedarray_type_t typedarray_id) /
+ ecma_builtin_id_t
+ ecma_typedarray_helper_get_constructor_id (ecma_typedarray_type_t typedarray_id) /**< the id of the typedarray **/
+ {
+-  return (ecma_builtin_id_t) (ECMA_FIRST_TYPEDARRAY_BUILTIN_ROUTINE_ID + typedarray_id);
++  return (ecma_builtin_id_t) ((uint32_t) ECMA_FIRST_TYPEDARRAY_BUILTIN_ROUTINE_ID + (uint32_t) typedarray_id);
+ } /* ecma_typedarray_helper_get_constructor_id */
+ 
+ /**
+diff --git a/jerry-port/win/jerry-port-win-date.c b/jerry-port/win/jerry-port-win-date.c
+index 91aee326..35e55482 100644
+--- a/jerry-port/win/jerry-port-win-date.c
++++ b/jerry-port/win/jerry-port-win-date.c
+@@ -46,7 +46,7 @@
+ static void
+ unix_time_to_filetime (double t, LPFILETIME ft_p)
+ {
+-  LONGLONG ll = (LONGLONG) t * TICKS_PER_MS + UNIX_EPOCH_IN_TICKS;
++  LONGLONG ll = (LONGLONG) t * (LONGLONG) TICKS_PER_MS + (LONGLONG) UNIX_EPOCH_IN_TICKS;
+ 
+   /* FILETIME values before the epoch are invalid. */
+   if (ll < 0)
+@@ -69,7 +69,7 @@ filetime_to_unix_time (LPFILETIME ft_p)
+   ULARGE_INTEGER date;
+   date.HighPart = ft_p->dwHighDateTime;
+   date.LowPart = ft_p->dwLowDateTime;
+-  return (double) (((LONGLONG) date.QuadPart - UNIX_EPOCH_IN_TICKS) / TICKS_PER_MS);
++  return (double) (((LONGLONG) date.QuadPart - (LONGLONG) UNIX_EPOCH_IN_TICKS) / (LONGLONG) TICKS_PER_MS);
+ } /* filetime_to_unix_time */
+ 
+ /**

+ 46 - 0
packages/j/jerryscript/xmake.lua

@@ -0,0 +1,46 @@
+package("jerryscript")
+    set_homepage("https://jerryscript.net")
+    set_description("Ultra-lightweight JavaScript engine for the Internet of Things.")
+    set_license("Apache-2.0")
+
+    add_urls("https://github.com/jerryscript-project/jerryscript.git")
+
+    add_versions("2024.12.03", "c509a06669bd39301fdf0d36305a69689f51919e")
+
+    add_patches("2024.12.03", "patches/2024.12.03/enum.patch", "91a69eacb49d9c7cc0302060787fe514fa53790858579bc32e326d991436bbaa")
+
+    add_configs("shared", {description = "Build shared library.", default = false, type = "boolean", readonly = true})
+    add_configs("cli", {description = "Build jerry command line tool", default = false, type = "boolean"})
+
+    add_deps("cmake")
+
+    if on_check then
+        on_check("linux", function (package)
+            assert(not package:has_tool("cxx", "clang", "clangxx"), "package(jerryscript): Linux Clang is not supported.")
+        end)
+    end
+
+    on_install("!mingw and !macosx", function (package)
+        local configs = {
+            "-DJERRY_CMDLINE=" .. (package:config("cli") and "ON" or "OFF"),
+            "-DCMAKE_POLICY_DEFAULT_CMP0057=NEW",
+        }
+        table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
+        table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
+        if package:is_plat("windows") then
+            table.insert(configs, "-DENABLE_STATIC_CRT=" .. (package:has_runtime("MT", "MTd") and "ON" or "OFF"))
+            if package:config("shared") then
+                table.insert(configs, "-DCMAKE_WINDOWS_EXPORT_ALL_SYMBOLS=ON")
+            end
+        end
+        import("package.tools.cmake").install(package, configs)
+    end)
+
+    on_test(function (package)
+        assert(package:check_cxxsnippets({test = [[
+            #include <jerryscript.h>
+            void test() {
+                jerry_init(JERRY_INIT_EMPTY);
+            }
+        ]]}, {configs = {languages = "c99"}}))
+    end)