forked from sinkingsugar/NativePath
-
Notifications
You must be signed in to change notification settings - Fork 2
revise lua script to use zig tool chain for stride #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jazzay
wants to merge
3
commits into
stride3d:master
Choose a base branch
from
jazzay:zig-cross
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -251,3 +251,4 @@ tools/WindowsUWP/x86/libCompilerRt.lib | |
| *.a | ||
| *.bc | ||
| *.lib | ||
| *.o | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| ffi = require 'ffi' | ||
|
|
||
| local SLASH = "/" | ||
| if ffi.os == "Windows" then SLASH = "\\" end | ||
|
|
||
| -- Code by David Kastrup | ||
| require "lfs" | ||
|
|
||
| function dirtree(dir) | ||
| assert(dir and dir ~= "", "directory parameter is missing or empty") | ||
| if string.sub(dir, -1) == SLASH then | ||
| dir=string.sub(dir, 1, -2) | ||
| end | ||
|
|
||
| local function yieldtree(dir) | ||
| for entry in lfs.dir(dir) do | ||
| if entry ~= "." and entry ~= ".." then | ||
| entry=dir..SLASH..entry | ||
| local attr=lfs.attributes(entry) | ||
| coroutine.yield(entry,attr) | ||
| if attr.mode == "directory" then | ||
| yieldtree(entry) | ||
| end | ||
| end | ||
| end | ||
| end | ||
|
|
||
| return coroutine.wrap(function() yieldtree(dir) end) | ||
| end | ||
|
|
||
| function string.ends(String,End) | ||
| return End=='' or string.sub(String,-string.len(End))==End | ||
| end | ||
|
|
||
| function string.starts(String,Start) | ||
| return string.sub(String,1,string.len(Start))==Start | ||
| end | ||
|
|
||
| local exclude_dirs = {} | ||
| local exclude_files = {} | ||
| local directory = "" | ||
|
|
||
| -- We may need to support both build approaches for now (iOS / android) | ||
| common_flags = "-ffast-math -fno-threadsafe-statics -nostdlibinc -nobuiltininc -nostdinc++ -Wno-macro-redefined -DFLOAT_APPROX -I.."..SLASH.."NativePath -I.."..SLASH.."NativePath"..SLASH.."standard" | ||
| zig_common_flags = "-Wno-ignored-attributes -Wno-delete-non-virtual-dtor -Wno-macro-redefined -fno-rtti -fno-exceptions" | ||
|
|
||
| objs = {} | ||
| cfiles = {} | ||
| cppfiles = {} | ||
| hfiles = {} | ||
| debug = false | ||
| is_verbose = false | ||
| is_shared = false | ||
| platform = "windows" | ||
| outputName = "lib" | ||
|
|
||
| function table.contains(table, element) | ||
| for _, value in pairs(table) do | ||
| if string.starts(element, value) then | ||
| return true | ||
| end | ||
| end | ||
| return false | ||
| end | ||
|
|
||
| for i,v in ipairs(arg) do | ||
| if v == "debug" then | ||
| debug = true | ||
| elseif string.starts(v, "-I") then | ||
jazzay marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| local includeDir = string.sub(v, 3) | ||
| common_flags = common_flags.." -I"..includeDir | ||
| zig_common_flags = zig_common_flags.." -I"..includeDir | ||
| elseif string.starts(v, "-D") then | ||
| local includeDir = string.sub(v, 3) | ||
| common_flags = common_flags.." -D"..includeDir | ||
| zig_common_flags = zig_common_flags.." -D"..includeDir | ||
| elseif string.starts(v, "-n") then | ||
| local n = string.sub(v, 3) | ||
| outputName = n | ||
| elseif string.starts(v, "-E") then | ||
| local n = string.sub(v, 3) | ||
| table.insert(exclude_dirs, n) | ||
| elseif string.starts(v, "-e") then | ||
| local n = string.sub(v, 3) | ||
| table.insert(exclude_files, n) | ||
| elseif v == "--verbose" or v == "-v" then | ||
| is_verbose = true | ||
| elseif v == "--shared" then | ||
| is_shared = true | ||
| elseif string.starts(v, "-p") then | ||
| platform = string.sub(v, 3) | ||
| else | ||
| directory = v | ||
| end | ||
| end | ||
|
|
||
| for filename, attr in dirtree(directory) do | ||
jazzay marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if table.contains(exclude_dirs, filename) ~= true and table.contains(exclude_files, filename) ~= true then | ||
| if string.ends(filename, ".c") and attr.mode == "file" and table.contains(exclude_files, filename) ~= true then | ||
| table.insert(cfiles, filename) | ||
| if is_verbose == true then | ||
| print("Keeping: "..filename) | ||
| end | ||
| elseif string.ends(filename, ".cpp") and attr.mode == "file" and table.contains(exclude_files, filename) ~= true then | ||
| table.insert(cppfiles, filename) | ||
| if is_verbose == true then | ||
| print("Keeping: "..filename) | ||
| end | ||
| end | ||
| elseif is_verbose == true then | ||
| print("Excluding: "..filename) | ||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,149 @@ | ||
| -- Special trick to load the parent path of the current script. | ||
| local parent_path = string.match(arg[0], "(.-)([^\\/]-%.?([^%.\\/]*))$") | ||
| -- Add that path to the list of places where lua will load packages | ||
| package.path = package.path .. ";" .. parent_path .. "?.lua" | ||
| -- Load the driver package which will take care of the command line arguments and other settings | ||
| -- as here we just focus on the code necessary to build our supported platforms | ||
| require "np-build-driver-stride" | ||
|
|
||
| local debug_flags = "-O0 -g" | ||
| local debug_ms_flags = "-Od" | ||
| local release_flags = "-O3" | ||
| local release_ms_flags = "-O2" | ||
|
|
||
| -- NOTE: This is a cleaned up version of np-build.lua specific to the needs of Stride, and uses Zig CC cross compiler instead of clang, etc. | ||
| -- We can port over other commands from np-build.lua as needed. | ||
|
|
||
| -- we require Zig v0.12.0 reachable from your path. this only works on Windows for now | ||
| local zig = "zig.exe" | ||
|
|
||
| -- For testing alternative versions of Zig, etc | ||
| -- local zig = "c:\\devtools\\zig-0.11.0\\zig.exe" | ||
|
|
||
| function BuildZig(cfile, target, platform_args) | ||
| local flags = "" | ||
| if debug then flags = debug_flags else flags = release_flags end | ||
|
|
||
| local cmd = zig.." cc "..platform_args.." -target "..target.." "..zig_common_flags.." "..flags.." -o "..cfile..".o ".." -c "..cfile | ||
| if is_verbose == true then | ||
| print(cmd) | ||
| end | ||
|
|
||
| os.execute(cmd) | ||
| table.insert(objs, cfile..".o") | ||
| end | ||
|
|
||
| function LinkZigStatic(target, folder, ext) | ||
| local objs_str = "" | ||
| for i, o in ipairs(objs) do | ||
| objs_str = objs_str..o.." " | ||
| end | ||
| local cmd = zig.." build-lib -static -target "..target.." -femit-bin="..folder.."\\"..outputName.."."..ext.." "..objs_str | ||
| if is_verbose == true then | ||
| print(cmd) | ||
| end | ||
| os.execute(cmd) | ||
| end | ||
|
|
||
| -- TODO: Unused for now | ||
| -- function LinkZigShared(target, folder, ext) | ||
| -- local objs_str = "" | ||
| -- for i, o in ipairs(objs) do | ||
| -- objs_str = objs_str..o.." " | ||
| -- end | ||
|
|
||
| -- local cmd = zig.." build-lib -shared -target "..target.." -femit-bin="..folder.."\\"..outputName.."."..ext.." "..objs_str | ||
| -- if is_verbose == true then | ||
| -- print(cmd) | ||
| -- end | ||
| -- os.execute(cmd) | ||
| -- end | ||
|
|
||
| if platform == "windows" then | ||
| lfs.mkdir("libs") | ||
| lfs.chdir("libs") | ||
| lfs.mkdir("win-x86") | ||
| lfs.mkdir("win-x64") | ||
| lfs.mkdir("win-arm64") | ||
| lfs.chdir("..") | ||
|
|
||
| objs = {} | ||
| print ("Building Windows x86...") | ||
| for i,f in ipairs(cfiles) do | ||
| BuildZig(f, "x86-windows-gnu", "-DNP_WIN32 -m32 -gcodeview -fno-ms-extensions") | ||
| end | ||
| LinkZigStatic("x86-windows-gnu", "libs\\win-x86", "lib") | ||
|
|
||
| objs = {} | ||
| print ("Building Windows x64...") | ||
| for i,f in ipairs(cfiles) do | ||
| BuildZig(f, "x86_64-windows-gnu", "-DNP_WIN32 -m64 -gcodeview -fno-ms-extensions") | ||
| end | ||
| LinkZigStatic("x86_64-windows-gnu", "libs\\win-x64", "lib") | ||
|
|
||
| objs = {} | ||
| print ("Building Windows arm64...") | ||
| for i,f in ipairs(cfiles) do | ||
| BuildZig(f, "aarch64-windows-gnu", "-DNP_WIN32 -m64 -gcodeview -fno-ms-extensions") | ||
| end | ||
| LinkZigStatic("aarch64-windows-gnu", "libs\\win-arm64", "lib") | ||
|
|
||
| elseif platform == "ios" then | ||
| -- TODO: port over to Zig | ||
|
|
||
| elseif platform == "macos" then | ||
| lfs.mkdir("libs") | ||
| lfs.chdir("libs") | ||
| lfs.mkdir("osx-x64") | ||
| lfs.mkdir("osx-arm64") | ||
| lfs.chdir("..") | ||
|
|
||
| objs = {} | ||
| print ("Building macOS x64...") | ||
| for i,f in ipairs(cfiles) do | ||
| BuildZig(f, "x86_64-macos", "-DNP_MACOS -mmacosx-version-min=10.5") | ||
| end | ||
| LinkZigStatic("x86_64-macos", "libs\\osx-x64", "a") | ||
|
|
||
| objs = {} | ||
| print ("Building macOS arm64...") | ||
| for i,f in ipairs(cfiles) do | ||
| BuildZig(f, "aarch64-macos", "-DNP_MACOS -mmacosx-version-min=10.5") | ||
| end | ||
| LinkZigStatic("aarch64-macos", "libs\\osx-arm64", "a") | ||
|
|
||
| -- lfs.mkdir("macOS") | ||
|
|
||
| if is_verbose == true then | ||
jazzay marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| print(cmd) | ||
| end | ||
| -- Not sure we need lipo anymore | ||
| -- os.execute("lipo macOS\\"..outputName.."_i386.a macOS\\"..outputName.."_x86_64.a -create -output macOS\\"..outputName..".a") | ||
| -- os.remove("macOS\\"..outputName.."_i386.a") | ||
| -- os.remove("macOS\\"..outputName.."_x86_64.a") | ||
|
|
||
| elseif platform == "linux" then | ||
| lfs.mkdir("libs") | ||
| lfs.chdir("libs") | ||
| lfs.mkdir("linux-x64") | ||
| lfs.mkdir("linux-arm64") | ||
| lfs.chdir("..") | ||
|
|
||
| objs = {} | ||
| print ("Building Linux x64...") | ||
| for i,f in ipairs(cfiles) do | ||
| BuildZig(f, "x86_64-linux-gnu", "-DNP_LINUX -fPIC") | ||
| end | ||
| LinkZigStatic("x86_64-linux-gnu", "libs\\linux-x64", "a") | ||
|
|
||
| objs = {} | ||
| print ("Building Linux arm64...") | ||
| for i,f in ipairs(cfiles) do | ||
| BuildZig(f, "aarch64-linux-gnu", "-DNP_LINUX -fPIC") | ||
| end | ||
| LinkZigStatic("aarch64-linux-gnu", "libs\\linux-arm64", "a") | ||
|
|
||
| elseif platform == "android" then | ||
| -- TODO: port over to Zig | ||
|
|
||
| end | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.