Browse Source

luajit: Add LuaJIT with RISC-V support

This LuaJIT package uses LuaJIT repo from PLCT, which have RISC-V support.
The build is tested on StarFive VisionFive2 using LuaJIT-test-cleanup,
failing 3/508 tests (test 363 365 366).

Signed-off-by: Jun Yuan Tan <junyuan.tan@starfivetech.com>
Jun Yuan Tan 8 months ago
parent
commit
f3f4cf9bcf

+ 31 - 0
recipes-devtools/luajit/luajit-riscv/0001-Do-not-strip-automatically-this-leaves-the-stripping.patch

@@ -0,0 +1,31 @@
+From 6ab806a3d6ab11828918b94d407c9dcd99272a5a Mon Sep 17 00:00:00 2001
+From: Khem Raj <raj.khem@gmail.com>
+Date: Fri, 10 May 2013 10:42:45 -0700
+Subject: [PATCH] Do not strip automatically, this leaves the stripping busines
+ to OE
+
+Upstream-Status: Inappropriate [OE-Specific]
+
+Signed-off-by: Khem Raj <raj.khem@gmail.com>
+
+---
+ src/Makefile | 2 --
+ 1 file changed, 2 deletions(-)
+
+diff --git a/src/Makefile b/src/Makefile
+index 108825e4..dcaf6c30 100644
+--- a/src/Makefile
++++ b/src/Makefile
+@@ -730,12 +730,10 @@ $(LUAJIT_A): $(LJVMCORE_O)
+ $(LUAJIT_SO): $(LJVMCORE_O)
+ 	$(E) "DYNLINK   $@"
+ 	$(Q)$(TARGET_LD) $(TARGET_ASHLDFLAGS) -o $@ $(LJVMCORE_DYNO) $(TARGET_ALIBS)
+-	$(Q)$(TARGET_STRIP) $@
+ 
+ $(LUAJIT_T): $(TARGET_O) $(LUAJIT_O) $(TARGET_DEP)
+ 	$(E) "LINK      $@"
+ 	$(Q)$(TARGET_LD) $(TARGET_ALDFLAGS) -o $@ $(LUAJIT_O) $(TARGET_O) $(TARGET_ALIBS)
+-	$(Q)$(TARGET_STRIP) $@
+ 	$(E) "OK        Successfully built LuaJIT"
+ 
+ ##############################################################################

+ 22 - 0
recipes-devtools/luajit/luajit-riscv/0002-original-patch-riscv-cross-compile-support.patch.patch

@@ -0,0 +1,22 @@
+From 8ec291a9b65e5503952b502fc7e8eb4ad07ceeca Mon Sep 17 00:00:00 2001
+From: OpenEmbedded <oe.patch@oe>
+Date: Wed, 23 Aug 2023 05:37:49 +0000
+Subject: [PATCH] %% original patch: riscv-cross-compile-support.patch
+
+---
+ src/lj_arch.h | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/src/lj_arch.h b/src/lj_arch.h
+index 453414f3..09284829 100644
+--- a/src/lj_arch.h
++++ b/src/lj_arch.h
+@@ -447,7 +447,7 @@
+ #error "No support for RISC-V 32"
+ 
+ #elif LUAJIT_TARGET == LUAJIT_ARCH_RISCV64
+-#if defined(__riscv_float_abi_double)
++#if defined(__riscv_float_abi_double) | 1
+ 
+ #define LJ_ARCH_NAME		"riscv64"
+ #define LJ_ARCH_BITS		64

+ 19 - 0
recipes-devtools/luajit/luajit-riscv/clang.patch

@@ -0,0 +1,19 @@
+clang pretends to be gcc 4.2.0 which is a big lie when it comes
+to features, its same as latest gcc
+
+Signed-off-by: Khem Raj <raj.khem@gmail.com>
+Upstream-Status: Pending
+
+Index: LuaJIT-2.0.5/src/lj_arch.h
+===================================================================
+--- LuaJIT-2.0.5.orig/src/lj_arch.h
++++ LuaJIT-2.0.5/src/lj_arch.h
+@@ -436,7 +436,7 @@
+ #endif
+ #endif
+ #elif !LJ_TARGET_PS3
+-#if (__GNUC__ < 4) || ((__GNUC__ == 4) && __GNUC_MINOR__ < 3)
++#if (__GNUC__ < 4) || ((__GNUC__ == 4) && __GNUC_MINOR__ < 3) && !defined(__clang__)
+ #error "Need at least GCC 4.3 or newer"
+ #endif
+ #endif

+ 13 - 0
recipes-devtools/luajit/luajit-riscv/riscv-cross-compile-support.patch

@@ -0,0 +1,13 @@
+diff --git a/src/lj_arch.h b/src/lj_arch.h
+index 453414f3..09284829 100644
+--- a/src/lj_arch.h
++++ b/src/lj_arch.h
+@@ -447,7 +447,7 @@
+ #error "No support for RISC-V 32"
+
+ #elif LUAJIT_TARGET == LUAJIT_ARCH_RISCV64
+-#if defined(__riscv_float_abi_double)
++#if defined(__riscv_float_abi_double) | 1
+
+ #define LJ_ARCH_NAME           "riscv64"
+ #define LJ_ARCH_BITS           64

