-
Notifications
You must be signed in to change notification settings - Fork 2
formula: add TsudaKageyu/minhook #215
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import "strings" | ||
|
|
||
| // Upstream mixes unprefixed GNU-style tags (1.2.1.1, 1.2.1A) with v-prefixed | ||
| // releases (v1.3.4). Strip an optional v, then compare as Go semver. | ||
| func normalize(version string) string { | ||
| return "v" + strings.trimPrefix(version, "v") | ||
| } | ||
|
|
||
| compareVer (a, b) => { | ||
| return semver.Compare(normalize(a.Version), normalize(b.Version)) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| import ( | ||
| "os" | ||
| "path/filepath" | ||
| ) | ||
|
|
||
| const consumerSource = `#include "MinHook.h" | ||
|
|
||
| int main(void) { | ||
| MH_Initialize(); | ||
| MH_Uninitialize(); | ||
| return 0; | ||
| } | ||
| ` | ||
|
|
||
| id "TsudaKageyu/minhook" | ||
|
|
||
| fromVer "v1.3.4" | ||
|
|
||
| defaults { | ||
| "shared": "OFF", | ||
| } | ||
|
|
||
| filter => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [P2] filter accepts all OS targets for a Windows-only library The |
||
| for name, values in target.options { | ||
| if name != "shared" { | ||
| return false | ||
| } | ||
| for value in values { | ||
| if value != "ON" && value != "OFF" { | ||
| return false | ||
| } | ||
| } | ||
| } | ||
| return true | ||
| } | ||
|
|
||
| onBuild ctx => { | ||
| installDir := ctx.outputDir | ||
| shared := target.options["shared"][0] == "ON" | ||
|
|
||
| // WIN32 Release/RelWithDebInfo/MinSizeRel postfixes are .x64 / .x32; | ||
| // Debug adds a trailing d. Non-Windows CMake uses libminhook, but this | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [P3] Comment mentions Debug 'd' postfix but only Release is built The comment says "Debug adds a trailing d", but |
||
| // package is a Windows x86/x86_64 API hooking library. | ||
| lib := "minhook.x64" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [P1] Lib name hardcoded to Windows .x64/.x32 for all targets The comment on the lines above states "Non-Windows CMake uses libminhook", yet This name flows into the generated pkgconfig |
||
| if values := target.require["arch"]; values.len > 0 { | ||
| arch := values[0] | ||
| if arch == "386" || arch == "x86" || arch == "i386" { | ||
| lib = "minhook.x32" | ||
| } | ||
| } | ||
|
|
||
| c := cmake.new(ctx.SourceDir, filepath.join(ctx.SourceDir, "_build"), installDir) | ||
| c.buildType "Release" | ||
| c.define "CMAKE_POLICY_VERSION_MINIMUM", "3.5" | ||
| c.defineBool "BUILD_SHARED_LIBS", shared | ||
| c.configure | ||
| c.build | ||
| c.install | ||
|
|
||
| licenseDir := filepath.join(installDir, "licenses") | ||
| os.mkdirAll(licenseDir, 0o755)! | ||
| os.writeFile(filepath.join(licenseDir, "LICENSE.txt"), os.readFile(filepath.join(ctx.SourceDir, "LICENSE.txt"))!, 0o644)! | ||
|
|
||
| pcDir := filepath.join(installDir, "lib", "pkgconfig") | ||
| os.mkdirAll(pcDir, 0o755)! | ||
| pc := `prefix=$${pcfiledir}/../.. | ||
| exec_prefix=$${prefix} | ||
| libdir=$${prefix}/lib | ||
| includedir=$${prefix}/include | ||
|
|
||
| Name: minhook | ||
| Description: The Minimalistic x86/x64 API Hooking Library for Windows | ||
| Version: 1.3.4 | ||
| Libs: -L$${libdir} -l` + lib + ` | ||
| Cflags: -I$${includedir} | ||
| ` | ||
| os.writeFile(filepath.join(pcDir, "minhook.pc"), []byte(pc), 0o644)! | ||
|
|
||
| pkgconfig.use installDir | ||
| ctx.setMetadata pkgconfig.lookup("minhook")! | ||
| } | ||
|
|
||
| onTest ctx => { | ||
| installDir := ctx.outputDir | ||
| testDir := filepath.join(ctx.SourceDir, "_llar_consumer") | ||
| os.mkdirAll(testDir, 0o755)! | ||
|
|
||
| sourcePath := filepath.join(testDir, "consumer.c") | ||
| os.writeFile(sourcePath, []byte(consumerSource), 0o644)! | ||
|
|
||
| pkgconfig.use installDir | ||
| flagsFile := filepath.join(testDir, "minhook.flags") | ||
| os.writeFile(flagsFile, []byte(pkgconfig.lookup("minhook")!), 0o644)! | ||
|
|
||
| binary := filepath.join(testDir, "consumer") | ||
| cc! sourcePath, "-o", binary, "@"+flagsFile | ||
|
|
||
| if target.options["shared"][0] == "ON" { | ||
| os.setenv("LD_LIBRARY_PATH", filepath.join(installDir, "lib"))! | ||
| os.setenv("DYLD_LIBRARY_PATH", filepath.join(installDir, "lib"))! | ||
| } | ||
|
Comment on lines
+98
to
+101
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [P2] Shared build sets only LD_LIBRARY_PATH/DYLD, not Windows PATH For a shared Windows build the runtime DLL is located via the loader |
||
| exec! binary | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| { | ||
| "path": "TsudaKageyu/minhook", | ||
| "deps": {} | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[P3] normalize does not guard against invalid semver tags
normalizeunconditionally does"v" + trimPrefix(version, "v"). For the upstream GNU-style tags the comment cites (e.g.1.2.1A), this yieldsv1.2.1A, which is not valid Go semver —semver.Comparetreats invalid versions as lowest, so such tags sort below everything. Not a problem for selecting the currentv1.3.4default, but worth a note if those older tags ever need to order correctly.