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

libmem: add package #5430

Open
wants to merge 7 commits into
base: dev
Choose a base branch
from
Open
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
148 changes: 148 additions & 0 deletions packages/l/libmem/xmake.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
package("libmem")

set_homepage("https://github.com/rdbo/libmem")
set_description("Cross-platform game hacking library for C, C++, Rust, and Python, supporting process/memory hacking, hooking, detouring, and DLL/SO injection.")
set_license("AGPL-3.0")

add_urls("https://github.com/rdbo/libmem/archive/refs/tags/$(version).tar.gz", "https://github.com/rdbo/libmem.git", {submodules = true})
add_versions("5.0.2", "99adea3e86bd3b83985dce9076adda16968646ebd9d9316c9f57e6854aeeab9c")
add_deps("cmake")


on_install(function (package)

local configs = {}

io.writefile("xmake.lua", [[
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

复杂的配置,挪到 port/xmake.lua 独立文件维护,参考其他包

Copy link
Author

@luadebug luadebug Oct 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🏳️🏳️🏳️
I wish I could do that, but libmem s repository refers to non-existing repositories branches I believe. Legacy
It will take a lot of time to port complete meaningless dependencies onto xrepo in that case.
Maybe I have misunderstood your review, idea behind context is to make some file to store stuff that is being used by io.writefile???

set_languages("c17", "c++20")

if is_plat("windows") then
set_toolset("make", "nmake") -- Use NMAKE as the make tool
end

-- Set options
option("build_tests", {description = "Build tests", default = false, showmenu = true})
option("deep_tests", {description = "Enable deep testing", default = false, showmenu = true})
option("build_static", {description = "Build static library", default = true, showmenu = true})

set_arch(os.arch())

-- Set Capstone, Keystone, and LLVM directories (adjust as needed)
local external_dependencies_dir = path.join(os.projectdir(), "external")
local capstone_dir = path.join(external_dependencies_dir, "capstone")
local keystone_dir = path.join(external_dependencies_dir, "keystone")
local llvm_dir = path.join(external_dependencies_dir, "llvm")

-- Set external dependencies
add_includedirs(path.join(capstone_dir, "include"))
add_includedirs(path.join(keystone_dir, "include"))
add_includedirs(path.join(llvm_dir, "include"))

-- Define source directories
local libmem_dir = os.projectdir()
local internal_dir = path.join(libmem_dir, "internal")
local common_dir = path.join(libmem_dir, "src", "common")

-- Add source files based on platform
local libmem_src = {}

if is_plat("windows") then
libmem_src = {
path.join(libmem_dir, "src/win/*.c"),
path.join(common_dir, "*.c"),
path.join(common_dir, "*.cpp"),
path.join(internal_dir, "winutils/*.c"),
path.join(internal_dir, "demangler/*.cpp")
}
elseif is_plat("linux") then
if is_arch("x86_64") then
libmem_src = {
path.join(common_dir, "arch/x86.c"),
path.join(libmem_dir, "src/linux/ptrace/x64/*.c"),
path.join(libmem_dir, "src/linux/*.c"),
path.join(common_dir, "*.c"),
path.join(common_dir, "*.cpp"),
path.join(internal_dir, "posixutils/*.c"),
path.join(internal_dir, "elfutils/*.c"),
path.join(internal_dir, "demangler/*.cpp")
}
elseif is_arch("i386") then
libmem_src = {
path.join(common_dir, "arch/x86.c"),
path.join(libmem_dir, "src/linux/ptrace/x86/*.c"),
path.join(libmem_dir, "src/linux/*.c"),
path.join(common_dir, "*.c"),
path.join(common_dir, "*.cpp"),
path.join(internal_dir, "posixutils/*.c"),
path.join(internal_dir, "elfutils/*.c"),
path.join(internal_dir, "demangler/*.cpp")
}
end
elseif is_plat("freebsd") then
if is_arch("x86_64") then
libmem_src = {
path.join(common_dir, "arch/x86.c"),
path.join(libmem_dir, "src/freebsd/ptrace/x64/*.c"),
path.join(libmem_dir, "src/freebsd/*.c"),
path.join(common_dir, "*.c"),
path.join(common_dir, "*.cpp"),
path.join(internal_dir, "posixutils/*.c"),
path.join(internal_dir, "elfutils/*.c"),
path.join(internal_dir, "demangler/*.cpp")
}
elseif is_arch("i386") then
libmem_src = {
path.join(common_dir, "arch/x86.c"),
path.join(libmem_dir, "src/freebsd/ptrace/x86/*.c"),
path.join(libmem_dir, "src/freebsd/*.c"),
path.join(common_dir, "*.c"),
path.join(common_dir, "*.cpp"),
path.join(internal_dir, "posixutils/*.c"),
path.join(internal_dir, "elfutils/*.c"),
path.join(internal_dir, "demangler/*.cpp")
}
end
end

-- Add target for libmem
target("libmem")
if has_config("build_static") then
set_kind("static")
else
set_kind("shared")
end

add_files(libmem_src)

-- Correct the include directory to point to "include"
add_includedirs(path.join(libmem_dir, "include"), { public = true })
add_includedirs(path.join(libmem_dir, "src"))
add_includedirs(internal_dir)
add_includedirs(common_dir)

-- Link against external libraries
add_links("capstone", "keystone", "llvm")

-- Platform-specific dependencies
if is_plat("windows") then
add_syslinks("user32", "psapi", "ntdll", "shell32")
elseif is_plat("linux") then
add_syslinks("dl", "stdc++", "m")
elseif is_plat("freebsd") then
add_syslinks("dl", "kvm", "procstat", "elf", "stdc++", "m")
end

-- Define for export symbol
add_defines("LM_EXPORT")

-- Optionally build tests
if has_config("build_tests") then
target("libmem_tests")
set_kind("binary")
add_files(path.join(libmem_dir, "tests/*.cpp"))
add_deps("libmem")
end
]])

import("package.tools.xmake").install(package, configs)
end)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

缺少 on_test

Copy link
Author

@luadebug luadebug Oct 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🏳️🏳️🏳️
I do not have idea how to make a one. I think it will never find libmem/libmem.h or libmem/libmem.hpp either to start a test…

Loading