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 ce411ce
Show file tree
Hide file tree
Showing 8 changed files with 143 additions and 145 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
13 changes: 10 additions & 3 deletions rake/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ def new_target_from_base(name, type)
"--std=c++20",
"-fno-char8_t"
]

target.linker_flags |= [
"-L#{LIB_DIR}",
"-Llibs/nativefiledialog-extended/build/src",
"`pkg-config --cflags --libs freetype2`",
"`sdl2-config --cflags --libs`",
"`sdl2-config --cflags --static-libs`",
"-lnfd", # Native File Dialog
"-lGL",
"-lcpptrace -ldwarf -lz -lzstd -ldl", # https://github.com/jeremy-rifkin/cpptrace?tab=readme-ov-file#use-without-cmake
Expand All @@ -45,7 +46,7 @@ def new_target_from_base(name, type)
target.linker_flags |= [
"-framework CoreFoundation",
"-framework Cocoa"
]
]
end

target.asset_folder_path = "assets" # a single folder
Expand All @@ -64,9 +65,15 @@ def new_target_from_base(name, type)
]
end

if BUILD_OS_MACOS
target.compiler_flags |= [
"-mmacosx-version-min=#{MACOSX_VERSION_MIN}",
]
end

if BUILD_TYPE_RELEASE
target.compiler_flags |= [
"-O3"
"-O2"
]
elsif BUILD_TYPE_DEBUG
target.compiler_flags |= [
Expand Down
Loading

0 comments on commit ce411ce

Please sign in to comment.