Skip to content

Commit

Permalink
feat: xmake | support plugin installation and packaging (Starfield-Re…
Browse files Browse the repository at this point in the history
…verse-Engineering#288)

- when you build (or run `xmake install`) it will search for the
environment variable `XSE_SF_MODS_PATH` or `XSE_SF_GAME_PATH` and copy
install files (by default ".dll" and ".pdb") to the root paths listed.
More files can be added using `add_installfiles`.
  - the install path above can be overwritten using `set_installdir`
- when you run `xmake package` it will package the same files from above
into a zip archive named after the target and the version.
- these events can be overwritten on a per-target basis if you wish to
make your own install/package logic.
  • Loading branch information
qudix authored Oct 11, 2024
1 parent c224e53 commit 9e7a5d4
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 2 deletions.
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

0 comments on commit 9e7a5d4

Please sign in to comment.