Admenri / rguplayer

The Universal Ruby Game Engine (RGU) Project
BSD 3-Clause "New" or "Revised" License
21 stars 6 forks source link

[Enhancement] Ruby Submodule #15

Open Nathan-MV opened 4 days ago

Nathan-MV commented 4 days ago

Wondering if you could create a fork of Ruby and apply your patches to it in a commit in the branch ruby_3_2 and use your fork as a submodule in RGU

.gitmodules

[submodule "third_party/ruby"]
    path = third_party/ruby
    url = https://github.com/Admenri/ruby
    branch = ruby_3_2
Admenri commented 4 days ago

CRuby doesn't support CMake build, I had to build ruby ​​separately and then add the lib to CMake on Windows. I just need to install ruby dev package on unix-like. So there is no need to add another submodule. Maybe I'll add a submodule once I fully adapt CRuby to CMake, but for now it seems easier to replace GLES renderer with the Vulkan API. The most troublesome part of the entire engine is CRuby :(

Nathan-MV commented 3 days ago

I tried it myself in Ruby 3.3.3 (branch ruby_3_3), didn't have much success, but i hope it helps you in some way

cmake_minimum_required(VERSION 3.5)

# Optimization and Debug Flags
set(OPT_FLAGS "-O3 -fno-fast-math")
set(DEBUG_FLAGS "-ggdb3")

# Warning Flags
set(WARN_FLAGS "-Wall -Wextra -Wdeprecated-declarations -Wdiv-by-zero -Wduplicated-cond -Wimplicit-function-declaration -Wimplicit-int -Wpointer-arith -Wwrite-strings -Wold-style-definition -Wimplicit-fallthrough=0 -Wmissing-noreturn -Wno-cast-function-type -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-packed-bitfield-compat -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wsuggest-attribute=format -Wsuggest-attribute=noreturn -Wunused-variable -Wmisleading-indentation -Wundef")

# Set CFLAGS
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OPT_FLAGS} ${DEBUG_FLAGS} ${WARN_FLAGS}")

# Set LDFLAGS
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -L. -fstack-protector-strong -rdynamic -Wl,-export-dynamic -Wl,--compress-debug-sections=zlib")

set(COMMONOBJS
    array.c
    ast.c
    bignum.c
    class.c
    compar.c
    compile.c
    complex.c
    cont.c
    debug.c
    debug_counter.c
    dir.c
    dln_find.c
    encoding.c
    enum.c
    enumerator.c
    error.c
    eval.c
    file.c
    gc.c
    hash.c
    inits.c
    io.c
    io_buffer.c
    iseq.c
    load.c
    marshal.c
    math.c
    memory_view.c
    #rjit.c
    #rjit_c.c
    node.c
    node_dump.c
    numeric.c
    object.c
    pack.c
    #parse.c
    parser_st.c
    proc.c
    process.c
    ractor.c
    random.c
    range.c
    rational.c
    re.c
    regcomp.c
    regenc.c
    regerror.c
    regexec.c
    regparse.c
    regsyntax.c
    ruby.c
    ruby_parser.c
    scheduler.c
    shape.c
    signal.c
    sprintf.c
    st.c
    strftime.c
    string.c
    struct.c
    symbol.c
    thread.c
    time.c
    transcode.c
    util.c
    variable.c
    version.c
    vm.c
    vm_backtrace.c
    vm_dump.c
    vm_sync.c
    vm_trace.c
    weakmap.c
)

set(ENCODING_FILES
    enc/ascii.c
    enc/us_ascii.c
    enc/unicode.c
    enc/utf_8.c
)

