From 6b4f5751ed00a929391967342e52656e0579ac7f Mon Sep 17 00:00:00 2001 From: aeberhardt <alexandre.eberhardt@savoirfairelinux.com> Date: Mon, 9 Sep 2024 14:00:26 -0400 Subject: [PATCH] plugins: fix build and add documentation Add documentation to build and sign AutoAnswer from scratch Fix some of the Example plugin Fix the CMakeLists.txt to copy the shared library in the right folder Copy the library to the right folder created by SDK/jplManipulation.py at line 146 Change-Id: Id0584d0c659d08687a41968b6b7f0064b4e7fac5 --- AutoAnswer/CMakeLists.txt | 45 ++++++++++++++++++++++------------- AutoAnswer/build.md | 24 +++++++++++++++++++ Example/CMakeLists.txt | 3 +-- sign.md | 49 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 103 insertions(+), 18 deletions(-) create mode 100644 AutoAnswer/build.md create mode 100644 sign.md diff --git a/AutoAnswer/CMakeLists.txt b/AutoAnswer/CMakeLists.txt index 1eece74..75876bb 100644 --- a/AutoAnswer/CMakeLists.txt +++ b/AutoAnswer/CMakeLists.txt @@ -37,28 +37,35 @@ set (LIBS_DIR ${PROJECT_SOURCE_DIR}/../contrib/Libs) # Detect the operating system if(WIN32) - set(OS_NAME "WINDOWS") - + set(DISTRIBUTION "x64-windows") elseif(ANDROID) set(OS_NAME "ANDROID") - + set(CONTRIB_PLATFORM_CURT ${ARCH}) + set(CONTRIB_PLATFORM ${CONTRIB_PLATFORM_CURT}-${OS_NAME}) +elseif(APPLE) + if(CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64") + set(DISTRIBUTION "arm64-apple-Darwin") + elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64") + set(DISTRIBUTION "x86_64-apple-Darwin") + else() + message(FATAL_ERROR "Unsupported architecture. Only x64 or arm64 is supported.") + endif() else() - set(OS_NAME "UNIX") - + set(DISTRIBUTION "x86_64-linux-gnu") endif() # Detect the architecture if(CMAKE_SIZEOF_VOID_P EQUAL 8) + message(ARCH: x64) set(ARCH "x64") +elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64") + message(ARCH: arm64) + set(ARCH "arm64") else() - message(FATAL_ERROR "Unsupported architecture. Only x64 is supported.") + message(FATAL_ERROR "Unsupported architecture. Only x64 or aarch64 is supported.") endif() -# Set platform-specific variables -set(CONTRIB_PLATFORM_CURT ${ARCH}) -set(CONTRIB_PLATFORM ${CONTRIB_PLATFORM_CURT}-${OS_NAME}) - -message(OS: ${OS_NAME} ${ARCH}) +message(OS: ${DISTRIBUTION}) message(Building: ${ProjectName} ${Version}) message(Build path: ${PROJECT_BINARY_DIR}) message(JPL assembling path: ${JPL_DIRECTORY}) @@ -135,14 +142,13 @@ add_custom_command( COMMENT "Assembling Plugin files" ) - if(WIN32) # Windows-specific file copying add_custom_command( TARGET ${ProjectName} POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_BINARY_DIR}/${ProjectName}.lib ${JPL_DIRECTORY}/lib/${CONTRIB_PLATFORM} - COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_BINARY_DIR}/${ProjectName}.dll ${JPL_DIRECTORY}/lib/${CONTRIB_PLATFORM} + COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_BINARY_DIR}/${ProjectName}.lib ${JPL_DIRECTORY}/lib/${DISTRIBUTION}/${ProjectName}.lib + COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_BINARY_DIR}/${ProjectName}.dll ${JPL_DIRECTORY}/lib/${DISTRIBUTION}/${ProjectName}.dll COMMENT "Copying files to jpl directory for Windows" ) elseif(APPLE) @@ -150,15 +156,22 @@ elseif(APPLE) add_custom_command( TARGET ${ProjectName} POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_BINARY_DIR}/lib${ProjectName}.dylib ${JPL_DIRECTORY}/lib/${CONTRIB_PLATFORM} + COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_BINARY_DIR}/lib${ProjectName}.dylib ${JPL_DIRECTORY}/lib/${DISTRIBUTION}/lib${ProjectName}.dylib COMMENT "Copying files to jpl directory for macOS" ) +elseif(ANDROID) + add_custom_command( + TARGET ${ProjectName} + POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_BINARY_DIR}/lib${ProjectName}.so ${JPL_DIRECTORY}/lib/${CONTRIB_PLATFORM} + COMMENT "Copying files to jpl directory for Android" + ) else() # Unix-like systems (Linux, etc.) add_custom_command( TARGET ${ProjectName} POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_BINARY_DIR}/lib${ProjectName}.so ${JPL_DIRECTORY}/lib/${CONTRIB_PLATFORM} + COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_BINARY_DIR}/lib${ProjectName}.so ${JPL_DIRECTORY}/lib/${DISTRIBUTION}/lib${ProjectName}.so COMMENT "Copying files to jpl directory for Unix-like systems or Android" ) endif() diff --git a/AutoAnswer/build.md b/AutoAnswer/build.md new file mode 100644 index 0000000..f0e8627 --- /dev/null +++ b/AutoAnswer/build.md @@ -0,0 +1,24 @@ +# To build AutoAnswer, follow these steps: + +## Go to the AutoAnswer folder and create a build directory: + +``` +mkdir build-local +cd build-local +``` + +## Run the following commands to build the project: + +``` +cmake .. +cmake --build . +``` + +## Once the build is complete, you will find your unsigned `AutoAnswer.jpl` in: + +``` +jami-plugins/build/<your distribution>/ +``` + +## To install it on Jami, you need to sign the plugin. Refer to `sign.md` in the `jami-plugins/` directory for instructions on how to sign your plugin. + diff --git a/Example/CMakeLists.txt b/Example/CMakeLists.txt index 071d4bb..4b66119 100644 --- a/Example/CMakeLists.txt +++ b/Example/CMakeLists.txt @@ -30,7 +30,7 @@ set (DAEMON ${PROJECT_SOURCE_DIR}/../daemon) set (JPL_FILE_NAME ${ProjectName}.jpl) set (DAEMON_SRC ${DAEMON}/src) set (CONTRIB_PATH ${DAEMON}/contrib) -set (PLUGINS_LIB ${PROJECT_SOURCE_DIR}/../lib)/ +set (PLUGINS_LIB ${PROJECT_SOURCE_DIR}/../lib) set (JPL_DIRECTORY ${PROJECT_BINARY_DIR}/jpl) # Detect the operating system @@ -217,5 +217,4 @@ if (DEBUG_SIGN) COMMENT "Generating plugin certificate" ) -python3 ./SDK/certKey.py --plugin sign --path /tmp/plugins/foo --issuer /tmp/foo /tmp/plugins/foo endif() diff --git a/sign.md b/sign.md new file mode 100644 index 0000000..e47ecd3 --- /dev/null +++ b/sign.md @@ -0,0 +1,49 @@ +# To add your plugin built on Jami, you need to sign it with certificates. + +## Create a directory to store them: + +``` +mkdir -p jami-plugins/certificate +``` + +## In a Python environment (recommended) install the requirements: + +``` +cd jami-plugins/SDK +pip install -r requirements.txt +pip install -r certificate_requirements.txt +pip install requests +``` + +## Create the certificates: + +``` +python3 ./certKey.py create --subject PluginName ../certificate/ +``` + +## Verify the certificates: + +``` +openssl x509 -in ../certificate/certificate.crt -text -noout +``` + +## Sign the plugin (certKey.py will automatically add the `.crt` and `.jpl` extensions): + +``` +python3 ./certKey.py --plugin sign --issuer <Path to your certificate without the ".crt"> --path <path to your plugin.jpl> <path to your signed plugin output without the ".jpl"> +``` + +For example: + +``` +python3 ./certKey.py --plugin sign --issuer ../certificate/certificate --path ../build/x86_64-linux-gnu/AutoAnswer.jpl ../build/x86_64-linux-gnu/signed/AutoAnswerSigned +``` + +## Display the signed files: + +``` +ls ../build/<your distribution>/signed +``` + +## You can now add your signed `.jpl` plugin to Jami. + -- GitLab