mirror of
https://github.com/logos-storage/logos-storage-app-skeleton.git
synced 2026-06-14 04:19:25 +00:00
181 lines
5.8 KiB
Nix
181 lines
5.8 KiB
Nix
# Builds the logos-storage-cli standalone CLI application
|
|
{ pkgs, common, src, logosLiblogos, logosSdk, logosStorageModule, logosCapabilityModule }:
|
|
|
|
pkgs.stdenv.mkDerivation rec {
|
|
pname = "${common.pname}-cli";
|
|
version = common.version;
|
|
|
|
inherit src;
|
|
|
|
# CLI has no design system or QML dependency: trim buildInputs accordingly
|
|
buildInputs = [
|
|
pkgs.qt6.qtbase
|
|
pkgs.qt6.qtremoteobjects
|
|
pkgs.zstd
|
|
pkgs.krb5
|
|
pkgs.abseil-cpp
|
|
];
|
|
|
|
# Add logosSdk to nativeBuildInputs for logos-cpp-generator
|
|
nativeBuildInputs = common.nativeBuildInputs ++ [ logosSdk pkgs.patchelf ];
|
|
|
|
inherit (common) meta;
|
|
|
|
# CLI is not a GUI application: still wrap so Qt shared libs are on LD_LIBRARY_PATH
|
|
dontWrapQtApps = false;
|
|
dontStrip = true;
|
|
|
|
qtLibPath = pkgs.lib.makeLibraryPath (
|
|
[
|
|
pkgs.qt6.qtbase
|
|
pkgs.qt6.qtremoteobjects
|
|
pkgs.zstd
|
|
pkgs.krb5
|
|
pkgs.zlib
|
|
pkgs.glib
|
|
pkgs.stdenv.cc.cc
|
|
]
|
|
);
|
|
|
|
qtWrapperArgs = [
|
|
"--prefix" "LD_LIBRARY_PATH" ":" qtLibPath
|
|
];
|
|
|
|
preConfigure = ''
|
|
runHook prePreConfigure
|
|
|
|
# Create generated_code directory for the CLI (cmake -S cli sets CMAKE_SOURCE_DIR=cli/)
|
|
mkdir -p ./cli/generated_code
|
|
|
|
# Copy pre-generated API files from logos-storage-module
|
|
echo "Copying include files from logos-storage-module..."
|
|
if [ -d "${logosStorageModule}/include" ]; then
|
|
cp -r "${logosStorageModule}/include"/* ./cli/generated_code/
|
|
echo "Copied include files:"
|
|
ls -la ./cli/generated_code/
|
|
else
|
|
echo "Warning: No include directory found in logos-storage-module"
|
|
fi
|
|
|
|
# Run logos-cpp-generator with cli/metadata.json and --general-only flag
|
|
# This generates logos_sdk.cpp which #includes storage_module_api.cpp
|
|
echo "Running logos-cpp-generator for CLI..."
|
|
logos-cpp-generator --metadata ${src}/cli/metadata.json --general-only --output-dir ./cli/generated_code
|
|
|
|
echo "Checking generated files in cli/generated_code:"
|
|
ls -la ./cli/generated_code/
|
|
|
|
# Move generated headers to include/ subdirectory (installed layout convention)
|
|
if [ -f "./cli/generated_code/logos_sdk.h" ] || [ -f "./cli/generated_code/core_manager_api.h" ]; then
|
|
echo "Creating include directory and moving generated files..."
|
|
mkdir -p ./cli/generated_code/include
|
|
for file in ./cli/generated_code/*.h; do
|
|
[ -f "$file" ] && mv "$file" ./cli/generated_code/include/
|
|
done
|
|
# Keep a copy of .cpp files in include/ so #include "storage_module_api.cpp" resolves
|
|
for file in ./cli/generated_code/*.cpp; do
|
|
[ -f "$file" ] && cp "$file" ./cli/generated_code/include/
|
|
done
|
|
echo "Generated include directory:"
|
|
ls -la ./cli/generated_code/include/
|
|
else
|
|
echo "Warning: No header files generated by logos-cpp-generator"
|
|
fi
|
|
|
|
runHook postPreConfigure
|
|
'';
|
|
|
|
configurePhase = ''
|
|
runHook preConfigure
|
|
|
|
echo "Configuring logos-storage-cli..."
|
|
echo "liblogos: ${logosLiblogos}"
|
|
echo "cpp-sdk: ${logosSdk}"
|
|
echo "storage-module: ${logosStorageModule}"
|
|
echo "capability-module: ${logosCapabilityModule}"
|
|
|
|
test -d "${logosLiblogos}" || (echo "liblogos not found" && exit 1)
|
|
test -d "${logosSdk}" || (echo "cpp-sdk not found" && exit 1)
|
|
test -d "${logosStorageModule}" || (echo "storage-module not found" && exit 1)
|
|
test -d "${logosCapabilityModule}" || (echo "capability-module not found" && exit 1)
|
|
|
|
cmake -S cli -B build/cli \
|
|
-GNinja \
|
|
-DCMAKE_BUILD_TYPE=Release \
|
|
-DCMAKE_INSTALL_RPATH_USE_LINK_PATH=FALSE \
|
|
-DCMAKE_INSTALL_RPATH="" \
|
|
-DCMAKE_SKIP_BUILD_RPATH=TRUE \
|
|
-DLOGOS_LIBLOGOS_ROOT=${logosLiblogos} \
|
|
-DLOGOS_CPP_SDK_ROOT=${logosSdk} \
|
|
-DLOGOS_STORAGE_ROOT=${logosStorageModule}
|
|
|
|
runHook postConfigure
|
|
'';
|
|
|
|
buildPhase = ''
|
|
runHook preBuild
|
|
|
|
cmake --build build/cli
|
|
echo "logos-storage-cli built successfully!"
|
|
|
|
runHook postBuild
|
|
'';
|
|
|
|
installPhase = ''
|
|
runHook preInstall
|
|
|
|
mkdir -p $out/bin $out/lib $out/modules $out/generated_code
|
|
|
|
# Install CLI binary
|
|
if [ -f "build/cli/bin/logos-storage-cli" ]; then
|
|
cp build/cli/bin/logos-storage-cli "$out/bin/"
|
|
echo "Installed logos-storage-cli binary"
|
|
fi
|
|
|
|
# Copy the core binaries from liblogos
|
|
if [ -f "${logosLiblogos}/bin/logoscore" ]; then
|
|
cp -L "${logosLiblogos}/bin/logoscore" "$out/bin/"
|
|
echo "Installed logoscore binary"
|
|
fi
|
|
if [ -f "${logosLiblogos}/bin/logos_host" ]; then
|
|
cp -L "${logosLiblogos}/bin/logos_host" "$out/bin/"
|
|
echo "Installed logos_host binary"
|
|
fi
|
|
|
|
# Copy required shared libraries from liblogos
|
|
if ls "${logosLiblogos}/lib/"liblogos_core.* >/dev/null 2>&1; then
|
|
cp -L "${logosLiblogos}/lib/"liblogos_core.* "$out/lib/" || true
|
|
fi
|
|
|
|
# Copy SDK library if it exists
|
|
if ls "${logosSdk}/lib/"liblogos_sdk.* >/dev/null 2>&1; then
|
|
cp -L "${logosSdk}/lib/"liblogos_sdk.* "$out/lib/" || true
|
|
fi
|
|
|
|
# Copy generated header files
|
|
cp -R "./cli/generated_code" "$out/generated_code" || true
|
|
|
|
# Determine platform-specific plugin extension
|
|
OS_EXT="so"
|
|
case "$(uname -s)" in
|
|
Darwin) OS_EXT="dylib";;
|
|
Linux) OS_EXT="so";;
|
|
esac
|
|
|
|
# Copy module plugins into the modules directory
|
|
if [ -f "${logosCapabilityModule}/lib/capability_module_plugin.$OS_EXT" ]; then
|
|
cp -L "${logosCapabilityModule}/lib/capability_module_plugin.$OS_EXT" "$out/modules/"
|
|
fi
|
|
if [ -f "${logosStorageModule}/lib/storage_module_plugin.$OS_EXT" ]; then
|
|
cp -L "${logosStorageModule}/lib/storage_module_plugin.$OS_EXT" "$out/modules/"
|
|
fi
|
|
|
|
# Copy libstorage library to modules directory (needed by storage_module_plugin)
|
|
if [ -f "${logosStorageModule}/lib/libstorage.$OS_EXT" ]; then
|
|
cp -L "${logosStorageModule}/lib/libstorage.$OS_EXT" "$out/modules/"
|
|
fi
|
|
|
|
runHook postInstall
|
|
'';
|
|
}
|