+ 104 - 0
recipes-devtools/luajit/luajit-riscv_git.bb

@@ -0,0 +1,104 @@
+SUMMARY = "Just-In-Time Compiler for Lua"
+LICENSE = "MIT"
+LIC_FILES_CHKSUM = "file://COPYRIGHT;md5=23d6278200de9b48fd1439f80507cba8"
+HOMEPAGE = "http://luajit.org"
+
+SRC_URI = "git://github.com/infiWang/LuaJIT.git;protocol=https;branch=riscv \
+           file://0001-Do-not-strip-automatically-this-leaves-the-stripping.patch \
+           file://riscv-cross-compile-support.patch \
+           "
+
+# Set PV to a version tag and date (YYMMDD) associated with SRCREV if it is later.
+PV = "2.1.0~beta3-210112"
+SRCREV = "e65b5fe899d88d898ab1176c93a89d313cc6fcfd"
+
+S = "${WORKDIR}/git"
+
+inherit pkgconfig binconfig siteinfo
+
+BBCLASSEXTEND = "native"
+
+# http://luajit.org/install.html#cross
+# Host luajit needs to be compiled with the same pointer size
+# If you want to cross-compile to any 32 bit target on an x64 OS,
+# you need to install the multilib development package (e.g.
+# libc6-dev-i386 on Debian/Ubuntu) and build a 32 bit host part
+# (HOST_CC="gcc -m32").
+BUILD_CC_ARCH:append = " ${@['-m32',''][d.getVar('SITEINFO_BITS') != '32']}"
+
+# The lua makefiles expect the TARGET_SYS to be from uname -s
+# Values: Windows, Linux, Darwin, iOS, SunOS, PS3, GNU/kFreeBSD
+LUA_TARGET_OS = "Unknown"
+LUA_TARGET_OS:darwin = "Darwin"
+LUA_TARGET_OS:linux = "Linux"
+LUA_TARGET_OS:linux-gnueabi = "Linux"
+LUA_TARGET_OS:mingw32 = "Windows"
+
+# We don't want the lua buildsystem's compiler optimizations, or its
+# stripping, and we don't want it to pick up CFLAGS or LDFLAGS, as those apply
+# to both host and target compiles
+EXTRA_OEMAKE = "\
+    Q= E='@:' \
+    \
+    CCOPT= CCOPT_x86= CFLAGS= LDFLAGS= TARGET_STRIP='@:' \
+    \
+    'TARGET_SYS=${LUA_TARGET_OS}' \
+    \
+    'CC=${CC}' \
+    'TARGET_AR=${AR} rcus' \
+    'TARGET_CFLAGS=${CFLAGS}' \
+    'TARGET_LDFLAGS=${LDFLAGS}' \
+    'TARGET_SHLDFLAGS=${LDFLAGS}' \
+    'HOST_CC=${BUILD_CC}' \
+    'HOST_CFLAGS=${BUILD_CFLAGS}' \
+    \
+    'PREFIX=${prefix}' \
+    'MULTILIB=${baselib}' \
+    'LDCONFIG=:' \
+"
+
+do_compile () {
+    oe_runmake
+}
+
+# There's INSTALL_LIB and INSTALL_SHARE also, but the lua binary hardcodes the
+# '/share' and '/' + LUA_MULTILIB paths, so we don't want to break those
+# expectations.
+EXTRA_OEMAKEINST = "\
+    'DESTDIR=${D}' \
+    'INSTALL_BIN=${D}${bindir}' \
+    'INSTALL_INC=${D}${includedir}/luajit-$(MAJVER).$(MINVER)' \
+    'INSTALL_MAN=${D}${mandir}/man1' \
+"
+do_install () {
+    oe_runmake ${EXTRA_OEMAKEINST} install
+    rmdir ${D}${datadir}/lua/5.* \
+          ${D}${datadir}/lua \
+          ${D}${libdir}/lua/5.* \
+          ${D}${libdir}/lua
+    cd ${D}/usr/bin
+    ln -sf ./luajit-2.1.0-beta3 luajit
+}
+
+PACKAGES += 'luajit-common'
+
+# See the comment for EXTRA_OEMAKEINST. This is needed to ensure the hardcoded
+# paths are packaged regardless of what the libdir and datadir paths are.
+FILES:${PN} += "${prefix}/${baselib} ${prefix}/share"
+FILES:${PN} += "${libdir}/libluajit-5.1.so.2 \
+    ${libdir}/libluajit-5.1.so.${PV} \
+"
+FILES:${PN}-dev += "${libdir}/libluajit-5.1.a \
+    ${libdir}/libluajit-5.1.so \
+    ${libdir}/pkgconfig/luajit.pc \
+"
+FILES:luajit-common = "${datadir}/${BPN}-${PV}"
+
+# mips64/ppc/ppc64/riscv64/riscv32 is not supported in this release
+COMPATIBLE_HOST:mipsarchn32 = "null"
+COMPATIBLE_HOST:mipsarchn64 = "null"
+COMPATIBLE_HOST:powerpc = "null"
+COMPATIBLE_HOST:powerpc64 = "null"
+COMPATIBLE_HOST:powerpc64le = "null"
+COMPATIBLE_HOST:riscv64 = "riscv.*"
+COMPATIBLE_HOST:riscv32 = "null"