Skip to content

Commit

Permalink
grab changes from old branch
Browse files Browse the repository at this point in the history
  • Loading branch information
berdal84 committed Nov 27, 2024
1 parent f53300c commit 51472d5
Show file tree
Hide file tree
Showing 8 changed files with 136 additions and 142 deletions.
7 changes: 1 addition & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ jobs:
env:
# Those are read by rake script
BUILD_TYPE: debug # release|debug
INSTALL_DIR: out
VERBOSE: true
steps:
- name: Git Checkout
Expand All @@ -44,12 +43,8 @@ jobs:
shell: bash
run: rake test --trace

- name: Pack
shell: bash
run: rake pack --trace

- name: Binary Artifact
uses: actions/upload-artifact@v4
with:
name: nodable-${{ runner.os }}
path: ${{env.INSTALL_DIR}}/*
path: build-${{env.BUILD_TYPE}}/nodable
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ _screenshots/
/bin/
/cmake-**
/rake-**
/build-**
/.idea
.gitconfig
.cache
41 changes: 41 additions & 0 deletions rake/_cmake.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

CMakeTarget = Struct.new(
:name,
:path,
keyword_init: true # If the optional keyword_init keyword argument is set to true, .new takes keyword arguments instead of normal arguments.
)

def tasks_for_cmake_target( target )
build_dir = "#{BUILD_DIR}/#{target.name}"

task :rebuild => [:clean, :build]

task :clean do
FileUtils.rm_f build_dir
end

task :build do
if Dir.exist? build_dir
FileUtils.rm_rf build_dir
end
if BUILD_TYPE == "release"
config = "Release"
else
config = "Debug"
end
directory build_dir # ensure folder exists
sh "cmake -S #{target.path} -B #{build_dir} -DCMAKE_OSX_DEPLOYMENT_TARGET=#{MACOSX_VERSION_MIN}" # configure
# TODO: we should precise which target to install
sh "cmake --build #{build_dir} --config #{config}"
end

task :install => :build do
# TODO: we should precise which target to install
cmd = "cmake --install #{build_dir}"
if BUILD_OS_LINUX or BUILD_OS_MACOS
sh "sudo #{cmd}"
else
sh cmd
end
end
end
40 changes: 14 additions & 26 deletions rake/_utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
BUILD_TYPE = (ENV["BUILD_TYPE"] || "release").downcase
BUILD_TYPE_RELEASE = BUILD_TYPE == "release"
BUILD_TYPE_DEBUG = !BUILD_TYPE_RELEASE
BUILD_DIR = ENV["BUILD_DIR"] || "rake-build-#{BUILD_TYPE}"
BUILD_DIR = ENV["BUILD_DIR"] || "build-#{BUILD_TYPE}"
OBJ_DIR = ENV["OBJ_DIR"] || "#{BUILD_DIR}/obj"
LIB_DIR = ENV["LIB_DIR"] || "#{BUILD_DIR}/lib"
DEP_DIR = ENV["DEP_DIR"] || "#{BUILD_DIR}/dep"
INSTALL_DIR = ENV["INSTALL_DIR"] || "out"
BUILD_OS_LINUX = BUILD_OS.include?("linux")
BUILD_OS_MACOS = BUILD_OS.include?("darwin")
BUILD_OS_WINDOWS = BUILD_OS.include?("windows") || BUILD_OS.include?("mingw32")
GITHUB_ACTIONS = ENV["GITHUB_ACTIONS"]
MACOSX_VERSION_MIN = "12.0" # GitHub Actions does not support 11.0

if VERBOSE
system "echo Ruby version: && ruby -v"
Expand Down Expand Up @@ -123,12 +123,6 @@ def copy_assets_to( destination, target )
FileUtils.copy_entry( source, "#{destination}/#{target.asset_folder_path}")
end

def _pack_to( destination, target )
copy_assets_to( destination, target )
FileUtils.mkdir_p destination
FileUtils.copy( get_binary_build_path( target ), destination)
end

def get_library_name( target )
"#{LIB_DIR}/lib#{target.name.ext(".a")}"
end
Expand All @@ -143,14 +137,18 @@ def build_static_library( target )
sh "llvm-ar r #{binary} #{objects}", verbose: VERBOSE
end

def get_binary_build_path( target )
def get_build_dir( target )
"#{BUILD_DIR}/#{target.name}"
end

def get_binary( target )
"#{get_build_dir(target)}/#{target.name}"
end

def build_executable_binary( target )

objects = get_objects_to_link(target).join(" ")
binary = get_binary_build_path( target )
binary = get_binary( target )
linker_flags = target.linker_flags.join(" ")

FileUtils.mkdir_p File.dirname(binary)
Expand Down Expand Up @@ -194,42 +192,32 @@ def compile_file(src, target)

def tasks_for_target(target)

binary = get_binary_build_path(target)
objects = get_objects(target)

desc "Clean #{target.name}'s intermediate files"
task :clean do
FileUtils.rm_f objects
FileUtils.rm_f get_objects(target)
end

if target.type == TargetType::EXECUTABLE
desc "Run the #{target.name}"
task :run => [ :build ] do
sh "./#{get_binary_build_path(target)}"
end
end

if target.type == TargetType::EXECUTABLE or target.type == TargetType::STATIC_LIBRARY
desc "Copy in #{INSTALL_DIR} the files to distribute the software"
task :pack do
_pack_to( "#{INSTALL_DIR}", target)
sh "./#{get_binary(target)}"
end
end

desc "Clean and build target #{target.name}"
task :rebuild => [:clean, :build]

desc "Compile #{target.name}"
task :build => binary do
task :build => get_binary(target) do
if target.asset_folder_path
puts "#{target.name} Copying assets ..."
copy_assets_to("#{BUILD_DIR}", target )
copy_assets_to( get_build_dir(target), target )
puts "#{target.name} Copying assets OK"
end
end


file binary => :link do
file get_binary(target) => :link do
case target.type
when TargetType::EXECUTABLE
puts "#{target.name} Linking ..."
Expand All @@ -249,7 +237,7 @@ def tasks_for_target(target)

multitask :link => get_objects_to_link( target )

objects.each_with_index do |obj, index|
get_objects(target).each_with_index do |obj, index|
src = obj_to_src( obj, target )
file obj => src do |task|
puts "#{target.name} | Compiling #{src} ..."
Expand Down
3 changes: 2 additions & 1 deletion rake/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@ def new_target_from_base(name, type)
]
elsif BUILD_OS_MACOS
target.linker_flags |= [
"-mmacosx-version-min=#{MACOSX_VERSION_MIN}",
"-framework CoreFoundation",
"-framework Cocoa"
]
]
end

target.asset_folder_path = "assets" # a single folder
Expand Down
164 changes: 66 additions & 98 deletions rake/libs.rb
Original file line number Diff line number Diff line change
@@ -1,129 +1,97 @@
require_relative "base"
require_relative "_utils"
require_relative "_cmake"

#---------------------------------------------------------------------------
$whereami = new_target_from_base("whereami", TargetType::OBJECTS)
$whereami.sources |= FileList[
"libs/whereami/src/whereami.c"
]
#---------------------------------------------------------------------------
$gl3w = new_target_from_base("gl3w", TargetType::OBJECTS)
$gl3w.sources |= FileList[
"libs/gl3w/GL/gl3w.c"
]
#---------------------------------------------------------------------------
$lodepng = new_target_from_base("lodepng", TargetType::OBJECTS)
$lodepng.sources |= FileList[
"libs/lodepng/lodepng.cpp"
]
#---------------------------------------------------------------------------
$imgui = new_target_from_base("imgui", TargetType::OBJECTS)
$imgui.sources |= FileList[
"libs/imgui/imgui.cpp",
"libs/imgui/imgui_demo.cpp",
"libs/imgui/imgui_draw.cpp",
"libs/imgui/imgui_tables.cpp",
"libs/imgui/imgui_widgets.cpp",
"libs/imgui/misc/freetype/imgui_freetype.cpp",
"libs/imgui/backends/imgui_impl_sdl.cpp",
"libs/imgui/backends/imgui_impl_opengl3.cpp",
]
#---------------------------------------------------------------------------
$text_editor = new_target_from_base("text_editor", TargetType::OBJECTS)
$text_editor.sources |= FileList[
"libs/ImGuiColorTextEdit/TextEditor.cpp"
]
#---------------------------------------------------------------------------
task :libs => 'libs:build'
namespace :libs do

task :build => [
# compile .a/.lib first
'freetype:install',
'googletest:install',
'nfd:install',
'cpptrace:install',
'sdl:install',
# then .o
'whereami:build',
'gl3w:build',
'imgui:build',
'lodepng:build',
'text_editor:build',
]

namespace :gl3w do
$gl3w = new_target_from_base("gl3w", TargetType::OBJECTS)
$gl3w.sources |= FileList[
"libs/gl3w/GL/gl3w.c"
]
tasks_for_target( $gl3w )
end

namespace :text_editor do
$text_editor = new_target_from_base("text_editor", TargetType::OBJECTS)
$text_editor.sources |= FileList[
"libs/ImGuiColorTextEdit/TextEditor.cpp"
]
tasks_for_target( $text_editor )
end

namespace :lodepng do
$lodepng = new_target_from_base("lodepng", TargetType::OBJECTS)
$lodepng.sources |= FileList[
"libs/lodepng/lodepng.cpp"
]
tasks_for_target( $lodepng )
end

namespace :imgui do
$imgui = new_target_from_base("imgui", TargetType::OBJECTS)
$imgui.sources |= FileList[
"libs/imgui/imgui.cpp",
"libs/imgui/imgui_demo.cpp",
"libs/imgui/imgui_draw.cpp",
"libs/imgui/imgui_tables.cpp",
"libs/imgui/imgui_widgets.cpp",
"libs/imgui/misc/freetype/imgui_freetype.cpp",
"libs/imgui/backends/imgui_impl_sdl.cpp",
"libs/imgui/backends/imgui_impl_opengl3.cpp",
]
tasks_for_target( $imgui )
end

namespace :whereami do
$whereami = new_target_from_base("whereami", TargetType::OBJECTS)
$whereami.sources |= FileList[
"libs/whereami/src/whereami.c"
]
tasks_for_target( $whereami )
end

#---------------------------------------------------------------------------
task :build => [
'nfd',
'cpptrace',
'sdl',
'freetype',
'gl3w:build',
'imgui:build',
'lodepng:build',
'text_editor:build',
'googletest',
]
#---------------------------------------------------------------------------
task :nfd => [] do
commands = [
"rm -rf libs/nativefiledialog-extended/build",
'cd libs/nativefiledialog-extended',
'mkdir -p build',
'cd build',
'cmake .. -DCMAKE_BUILD_TYPE=Release',
'cmake --build .'
]
system commands.join(" && ")
namespace :nfd do
nfd = CMakeTarget.new(name: "nfd", path: "libs/nativefiledialog-extended" )
tasks_for_cmake_target( nfd )
end
#---------------------------------------------------------------------------
task :cpptrace => [] do
commands = [
"cd libs/cpptrace",
"mkdir -p build && cd build",
"cmake .. -DCMAKE_BUILD_TYPE=Release",
"make -j",
"sudo make install"
]
system commands.join(" && ")

namespace :cpptrace do
cpptrace = CMakeTarget.new(name: "cpptrace", path: "libs/cpptrace" )
tasks_for_cmake_target( cpptrace )
end
#---------------------------------------------------------------------------
task :sdl => [] do
commands = [
'cd libs/SDL',
'mkdir -p build',
'cd build',
'../configure',
'make',
'sudo make install'
]
system commands.join(" && ")

namespace :sdl do
sdl = CMakeTarget.new(name: "sdl", path: "libs/SDL" )
tasks_for_cmake_target( sdl )
end
#---------------------------------------------------------------------------
task :freetype => [] do
commands = [
'cd libs/freetype',
'mkdir -p build && cd build',
'cmake ..',
'make',
'sudo make install'
]
system commands.join(" && ")

namespace :googletest do
googletest = CMakeTarget.new(name: "googletest", path: "libs/googletest" )
tasks_for_cmake_target( googletest )
end

#---------------------------------------------------------------------------
task :googletest => [] do
commands = [
'cd libs/googletest',
'mkdir -p build && cd build',
'cmake ..',
'make',
'sudo make install',
]
system commands.join(" && ")

namespace :freetype do
freetype = CMakeTarget.new(name: "freetype", path: "libs/freetype" )
tasks_for_cmake_target( freetype )
end
#--------------------------------------------------------------------------
end # namespace libs

end # namespace libs
Loading

0 comments on commit 51472d5

Please sign in to comment.