set(PRISM_FILES
    #prism/api_node.c
    prism/api_pack.c
    prism/diagnostic.c
    prism/encoding.c
    prism/extension.c
    #prism/node.c
    prism/options.c
    prism/pack.c
    #prism/prettyprint.c
    prism/regexp.c
    #prism/serialize.c
    #prism/token_type.c
    prism/util/pm_buffer.c
    prism/util/pm_char.c
    prism/util/pm_constant_pool.c
    prism/util/pm_list.c
    prism/util/pm_memchr.c
    prism/util/pm_newline_list.c
    prism/util/pm_state_stack.c
    prism/util/pm_string.c
    prism/util/pm_string_list.c
    prism/util/pm_strncasecmp.c
    prism/util/pm_strpbrk.c
    prism/prism.c
    prism_init.c
)

set(YJIT_FILES
    yjit.c
)

set(MISSING
    missing/setproctitle.c
    missing/strlcat.c
    missing/strlcpy.c
    missing/crypt.c
)

# Define the library to be built and its sources
add_library(ruby STATIC ${COMMONOBJS} ${PRISM_FILES} ${YJIT_FILES} ${ENCODING_FILES} ${MISSING})

# Registering include directories
target_include_directories(ruby
                           PUBLIC
                           $<INSTALL_INTERFACE:include>
                           $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
                           PRIVATE
                           ${CMAKE_CURRENT_SOURCE_DIR}
                           include
                           )

# Copy the header files to the build directory for convenience
file(COPY include/ruby DESTINATION "include")
file(COPY include/ruby.h DESTINATION "include")
Nathan-MV commented 3 days ago

I also made a working external project for it, it will fail because of --without-ext, but i made a patch for it https://github.com/Nathan-MV/ruby/commit/96a10854c88a028cd33733022c21d7c7dee6fb49

cmake_minimum_required(VERSION 3.5)
project(Game VERSION 0.1.0)

include(ProcessorCount)
include(ExternalProject)

# Set C++ standard and required flag
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# Set Directories
set(SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src)
set(THIRD_PARTY_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party)
set(RUBY_DIR ${THIRD_PARTY_DIR}/ruby)
set(RUBY_BUILD_DIR ${CMAKE_BINARY_DIR}/third_party/ruby)
set(RUBY_VERSION "3.3.0")

# Determine the number of processors
ProcessorCount(N)
if(NOT N EQUAL 0)
  set(CTEST_BUILD_FLAGS -j${N})
  set(ctest_test_args ${ctest_test_args} PARALLEL_LEVEL ${N})
endif()

# Ruby configuration
set(RUBY_ARGS
    --prefix=${RUBY_BUILD_DIR}
    --enable-install-static-library
    --with-static-linked-ext
    --without-valgrind
    --without-jemalloc
    --without-gmp
    --without-git
    --without-ext
    --disable-rubygems
    --disable-gems
    --disable-rpath
    --disable-install-doc
    --disable-install-rdoc
    --disable-install-capi
)

# ExternalProject setup for Ruby
ExternalProject_Add(
    ruby
    PREFIX ${RUBY_BUILD_DIR}
    SOURCE_DIR ${RUBY_DIR}
    CONFIGURE_COMMAND ${RUBY_DIR}/autogen.sh && ${RUBY_DIR}/configure -C ${RUBY_ARGS} ${RUBY_FLAGS}
    BUILD_COMMAND make -j${N}
    INSTALL_COMMAND make install
    BUILD_BYPRODUCTS ${RUBY_BUILD_DIR}/lib/libruby-static.a
)

add_dependencies(game ruby)
target_include_directories(game PRIVATE ${RUBY_BUILD_DIR}/include/ruby-${RUBY_VERSION} 
                                        ${RUBY_BUILD_DIR}/include/ruby-${RUBY_VERSION}/${CMAKE_SYSTEM_PROCESSOR}-${LOWERCASE_SYSTEM_NAME}/ruby
)
target_link_libraries(game PRIVATE ${RUBY_BUILD_DIR}/lib/libruby-static.a -lz -lcrypt)
Admenri commented 2 days ago

Thanks, I will try to import it after upgrading the GLES rendering to D3D12/Vulkan rendering. If there is any progress, I will update here.