diff options
| author | ruki <[email protected]> | 2025-12-05 22:38:22 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2025-12-05 22:38:22 +0800 |
| commit | b25ae9c831a536b17a913b7af2494f08c9c98c4d (patch) | |
| tree | 8aef67d1fc1b975a7e3bff048fd2848410050e8c | |
| parent | e688a7bd853c49ec10aa8656e704c2115ea5e14c (diff) | |
format code
| -rw-r--r-- | xmake/modules/core/tools/go.lua | 39 | ||||
| -rw-r--r-- | xmake/rules/go/xmake.lua | 4 | ||||
| -rw-r--r-- | xmake/toolchains/go/xmake.lua | 12 |
3 files changed, 10 insertions, 45 deletions
diff --git a/xmake/modules/core/tools/go.lua b/xmake/modules/core/tools/go.lua index 90431320c..a0a3809d5 100644 --- a/xmake/modules/core/tools/go.lua +++ b/xmake/modules/core/tools/go.lua @@ -32,23 +32,15 @@ end -- make the optimize flag function nf_optimize(self, level) - -- Go build flags for optimization local maps = { none = "-gcflags=-N" } return maps[level] end --- make the symbol flag -function nf_symbol(self, level, opt) - -- Go doesn't use separate symbol flags like C/C++ - return -end -- make the strip flag function nf_strip(self, level) - -- Go uses -ldflags="-s -w" for stripping - -- -ldflags needs to be passed as separate arguments: -ldflags and the value local maps = { debug = {"-ldflags", "-s"} , all = {"-ldflags", "-s -w"} @@ -56,12 +48,6 @@ function nf_strip(self, level) return maps[level] end --- make the includedir flag -function nf_includedir(self, dir) - -- Go doesn't use -I flags, but we can use build tags or build constraints - return -end - -- make the sysincludedir flag function nf_sysincludedir(self, dir) return nf_includedir(self, dir) @@ -69,9 +55,6 @@ end -- make the linkdir flag function nf_linkdir(self, dir) - -- Go uses -L flag for linker search paths via -ldflags - -- -ldflags needs to be passed as separate arguments: -ldflags and the value - -- Note: -L must be inside the -ldflags value, not as a separate argument return {"-ldflags", "-L " .. dir} end @@ -79,34 +62,20 @@ end -- Modern Go uses "go build" command for both compilation and linking function buildargv(self, sourcefiles, targetkind, targetfile, flags) local argv = {"build"} - - -- add build flags if flags then table.join2(argv, flags) end - - -- set output file table.insert(argv, "-o") table.insert(argv, targetfile) - + -- for static library, use buildmode=archive if targetkind == "static" then table.insert(argv, "-buildmode=archive") end - + -- add source files (Go supports building from source file list) - -- The caller should change to the source directory before calling build - if sourcefiles and #sourcefiles > 0 then - -- convert source files to relative paths from current directory - -- or use absolute paths if needed - for _, sourcefile in ipairs(sourcefiles) do - table.insert(argv, sourcefile) - end - else - -- fallback to current package if no source files - table.insert(argv, ".") - end - + table.join2(argv, sourcefiles) + return self:program(), argv end diff --git a/xmake/rules/go/xmake.lua b/xmake/rules/go/xmake.lua index 25ab5af56..820df80c3 100644 --- a/xmake/rules/go/xmake.lua +++ b/xmake/rules/go/xmake.lua @@ -31,9 +31,5 @@ rule("go.build") on_build("build.target") rule("go") - - -- add build rules add_deps("go.build") - - -- inherit links and linkdirs of all dependent targets by default add_deps("utils.inherit.links") diff --git a/xmake/toolchains/go/xmake.lua b/xmake/toolchains/go/xmake.lua index d12fe0dc2..d7ae96f8c 100644 --- a/xmake/toolchains/go/xmake.lua +++ b/xmake/toolchains/go/xmake.lua @@ -34,30 +34,30 @@ toolchain("go") -- on load on_load(function (toolchain) import("private.tools.go.goenv") - + -- set GOOS and GOARCH for cross-compilation local goos = goenv.GOOS(toolchain:plat()) if goos then toolchain:add("runenvs", "GOOS", goos) end - + local goarch = goenv.GOARCH(toolchain:arch()) if goarch then toolchain:add("runenvs", "GOARCH", goarch) end - + -- Set CGO_ENABLED=0 by default for better cross-compilation support -- Users can override this if they need CGO if not os.getenv("CGO_ENABLED") then toolchain:add("runenvs", "CGO_ENABLED", "0") end - + -- Disable Go modules mode to use GOPATH mode -- This allows Go to find packages using GOPATH if not os.getenv("GO111MODULE") then toolchain:add("runenvs", "GO111MODULE", "off") end - + -- Set GOPATH to project directory if not already set -- This allows Go to find packages in the project if not os.getenv("GOPATH") then @@ -66,7 +66,7 @@ toolchain("go") toolchain:add("runenvs", "GOPATH", projectdir) end end - + -- set default flags toolchain:set("gcldflags", "") toolchain:set("gcarflags", "") |
