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

Add xmake pack command to generate installation package like cmake/cpack #1433

Closed
10 tasks done
waruqi opened this issue Jun 1, 2021 · 8 comments
Closed
10 tasks done

Comments

@waruqi
Copy link
Member

waruqi commented Jun 1, 2021

Roadmaps

  • nsis
  • wix
  • deb
  • rpm
  • srpm
  • targz
  • zip
  • srczip
  • srctargz
  • runself

Refs

@waruqi waruqi added this to the todo milestone Jun 1, 2021
@waruqi waruqi changed the title Add xpack command to generate installation package like cmake/cpack Add xmake pack command to generate installation package like cmake/cpack Jun 1, 2021
@waruqi waruqi modified the milestones: todo, v2.8.6 Nov 8, 2023
@waruqi
Copy link
Member Author

waruqi commented Nov 15, 2023

New Scope Apis (xpack)

we can call includes("@builtin/xpack") to import xpack() apis.

includes("@builtin/xpack")

xpack("test")
    set_formats("nsis")
    set_description("hello")
    add_targets("test", "foo")
local apis = {
    values = {
        -- set package version,  we will also get it from project/target
        "xpack.set_version",
        -- set package homepage url
        "xpack.set_homepage",
        -- set package title
        "xpack.set_title",
        -- set author
        "xpack.set_author",
        -- set maintainer,
        "xpack.set_maintainer",
        -- set package description
        "xpack.set_description",
        -- set input kind, e.g. binary, source
        "xpack.set_inputkind",
        -- set package copyright
        "xpack.set_copyright",
        -- set company name
        "xpack.set_company",
        -- set package formats, e.g. nsis, deb, rpm, targz, zip, srctargz, srczip, runself, ...
        -- we can also add custom formats
        "xpack.set_formats",
        -- set the base name of the output file
        "xpack.set_basename",
        -- set the extension of the output file
        "xpack.set_extension",
        -- add targets to be packaged
        "xpack.add_targets",
        -- add package components
        "xpack.add_components",
        -- set installed binary directory, e.g. bin
        "xpack.set_bindir",
        -- set installed library directory, e.g. lib
        "xpack.set_libdir",
        -- set installed include directory, e.g. include
        "xpack.set_includedir",
        -- set prefix directory, e.g. prefixdir/bin, prefixdir/lib ..
        "xpack.set_prefixdir",
        -- set nsis display icon
        "xpack.set_nsis_displayicon",
        -- set package component title
        "xpack_component.set_title",
        -- set package component description
        "xpack_component.set_description",
        -- enable/disable this component by default
        "xpack_component.set_default"
    },
    paths = {
        -- set the spec file path, support the custom variable pattern, e.g. set_specfile("", {pattern = "%${([^\n]-)}"})
        "xpack.set_specfile",
        -- set icon file path, e.g foo.ico
        "xpack.set_iconfile",
        -- set package license file, we will also get them from target
        "xpack.set_licensefile",
        -- add source files
        "xpack.add_sourcefiles",
        -- add install files, we will also get them from target
        "xpack.add_installfiles",
        -- add source files for component
        "xpack_component.add_sourcefiles",
        -- add install files for component
        "xpack_component.add_installfiles"
    },
    script = {
        -- add custom load script
        "xpack.on_load",
        -- add custom package script before packing package
        "xpack.before_package",
        -- rewrite custom package script
        "xpack.on_package",
        -- add custom package script after packing package
        "xpack.after_package",
        -- add custom commands script before installing
        "xpack.before_installcmd",
        -- add custom commands script before uninstalling
        "xpack.before_uninstallcmd",
        -- rewrite custom install commands script, we will also get it from target/rules
        "xpack.on_installcmd",
        -- rewrite custom uninstall commands script, we will also get it from target/rules
        "xpack.on_uninstallcmd",
        -- add custom commands script after installing
        "xpack.after_installcmd",
        -- add custom commands script after uninstalling
        "xpack.after_uninstallcmd",
        -- add custom load script in component
        "xpack_component.on_load",
        -- add custom commands script before installing in component
        "xpack_component.before_installcmd",
        -- add custom commands script before uninstalling in component
        "xpack_component.before_uninstallcmd",
        -- rewrite custom install commands script in component, we will also get it from target/rules
        "xpack_component.on_installcmd",
        -- rewrite custom uninstall commands script in component, we will also get it from target/rules
        "xpack_component.on_uninstallcmd",
        -- add custom commands script after installing in component
        "xpack_component.after_installcmd",
        -- add custom commands script after uninstalling in component
        "xpack_component.after_uninstallcmd"
    },
    keyvalues = {
        -- set the spec variable
        "xpack.set_specvar"
    }
}

