aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md1
-rwxr-xr-xscripts/package.py30
-rw-r--r--src/main.cpp2
3 files changed, 31 insertions, 2 deletions
diff --git a/README.md b/README.md
index 430ccfe..416440c 100644
--- a/README.md
+++ b/README.md
@@ -40,6 +40,7 @@ After you have installed sibs, execute `sibs` without any arguments and you will
# Package
Sibs supports creating a redistributable packages of projects (currently only on Linux, run `sibs package --bundle`). Packaging is in testing phase and may not work for all projects. Currently you need to have python3, ldd and patchelf installed and also set the environment variable SIBS_SCRIPT_DIR to scripts sub directory which is in sibs root directory (the directory that contains package.py).
Currently a script file is generated which should be used to run the project. The name of the script file is the same as project. This script file will most likely to be removed later. Do NOT run the executable called "program".
+Because creating a package is currently done by copying gcc/clang libraries and not musl, the distributable package becomes very large; a hello world application extracted from its archive is 6 megabytes...
# IDE support
Sibs generates a compile_commands.json in the project root directory when executing `sibs build` and tools that support clang completion can be used, such as YouCompleteMe.
There are several editors that support YouCompleteMe, including Vim, Emacs and Visual Studio Code. Visual studio code now also supports clang completion with C/C++ extension by Microsoft; the extension will ask you which compile_commands.json file you want to use and you can choose the compile_commands.json in the project root directory.
diff --git a/scripts/package.py b/scripts/package.py
index a10cdcb..f2841b8 100755
--- a/scripts/package.py
+++ b/scripts/package.py
@@ -15,8 +15,7 @@ set -e
script_path=`readlink -f $0`
script_dir=`dirname $script_path`
-cd "$script_dir"
-"./$SO_LOADER" --library-path libs "./$PROGRAM_NAME" "$@"
+"$script_dir/$SO_LOADER" --library-path "$script_dir/libs" "$script_dir/$PROGRAM_NAME" "$@"
"""
def get_executable_dynamic_libraries(filepath):
@@ -38,6 +37,14 @@ def make_executable(filepath):
mode = os.stat(filepath).st_mode
os.chmod(filepath, mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)
+def get_libnss_files():
+ libnss_pattern = re.compile("libnss.*\\.so.*")
+ files = []
+ for filepath in os.listdir("/usr/lib"):
+ if libnss_pattern.match(filepath):
+ files.append(os.path.join("/usr/lib", filepath))
+ return files
+
def main():
if len(sys.argv) <= 2:
print("usage: %s executable_path destination_path" % sys.argv[0])
@@ -60,6 +67,17 @@ def main():
exit(5)
so_loader = os.path.join("libs", so_loader)
+
+ libnss_files = get_libnss_files()
+ for idx, libnss_file in enumerate(libnss_files):
+ new_file_path = os.path.join(sys.argv[2], os.path.basename(libnss_file))
+ libnss_files[idx] = new_file_path
+ if os.path.islink(libnss_file):
+ target_name = os.path.basename(os.readlink(libnss_file))
+ os.symlink(target_name, new_file_path)
+ else:
+ shutil.copyfile(libnss_file, new_file_path)
+
executable_filename = os.path.basename(sys.argv[1])
new_executable_path = os.path.join(sys.argv[2], executable_filename)
shutil.copyfile(sys.argv[1], new_executable_path)
@@ -89,6 +107,12 @@ def main():
for lib in libs:
print("Adding shared library %s to package" % lib[0])
tar.add(lib[0], arcname=os.path.join("libs", lib[1]))
+
+ for libnss_file in libnss_files:
+ print("Adding libnss shared library %s to package" % libnss_file)
+ libnss_name = os.path.basename(libnss_file)
+ tar.add(libnss_file, arcname=os.path.join("libs", libnss_name))
+
print("Adding executable %s to package" % sys.argv[1])
tar.add(new_executable_path, arcname="program")
print("Adding run script %s to package" % run_script_path)
@@ -97,6 +121,8 @@ def main():
print("Removing temporary files")
os.remove(new_executable_path)
os.remove(run_script_path)
+ for libnss_file in libnss_files:
+ os.remove(libnss_file)
print("Package has been created at %s" % package_name)
if __name__ == "__main__":
diff --git a/src/main.cpp b/src/main.cpp
index 119aafb..6a807f0 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -86,6 +86,8 @@ using namespace std::chrono;
// TODO: When creating a package with `sibs package` copy LICENSE files into archive.
+// TODO: Support packaging with musl to reduce number of libraries needed for the package and also to reduce package size.
+
#if OS_FAMILY == OS_FAMILY_POSIX
#define fout std::cout
#define ferr std::cerr