Skip to content

Commit

Permalink
fix toolchain
Browse files Browse the repository at this point in the history
  • Loading branch information
PoloNX committed Aug 26, 2024
1 parent 515b453 commit 0832a95
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 22 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/switch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ jobs:
run: xmake repo --update --root && xmake repo -u --root && dkp-pacman -Rs --noconfirm switch-tinyxml2

- name: Configure xmake and install dependencies
run: xmake f --yes -p switch -m ${{ matrix.mode }} -a aarch64 --toolchain=devkita64 -vD --root
run: xmake f --yes -p cross -m ${{ matrix.mode }} -a aarch64 --toolchain=devkita64 -vD --root

- name: Build SimpleModDownloader
run: xmake -vD --root

- uses: actions/upload-artifact@v2
with:
name: SimpleModDownloader
path: build/switch/aarch64/debug/SimpleModDownloader.nro
path: build/cross/aarch64/debug/SimpleModDownloader.nro


4 changes: 2 additions & 2 deletions toolchain/check.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
-- import("lib.detect.find_tool")

function main(toolchain)
if not is_plat("switch") then
cprint("Use switch platform")
if not is_plat("cross") then
cprint("Use cross platform")
return
end

Expand Down
59 changes: 52 additions & 7 deletions toolchain/devkitA64.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,46 @@
local triple = "aarch64-unknown-none-elf"

local buildflags = {
"-mcpu=cortex-a57", -- Utiliser uniquement -mcpu
"-mtune=cortex-a57",
"-ftls-model=local-exec",
"-ffunction-sections",
"-fdata-sections",
"-fstack-protector-strong",
"-fPIC",
"-D__SWITCH__=1",
"-D__SWITCH=1",
"-DLIBNX_NO_DEPRECATION",
"-D_GNU_SOURCE=1",
"-D_LIBC",
"-D_NEWLIB_VERSION=4.3.0",
"-D__NEWLIB__=4"
}

local sharedlinkflags = {
"-Wl,-Bdynamic",
"-fPIC",
"-Wl,--gc-sections",
"-Wl,-z,text",
"-Wl,--build-id=sha1",
"-Wl,--no-dynamic-linker",
"-Wl,--as-needed",
"-Wl,--eh-frame-hdr",
"-fvisibility=hidden"
}

local executablelinkflags = {
"-Wl,-Bsymbolic",
"-fPIE",
"-Wl,-pie",
"-Wl,--gc-sections",
"-Wl,-z,text",
"-Wl,--build-id=sha1",
"-Wl,--no-dynamic-linker",
"-Wl,--as-needed",
"-Wl,--eh-frame-hdr",
"-fvisibility=hidden",
}

toolchain("devkita64")
add_defines("__SWITCH__")
Expand All @@ -22,19 +63,23 @@ toolchain("devkita64")
set_toolset("ranlib", "aarch64-none-elf-ranlib")
set_toolset("as", "aarch64-none-elf-gcc")

add_cxflags(buildflags)
add_asflags(buildflags)
add_ldflags(executablelinkflags)
add_shflags(sharedlinkflags)

on_check("check")

on_load(function(toolchain)
toolchain:add("defines", "SWITCH", "HAVE_LIBNX")
toolchain:add("arch", "-march=armv8-a+crc+crypto", "-mtune=cortex-a57", "-mtp=soft", "-fPIE")
toolchain:add("defines", "SWITCH", "__SWITCH__", "HAVE_LIBNX")
toolchain:add("arch", "-mcpu=cortex-a57", "-mtune=cortex-a57", "-mtp=soft", "-fPIE")

toolchain:add("cflags", "-g", "-Wall", "-O2", "-ffunction-sections", "-fdata-sections", {force = true})
toolchain:add("cxflags", "-march=armv8-a+crc+crypto", "-mtune=cortex-a57", "-mtp=soft", "-fPIE", {force = true})
toolchain:add("cxflags", "-mcpu=cortex-a57", "-mtune=cortex-a57", "-mtp=soft", "-fPIE", {force = true})
toolchain:add("cxxflags", "-frtti", "-fexceptions", {force = true})

toolchain:add("asflags", "-g", "-march=armv8-a+crc+crypto", "-mtune=cortex-a57", "-mtp=soft", "-fPIE", {force = true})
toolchain:add("asflags", "-g", "-mcpu=cortex-a57", "-mtune=cortex-a57", "-mtp=soft", "-fPIE", {force = true})
toolchain:add("ldflags", "-specs=" .. path.join(DEVKITPRO, "/libnx/switch.specs"), "-g", "-W", "-fPIC","$(notdir $*.map)", {force = true})

-- toolchain:add("linkdirs", path.join(DEVKITPRO, "/libnx/lib"), path.join(DEVKITPRO, "/portlibs/switch/lib"))
toolchain:add("syslinks", "gcc", "c", "m", "nx")
end)
toolchain:add("syslinks", "gcc", "c", "m")
end)
56 changes: 46 additions & 10 deletions toolchain/switch.lua
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,54 @@ rule("switch")

import("core.base.option")
import("core.project.config")
import("lib.detect.find_program")
import("lib.detect.find_tool")

local args = table.wrap(option.get("arguments"))

if #args > 0 then
for i, arg in ipairs(args) do
cprint("${color.build.target}Argument[%d]: ${clear}%s", i, arg)
if arg:startswith("--nx=") then
ip_addr = arg:sub(6)
break
end
end
end


if ip_addr ~= nil and ip_addr ~= "" then
if find_tool("nxlink", {check = "--help"}) then
nxlink = "nxlink"
else
nxlink = "nxlink"
cprint("You must add nxlink to your PATH variable")
end

local target_file = target:targetfile()
local executable = target_file .. ".nro"
local nxlink_args = {"-a", ip_addr, "-s", executable}

cprint("Launching from nxlink " .. executable)

if(os.isexec("Ryujinx")) then
ryujinx = "Ryujinx"
elseif(os.isexec("ryujinx")) then
ryujinx = "ryujinx"
local args_str = table.concat(nxlink_args, " ")

os.execv(nxlink, nxlink_args)
else
cprint("${color.build.target}Please install Ryujinx first")
ryujinx = "ryujinx"
end
if find_tool("ryujinx", {program = "ryujinx"}) then
ryujinx = "ryujinx"
elseif find_tool("Ryujinx", {program = "Ryujinx"}) then
ryujinx = "Ryujinx"
else
cprint("You must add ryujinx to your PATH variable")
return
end

local target_file = target:targetfile()
local executable = target_file .. ".nro"
local target_file = target:targetfile()
local executable = target_file .. ".nro"

os.run(ryujinx, {executable})

cprint("Launching " .. executable)
os.execv(ryujinx, {executable})
end
end)
2 changes: 1 addition & 1 deletion xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ add_requires("borealis", {repo = "switch-repo"}, "deko3d", "libcurl", "libarchiv

target("SimpleModDownloader")
set_kind("binary")
if not is_plat("switch") then
if not is_plat("cross") then
return
end

Expand Down

0 comments on commit 0832a95

Please sign in to comment.