Example

https://github.com/xmake-io/xmake/blob/dev/tests/plugins/pack/xmake.lua

set_version("1.0.0")
add_rules("mode.debug", "mode.release")

includes("@builtin/xpack")

add_requires("zlib", {configs = {shared = true}})

target("test")
    set_kind("binary")
    add_files("src/*.cpp")
    if is_plat("windows") then
        add_files("src/*.rc")
    end

target("foo")
    set_kind("shared")
    add_files("src/*.cpp")
    add_headerfiles("include/(*.h)")
    add_packages("zlib")

xpack("test")
    set_formats("nsis", "zip", "targz", "srczip", "srctargz", "runself")
    set_title("hello")
    set_author("ruki")
    set_description("A test installer.")
    set_homepage("https://xmake.io")
    set_licensefile("LICENSE.md")
    add_targets("test", "foo")
    add_installfiles("src/(assets/*.png)", {prefixdir = "images"})
    add_sourcefiles("(src/**)")
    set_iconfile("src/assets/xmake.ico")
    add_components("LongPath")

    on_load(function (package)
        if package:from_source() then
            package:set("basename", "test-$(plat)-src-v$(version)")
        else
            package:set("basename", "test-$(plat)-$(arch)-v$(version)")
        end
    end)

    after_installcmd(function (package, batchcmds)
        if package:from_source() then
            batchcmds:runv("echo", {"hello"})
        else
            batchcmds:mkdir(package:installdir("resources"))
            batchcmds:cp("src/assets/*.txt", package:installdir("resources"), {rootdir = "src"})
            batchcmds:mkdir(package:installdir("stub"))
        end
    end)

    after_uninstallcmd(function (package, batchcmds)
        batchcmds:rmdir(package:installdir("resources"))
        batchcmds:rmdir(package:installdir("stub"))
    end)

xpack_component("LongPath")
    set_default(false)
    set_title("Enable Long Path")
    set_description("Increases the maximum path length limit, up to 32,767 characters (before 256).")
    on_installcmd(function (component, batchcmds)
        batchcmds:rawcmd("nsis", [[
  ${If} $NoAdmin == "false"
    ; Enable long path
    WriteRegDWORD ${HKLM} "SYSTEM\CurrentControlSet\Control\FileSystem" "LongPathsEnabled" 1
  ${EndIf}]])
    end)

Pack packages

$ xmake pack

@waruqi
Copy link
Member Author

waruqi commented Nov 15, 2023

Pack NSIS package

It will download and install NSIS (makensis.exe) first automically.

$ xmake pack
note: install or modify (m) these packages (pass -y to skip confirm)?
in xmake-repo:
  -> nsis 3.09
please input: y (y/n/m)

  => install nsis 3.09 .. ok

[ 25%]: compiling.release src\main.cpp
[ 37%]: compiling.release src\main.cpp
[ 50%]: linking.release foo.dll
[ 62%]: linking.release test.exe
packing build\xpack\test\test-windows-x64-v1.0.0.exe
pack ok

image
image
image
image

@waruqi
Copy link
Member Author

waruqi commented Nov 17, 2023

More example: Pack xmake installation package https://github.com/xmake-io/xmake/blob/dev/core/xpack.lua

@waruqi
Copy link
Member Author

waruqi commented Nov 18, 2023

Support pack zip/tar.gz archive

xpack("test")
    set_formats("zip", "targz")
$ xmake pack
$ xmake pack --formats=zip,targz

@waruqi
Copy link
Member Author

waruqi commented Nov 22, 2023

Support components and custom nsis commands

xpack("test")
    add_components("LongPath")

