summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2020-04-03 22:39:21 +0800
committerruki <[email protected]>2020-04-03 14:20:20 +0800
commit43c47094400aa2dc1d17628a840a58868215d6de (patch)
tree1d066318b69254ecbf8b789c02fb13e24c27514d
parent33119c0368854f19bddf128c3f43ea14e741f5c8 (diff)
add strip
-rw-r--r--xmake/actions/build/kinds/binary.lua3
-rw-r--r--xmake/actions/build/kinds/shared.lua3
-rw-r--r--xmake/actions/build/kinds/static.lua3
-rw-r--r--xmake/core/sandbox/modules/os.lua10
-rw-r--r--xmake/modules/detect/tools/find_strip.lua79
-rw-r--r--xmake/platforms/android/config.lua6
-rw-r--r--xmake/platforms/cross/config.lua8
-rw-r--r--xmake/platforms/iphoneos/config.lua6
-rw-r--r--xmake/platforms/linux/config.lua7
-rw-r--r--xmake/platforms/macosx/config.lua6
-rw-r--r--xmake/platforms/watchos/config.lua6
-rw-r--r--xmake/rules/mode/xmake.lua2
-rw-r--r--xmake/rules/utils/symbols/extract.lua74
-rw-r--r--xmake/rules/utils/symbols/xmake.lua24
14 files changed, 218 insertions, 19 deletions
diff --git a/xmake/actions/build/kinds/binary.lua b/xmake/actions/build/kinds/binary.lua
index 7b4ee23ee..5525d84cc 100644
--- a/xmake/actions/build/kinds/binary.lua
+++ b/xmake/actions/build/kinds/binary.lua
@@ -84,9 +84,6 @@ function _do_link_target(target, opt)
print(linkinst:linkcmd(objectfiles, targetfile, {linkflags = linkflags, rawargs = true}))
end
- -- flush io buffer to update progress info
- io.flush()
-
-- link it
if not option.get("dry-run") then
assert(linkinst:link(objectfiles, targetfile, {linkflags = linkflags}))
diff --git a/xmake/actions/build/kinds/shared.lua b/xmake/actions/build/kinds/shared.lua
index bec79f4fc..b4d0f208a 100644
--- a/xmake/actions/build/kinds/shared.lua
+++ b/xmake/actions/build/kinds/shared.lua
@@ -97,9 +97,6 @@ function _do_link_target(target, opt)
print(linkinst:linkcmd(objectfiles, targetfile, {linkflags = linkflags, rawargs = true}))
end
- -- flush io buffer to update progress info
- io.flush()
-
-- link it
if not option.get("dry-run") then
assert(linkinst:link(objectfiles, targetfile, {linkflags = linkflags}))
diff --git a/xmake/actions/build/kinds/static.lua b/xmake/actions/build/kinds/static.lua
index 8864f8ab4..432863bf2 100644
--- a/xmake/actions/build/kinds/static.lua
+++ b/xmake/actions/build/kinds/static.lua
@@ -93,9 +93,6 @@ function _do_link_target(target, opt)
print(linkinst:linkcmd(objectfiles, targetfile, {linkflags = linkflags, rawargs = true}))
end
- -- flush io buffer to update progress info
- io.flush()
-
-- link it
if not option.get("dry-run") then
assert(linkinst:link(objectfiles, targetfile, {linkflags = linkflags}))
diff --git a/xmake/core/sandbox/modules/os.lua b/xmake/core/sandbox/modules/os.lua
index 43899a536..6b505b43a 100644
--- a/xmake/core/sandbox/modules/os.lua
+++ b/xmake/core/sandbox/modules/os.lua
@@ -280,7 +280,9 @@ function sandbox_os.vrunv(program, argv, opt)
end
-- run it
- (option.get("verbose") and sandbox_os.execv or sandbox_os.runv)(program, argv, opt)
+ if not (opt and opt.dryrun) then
+ (option.get("verbose") and sandbox_os.execv or sandbox_os.runv)(program, argv, opt)
+ end
end
-- run command and return output and error data
@@ -410,7 +412,11 @@ function sandbox_os.vexecv(program, argv, opt)
end
-- run it
- return sandbox_os.execv(program, argv, opt)
+ if not (opt and opt.dryrun) then
+ return sandbox_os.execv(program, argv, opt)
+ else
+ return 0
+ end
end
-- match files or directories
diff --git a/xmake/modules/detect/tools/find_strip.lua b/xmake/modules/detect/tools/find_strip.lua
new file mode 100644
index 000000000..fe85cf238
--- /dev/null
+++ b/xmake/modules/detect/tools/find_strip.lua
@@ -0,0 +1,79 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed under the Apache License, Version 2.0 (the "License");
+-- you may not use this file except in compliance with the License.
+-- You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+-- Copyright (C) 2015-2020, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file find_strip.lua
+--
+
+-- imports
+import("core.tool.compiler")
+import("lib.detect.find_program")
+
+-- check strip of xcode
+function _check_strip_of_xcode(program)
+
+ -- make an stub source file
+ local objectfile = os.tmpfile() .. ".o"
+ local sourcefile = os.tmpfile() .. ".c"
+ io.writefile(sourcefile, "int test(void)\n{return 0;}")
+
+ -- compile it
+ compiler.compile(sourcefile, objectfile)
+
+ -- archive it
+ os.runv(program, {"-S", objectfile})
+
+ -- remove files
+ os.rm(objectfile)
+ os.rm(sourcefile)
+end
+
+-- find strip
+--
+-- @param opt the argument options, e.g. {version = true}
+--
+-- @return program, version
+--
+-- @code
+--
+-- local strip = find_strip()
+-- local strip, version = find_strip({program = "xcrun -sdk macosx strip", version = true})
+--
+-- @endcode
+--
+function main(opt)
+
+ -- init options
+ opt = opt or {}
+
+ -- attempt to find gnu strip first with `--version`
+ local program = find_program(opt.program or "strip", opt)
+ if not program then
+ -- find strip of xcode without `--version`
+ if is_plat("macosx", "iphoneos", "watchos") or is_host("macosx") then
+ opt.force = true
+ opt.check = _check_strip_of_xcode
+ program = find_program(opt.program or "strip", opt)
+ end
+ end
+
+ -- find program version
+ local version = nil
+ if program and opt.version then
+ version = find_programver(program, opt)
+ end
+ return program, version
+end
diff --git a/xmake/platforms/android/config.lua b/xmake/platforms/android/config.lua
index 8e1e86639..056a768e6 100644
--- a/xmake/platforms/android/config.lua
+++ b/xmake/platforms/android/config.lua
@@ -74,12 +74,13 @@ function _toolchains()
local ar = toolchain("the static library archiver")
local ex = toolchain("the static library extractor")
local ranlib = toolchain("the static library index generator")
+ local strip = toolchain("the symbols stripper")
local as = toolchain("the assember")
local rc = toolchain("the rust compiler")
local rc_ld = toolchain("the rust linker")
local rc_sh = toolchain("the rust shared library linker")
local rc_ar = toolchain("the rust static library archiver")
- local toolchains = {cc = cc, cxx = cxx, cpp = cpp, as = as, ld = ld, sh = sh, ar = ar, ex = ex, ranlib = ranlib,
+ local toolchains = {cc = cc, cxx = cxx, cpp = cpp, as = as, ld = ld, sh = sh, ar = ar, ex = ex, ranlib = ranlib, strip = strip,
rc = rc, ["rc-ld"] = rc_ld, ["rc-sh"] = rc_sh, ["rc-ar"] = rc_ar}
-- init the c compiler
@@ -113,6 +114,9 @@ function _toolchains()
-- init the static library index generator
ranlib:add({name = "ranlib", cross = cross, pathes = gcc_toolchain_bin}, "ranlib")
+ -- init the symbols stripper
+ strip:add({name = "strip", cross = cross, pathes = gcc_toolchain_bin}, "strip")
+
-- init the rust compiler and linker
rc:add("$(env RC)", "rustc")
rc_ld:add("$(env RC)", "rustc")
diff --git a/xmake/platforms/cross/config.lua b/xmake/platforms/cross/config.lua
index a360dfaa8..b410ddbef 100644
--- a/xmake/platforms/cross/config.lua
+++ b/xmake/platforms/cross/config.lua
@@ -66,9 +66,10 @@ function _toolchains()
local sh = toolchain("the shared library linker")
local ar = toolchain("the static library archiver")
local ex = toolchain("the static library extractor")
+ local strip = toolchain("the symbols stripper")
local ranlib = toolchain("the static library index generator")
local as = toolchain("the assember")
- local toolchains = {cc = cc, cxx = cxx, cpp = cpp, as = as, ld = ld, sh = sh, ar = ar, ex = ex, ranlib = ranlib}
+ local toolchains = {cc = cc, cxx = cxx, cpp = cpp, as = as, ld = ld, sh = sh, ar = ar, ex = ex, ranlib = ranlib, strip = strip}
-- init the c compiler
cc:add("$(env CC)", {name = "gcc", cross = cross}, {name = "clang", cross = cross})
@@ -107,7 +108,10 @@ function _toolchains()
ex:add("$(env AR)", {name = "ar", cross = cross})
-- init the static library index generator
- ar:add("$(env RANLIB)", {name = "ranlib", cross = cross})
+ ranlib:add("$(env RANLIB)", {name = "ranlib", cross = cross})
+
+ -- init the symbols stripper
+ strip:add("$(env STRIP)", {name = "strip", cross = cross})
return toolchains
end
diff --git a/xmake/platforms/iphoneos/config.lua b/xmake/platforms/iphoneos/config.lua
index 23840bea5..60e8a7500 100644
--- a/xmake/platforms/iphoneos/config.lua
+++ b/xmake/platforms/iphoneos/config.lua
@@ -44,13 +44,14 @@ function _toolchains()
local sh = toolchain("the shared library linker")
local ar = toolchain("the static library archiver")
local ex = toolchain("the static library extractor")
+ local strip = toolchain("the symbols stripper")
local mm = toolchain("the objc compiler")
local mxx = toolchain("the objc++ compiler")
local as = toolchain("the assember")
local sc = toolchain("the swift compiler")
local sc_ld = toolchain("the swift linker")
local sc_sh = toolchain("the swift shared library linker")
- local toolchains = {cc = cc, cpp = cpp, cxx = cxx, as = as, ld = ld, sh = sh, ar = ar, ex = ex,
+ local toolchains = {cc = cc, cpp = cpp, cxx = cxx, as = as, ld = ld, sh = sh, ar = ar, ex = ex, strip = strip,
mm = mm, mxx = mxx, sc = sc, ["sc-ld"] = sc_ld, ["sc-sh"] = sc_sh}
-- init the c compiler
@@ -84,6 +85,9 @@ function _toolchains()
-- init the static library extractor
ex:add({name = "ar", cross = cross})
+ -- init the symbols stripper
+ strip:add({name = "strip", cross = cross})
+
-- init the objc compiler
mm:add({name = "clang", cross = cross})
diff --git a/xmake/platforms/linux/config.lua b/xmake/platforms/linux/config.lua
index 3a7f26574..489c8d15e 100644
--- a/xmake/platforms/linux/config.lua
+++ b/xmake/platforms/linux/config.lua
@@ -60,6 +60,7 @@ function _toolchains()
local sh = toolchain("the shared library linker")
local ar = toolchain("the static library archiver")
local ex = toolchain("the static library extractor")
+ local strip = toolchain("the symbols stripper")
local mm = toolchain("the objc compiler")
local mxx = toolchain("the objc++ compiler")
local as = toolchain("the assember")
@@ -77,7 +78,7 @@ function _toolchains()
local cu = toolchain("the cuda compiler")
local cu_ld = toolchain("the cuda linker")
local cu_ccbin = toolchain("the cuda host c++ compiler")
- local toolchains = {cc = cc, cxx = cxx, as = as, ld = ld, sh = sh, ar = ar, ex = ex,
+ local toolchains = {cc = cc, cxx = cxx, as = as, ld = ld, sh = sh, ar = ar, ex = ex, strip = strip,
mm = mm, mxx = mxx,
gc = gc, ["gc-ld"] = gc_ld, ["gc-ar"] = gc_ar,
dc = dc, ["dc-ld"] = dc_ld, ["dc-sh"] = dc_sh, ["dc-ar"] = dc_ar,
@@ -117,6 +118,9 @@ function _toolchains()
-- init the static library extractor
ex:add("$(env AR)", {name = "ar", cross = cross})
+ -- init the symbols stripper
+ strip:add("$(env STRIP)", {name = "strip", cross = cross})
+
-- init the objc compiler
mm:add("$(env MM)", {name = "clang", cross = cross}, {name = "gcc", cross = cross})
@@ -150,7 +154,6 @@ function _toolchains()
if not cross or cross == "" then
cu_ccbin:add("$(env CXX)", "$(env CC)", "gcc", "clang", "g++", "clang++")
end
-
return toolchains
end
diff --git a/xmake/platforms/macosx/config.lua b/xmake/platforms/macosx/config.lua
index 4eef3f780..7c24bea6d 100644
--- a/xmake/platforms/macosx/config.lua
+++ b/xmake/platforms/macosx/config.lua
@@ -39,6 +39,7 @@ function _toolchains()
local sh = toolchain("the shared library linker")
local ar = toolchain("the static library archiver")
local ex = toolchain("the static library extractor")
+ local strip = toolchain("the symbols stripper")
local mm = toolchain("the objc compiler")
local mxx = toolchain("the objc++ compiler")
local as = toolchain("the assember")
@@ -59,7 +60,7 @@ function _toolchains()
local cu = toolchain("the cuda compiler")
local cu_ld = toolchain("the cuda linker")
local cu_ccbin = toolchain("the cuda host c++ compiler")
- local toolchains = {cc = cc, cxx = cxx, as = as, ld = ld, sh = sh, ar = ar, ex = ex,
+ local toolchains = {cc = cc, cxx = cxx, as = as, ld = ld, sh = sh, ar = ar, ex = ex, strip = strip,
mm = mm, mxx = mxx, sc = sc, ["sc-ld"] = sc_ld, ["sc-sh"] = sc_sh,
gc = gc, ["gc-ld"] = gc_ld, ["gc-ar"] = gc_ar,
dc = dc, ["dc-ld"] = dc_ld, ["dc-sh"] = dc_sh, ["dc-ar"] = dc_ar,
@@ -96,6 +97,9 @@ function _toolchains()
-- init the static library extractor
ex:add({name = "ar", cross = cross}, "ar")
+ -- init the symbols stripper
+ strip:add({name = "strip", cross = cross}, "strip")
+
-- init the objc compiler
mm:add("$(env MM)", {name = "clang", cross = cross}, "clang", "gcc")
diff --git a/xmake/platforms/watchos/config.lua b/xmake/platforms/watchos/config.lua
index ebd84c21c..7776e4128 100644
--- a/xmake/platforms/watchos/config.lua
+++ b/xmake/platforms/watchos/config.lua
@@ -43,13 +43,14 @@ function _toolchains()
local sh = toolchain("the shared library linker")
local ar = toolchain("the static library archiver")
local ex = toolchain("the static library extractor")
+ local strip = toolchain("the symbols stripper")
local mm = toolchain("the objc compiler")
local mxx = toolchain("the objc++ compiler")
local as = toolchain("the assember")
local sc = toolchain("the swift compiler")
local sc_ld = toolchain("the swift linker")
local sc_sh = toolchain("the swift shared library linker")
- local toolchains = {cc = cc, cxx = cxx, as = as, ld = ld, sh = sh, ar = ar, ex = ex,
+ local toolchains = {cc = cc, cxx = cxx, as = as, ld = ld, sh = sh, ar = ar, ex = ex, strip = strip,
mm = mm, mxx = mxx, sc = sc, ["sc-ld"] = sc_ld, ["sc-sh"] = sc_sh}
-- init the c compiler
@@ -80,6 +81,9 @@ function _toolchains()
-- init the static library extractor
ex:add({name = "ar", cross = cross})
+ -- init the symbols stripper
+ strip:add({name = "strip", cross = cross})
+
-- init the objc compiler
mm:add({name = "clang", cross = cross})
diff --git a/xmake/rules/mode/xmake.lua b/xmake/rules/mode/xmake.lua
index 6dfa4b0f2..7214e23f8 100644
--- a/xmake/rules/mode/xmake.lua
+++ b/xmake/rules/mode/xmake.lua
@@ -39,6 +39,8 @@ rule("mode.debug")
-- define rule: release mode
rule("mode.release")
+ -- we attempt to extract symbols to the independent file and strip self-target binary if `symbols/debug` is enabled
+ add_deps("utils.symbols.extract")
after_load(function (target)
-- is release mode now? xmake f -m release
diff --git a/xmake/rules/utils/symbols/extract.lua b/xmake/rules/utils/symbols/extract.lua
new file mode 100644
index 000000000..f53044a21
--- /dev/null
+++ b/xmake/rules/utils/symbols/extract.lua
@@ -0,0 +1,74 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed under the Apache License, Version 2.0 (the "License");
+-- you may not use this file except in compliance with the License.
+-- You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+-- Copyright (C) 2015-2020, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file xmake.lua
+--
+
+-- imports
+import("core.base.option")
+import("core.theme.theme")
+import("core.platform.platform")
+import("lib.detect.find_tool")
+
+-- need generate symbols?
+function _need_symbols(target)
+ local strip = target:get("strip")
+ local targetkind = target:targetkind()
+ return target:get("symbols") == "debug" and (strip == "all" or strip == "debug") and (targetkind == "binary" or targetkind == "shared")
+end
+
+-- the main entry
+function main(target, opt)
+
+ -- need generate symbols?
+ if not _need_symbols(target) then
+ return
+ end
+
+ -- find strip
+ local strip = platform.tool("strip")
+ if not strip then
+ return
+ end
+
+ -- trace progress info
+ local targetfile = target:targetfile()
+ local progress_prefix = "${color.build.progress}" .. theme.get("text.build.progress_format") .. ":${clear} "
+ if option.get("verbose") then
+ cprint(progress_prefix .. "${dim color.build.target}stripping.$(mode) %s", opt.progress, path.filename(targetfile))
+ else
+ cprint(progress_prefix .. "${color.build.target}stripping.$(mode) %s", opt.progress, path.filename(targetfile))
+ end
+
+ -- strip it
+ local strip_argv = {}
+ if is_plat("macosx", "iphoneos", "watchos") then
+ -- do not support `-s`, we can only strip debug symbols
+ local arch = get_config("arch")
+ if arch then
+ table.insert(strip_argv, "-arch")
+ table.insert(strip_argv, arch)
+ end
+ table.insert(strip_argv, "-S")
+ else
+ -- -s/--strip-all for gnu strip
+ table.insert(strip_argv, "-s")
+ end
+ table.insert(strip_argv, targetfile)
+ os.vrunv(strip, strip_argv, {dryrun = option.get("dry-run")})
+end
+
diff --git a/xmake/rules/utils/symbols/xmake.lua b/xmake/rules/utils/symbols/xmake.lua
new file mode 100644
index 000000000..fa3ce5528
--- /dev/null
+++ b/xmake/rules/utils/symbols/xmake.lua
@@ -0,0 +1,24 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed under the Apache License, Version 2.0 (the "License");
+-- you may not use this file except in compliance with the License.
+-- You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+-- Copyright (C) 2015-2020, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file xmake.lua
+--
+
+-- define rule: utils.symbols.extract
+rule("utils.symbols.extract")
+ after_link("extract")
+