Skip to content
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

feat: xmake | support plugin installation and packaging #288

Merged
merged 3 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 60 additions & 2 deletions xmake-extra.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ constinit auto SFSEPlugin_Version = []() noexcept {
return v;
}();]]

local PLUGIN_VERSION_FILE = [[
local PLUGIN_RC_FILE = [[
#include <winres.h>

1 VERSIONINFO
Expand Down Expand Up @@ -77,6 +77,15 @@ rule("commonlibsf.plugin")
target:set("arch", "x64")
target:set("kind", "shared")

target:add("installfiles", target:targetfile(), { prefixdir = "SFSE/Plugins" })
target:add("installfiles", target:symbolfile(), { prefixdir = "SFSE/Plugins" })

if os.getenv("XSE_SF_MODS_PATH") then
target:set("installdir", path.join(os.getenv("XSE_SF_MODS_PATH"), target:name()))
elseif os.getenv("XSE_SF_GAME_PATH") then
target:set("installdir", path.join(os.getenv("XSE_SF_GAME_PATH"), "Data"))
end

local conf = target:extraconf("rules", "commonlibsf.plugin")
local conf_dir = path.join(target:autogendir(), "rules", "commonlibsf", "plugin")

Expand Down Expand Up @@ -151,5 +160,54 @@ rule("commonlibsf.plugin")
end

add_file("plugin.cpp", PLUGIN_FILE)
add_file("version.rc", PLUGIN_VERSION_FILE)
add_file("version.rc", PLUGIN_RC_FILE)
end)

on_install(function(target)
local srcfiles, dstfiles = target:installfiles()
if srcfiles and #srcfiles > 0 and dstfiles and #dstfiles > 0 then
for idx, srcfile in ipairs(srcfiles) do
os.trycp(srcfile, dstfiles[idx])
end
end
end)

on_package(function(target)
import("core.project.config")
import("core.project.project")
import("utils.archive")

local archive_name = target:name() .. "-" .. (target:version() or "0.0.0") .. ".zip"
print("packing %s .. ", archive_name)

local root_dir = path.join(os.tmpdir(), "packages", project.name() or "", target:name())
os.tryrm(root_dir)

local srcfiles, dstfiles = target:installfiles(path.join(root_dir, "Data"))
if srcfiles and #srcfiles > 0 and dstfiles and #dstfiles > 0 then
for idx, srcfile in ipairs(srcfiles) do
os.trycp(srcfile, dstfiles[idx])
end
else
return
end

local archive_path = path.join(config.buildir(), "packages", archive_name)
local old_dir = os.cd(root_dir)
local archive_files = os.files("**")
os.cd(old_dir)
archive.archive(path.absolute(archive_path), archive_files, { curdir = root_dir })
end)

after_build(function(target)
import("core.project.depend")
import("core.project.project")
import("core.project.task")

depend.on_changed(function()
local srcfiles, dstfiles = target:installfiles()
if srcfiles and #srcfiles > 0 and dstfiles and #dstfiles > 0 then
task.run("install")
end
end, { files = project.allfiles(), changed = target:is_rebuilt()})
end)
3 changes: 3 additions & 0 deletions xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ target("commonlibsf")
-- set target kind
set_kind("static")

-- set build by default
set_default(os.scriptdir() == os.projectdir())

-- add packages
add_packages("spdlog", { public = true })

Expand Down