xpack_component("LongPath")
    set_default(false)
    set_title("Enable Long Path")
    set_description("Increases the maximum path length limit, up to 32,767 characters (before 256).")
    on_installcmd(function (component, batchcmds)
        batchcmds:rawcmd("nsis", [[
  ${If} $NoAdmin == "false"
    ; Enable long path
    WriteRegDWORD ${HKLM} "SYSTEM\CurrentControlSet\Control\FileSystem" "LongPathsEnabled" 1
  ${EndIf}]])
    end)

image

@waruqi waruqi mentioned this issue Nov 23, 2023
@waruqi
Copy link
Member Author

waruqi commented Nov 24, 2023

Pack source zip/tar.gz package

xpack("test")
    set_formats("srczip", "srctargz")
    add_sourcefiles("(src/**)")
$ xmake pack
packing build/xpack/test/test-macosx-src-v1.0.0.zip ..
packing build/xpack/test/test-macosx-src-v1.0.0.tar.gz ..
pack ok

Pack runself package

xpack("test")
    set_formats("runself")
    add_sourcefiles("(src/**)")
    on_installcmd(function (package, batchcmds)
        batchcmds:runv("make", {"install"})
    end)
$ xmake pack
packing build/xpack/test/test-macosx-src-v1.0.0.gz.run
pack ok

$ sh ./build/xpack/test/test-macosx-src-v1.0.0.gz.run

xmake/core/xpack.lua

Lines 79 to 112 in 51efaa7

xpack("xmakesrc")
set_formats("srczip", "srctargz", "runself")
set_basename("xmake-v$(version)")
set_prefixdir("xmake-$(version)")
before_package(function (package)
import("devel.git")
local rootdir = path.join(os.tmpfile(package:basename()) .. ".dir", "repo")
if not os.isdir(rootdir) then
os.tryrm(rootdir)
os.cp(path.directory(os.projectdir()), rootdir)
git.clean({repodir = rootdir, force = true, all = true})
git.reset({repodir = rootdir, hard = true})
if os.isfile(path.join(rootdir, ".gitmodules")) then
git.submodule.clean({repodir = rootdir, force = true, all = true})
git.submodule.reset({repodir = rootdir, hard = true})
end
end
local extraconf = {rootdir = rootdir}
package:add("sourcefiles", path.join(rootdir, "core/**|src/pdcurses/**|src/luajit/**|src/tbox/tbox/src/demo/**"), extraconf)
package:add("sourcefiles", path.join(rootdir, "xmake/**"), extraconf)
package:add("sourcefiles", path.join(rootdir, "*.md"), extraconf)
package:add("sourcefiles", path.join(rootdir, "configure"), extraconf)
package:add("sourcefiles", path.join(rootdir, "scripts/*.sh"), extraconf)
package:add("sourcefiles", path.join(rootdir, "scripts/man/**"), extraconf)
package:add("sourcefiles", path.join(rootdir, "scripts/debian/**"), extraconf)
package:add("sourcefiles", path.join(rootdir, "scripts/msys/**"), extraconf)
end)
on_installcmd(function (package, batchcmds)
batchcmds:runv("./scripts/get.sh", {"__local__"})
end)

@waruqi
Copy link
Member Author

waruqi commented Dec 21, 2023

Pack srpm package

Pack xmake project with targets

xpack("test")
    set_homepage("https://xmake.io")
    set_license("Apache-2.0")
    set_description("A cross-platform build utility based on Lua.")

    set_formats("srpm")
    add_sourcefiles("(src/**)")
    add_sourcefiles("./xmake.lua")

    add_targets("demo")

Pack 3rd build system project

xpack("test")
    set_homepage("https://xmake.io")
    set_license("Apache-2.0")
    set_description("A cross-platform build utility based on Lua.")

    set_formats("srpm")
    add_sourcefiles("(src/**)")
    add_sourcefiles("./configure")

    on_buildcmd(function (package, batchcmds)
        batchcmds:runv("./configure")
        batchcmds:runv("make")
    end)

    on_installcmd(function (package, batchcmds)
        batchcmds:runv("make", {"install", "PREFIX=%{buildroot}"})
    end)

@waruqi
Copy link
Member Author

waruqi commented Jun 14, 2024

deb: #5210
wix: #5153

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant