Skip to content

Commit

Permalink
Merge pull request #555 from wazuh/enhancement/544-remove-vcpkg-as-su…
Browse files Browse the repository at this point in the history
…bmodule

Remove VCPKG as submodule
  • Loading branch information
TomasTurina authored Jan 29, 2025
2 parents 706733c + 27e912f commit 612e625
Show file tree
Hide file tree
Showing 27 changed files with 103 additions and 121 deletions.
1 change: 0 additions & 1 deletion .github/workflows/build_and_test_component.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ jobs:
- name: Checkout code
uses: actions/checkout@v3
with:
submodules: true
fetch-depth: 0

- name: Set up dependencies
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/compile_and_run_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ jobs:
- name: Checkout code
uses: actions/checkout@v3
with:
submodules: true
fetch-depth: 0

- name: Set up dependencies on Ubuntu
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/coverage_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ jobs:
- name: Checkout code
uses: actions/checkout@v3
with:
submodules: true
fetch-depth: 0

- name: Set up dependencies
Expand Down
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

40 changes: 14 additions & 26 deletions BUILD.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,15 @@
git clone https://github.com/wazuh/wazuh-agent.git
```

3. **Initialize Submodules**
3. **Vcpkg**

The project uses submodules, so you need to initialize and update them. Run the following commands:

```bash
cd wazuh-agent
git submodule update --init --recursive
```
The project uses Vcpkg for dependency management. If you already have Vcpkg's repository checked out, make sure that `VCPKG_ROOT` is set.
Otherwise, the repository will be checked out during CMake's configuration phase.

4. **Configure and Build the Project**

```bash
cd wazuh-agent
cmake src -B build
cmake --build build
```
Expand Down Expand Up @@ -111,18 +108,15 @@
git clone https://github.com/wazuh/wazuh-agent.git
```

4. **Initialize Submodules**
4. **Vcpkg**

The project uses submodules, so you need to initialize and update them. Run the following commands:

```bash
cd wazuh-agent
git submodule update --init --recursive
```
The project uses Vcpkg for dependency management. If you already have Vcpkg's repository checked out, make sure that `VCPKG_ROOT` is set.
Otherwise, the repository will be checked out during CMake's configuration phase.

5. **Configure and Build the Project**

```bash
cd wazuh-agent
cmake src -B build
cmake --build build
```
Expand Down Expand Up @@ -228,18 +222,15 @@
git clone https://github.com/wazuh/wazuh-agent.git
```

3. **Initialize Submodules**

The project uses submodules, so you need to initialize and update them. Run the following commands:
3. **Vcpkg**

```bash
cd wazuh-agent
git submodule update --init --recursive
```
The project uses Vcpkg for dependency management. If you already have Vcpkg's repository checked out, make sure that `VCPKG_ROOT` is set.
Otherwise, the repository will be checked out during CMake's configuration phase.

4. **Configure and Build the Project**

```bash
cd wazuh-agent
cmake src -B build -G "Visual Studio 17 2022" -A x64
cmake --build build
```
Expand All @@ -261,7 +252,7 @@
.\wazuh-agent
.\wazuh-agent --status
```

**To install the agent as a windows service**

```bash
Expand All @@ -270,7 +261,7 @@
You can start, stop or restart the service from Windows SCM.

Or from the CLI

```bash
net start "Wazuh Agent"
net stop "Wazuh Agent"
Expand Down Expand Up @@ -299,6 +290,3 @@
|`ENABLE_INVENTORY`|Enable Inventory module |`ON`|
|`ENABLE_LOGCOLLECTOR`|Enable Logcollector module|`ON`|

## Notes

- The project uses `vcpkg` as a submodule to manage dependencies. By initializing the submodules, `vcpkg` will automatically fetch the necessary dependencies when running CMake.
20 changes: 15 additions & 5 deletions packages/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,27 @@ set_vcpkg_remote_binary_cache(){

if [[ $(mono --version 2>/dev/null) =~ [0-9] ]]; then
echo "mono already installed, proceeding"

git clone --branch master --single-branch https://github.com/microsoft/vcpkg.git
pushd vcpkg

export VCPKG_ROOT="$(pwd)"

git checkout "2024.09.30"

export VCPKG_BINARY_SOURCES="clear;nuget,GitHub,readwrite"
$sources_dir/src/vcpkg/bootstrap-vcpkg.sh
mono `$sources_dir/src/vcpkg/vcpkg fetch nuget | tail -n 1` \
./bootstrap-vcpkg.sh
mono `./vcpkg fetch nuget | tail -n 1` \
sources add \
-source "https://nuget.pkg.github.com/wazuh/index.json" \
-name "GitHub" \
-username "wazuh" \
-password "$vcpkg_token"
mono `$sources_dir/src/vcpkg/vcpkg fetch nuget | tail -n 1` \
mono `./vcpkg fetch nuget | tail -n 1` \
setapikey "$vcpkg_token" \
-source "https://nuget.pkg.github.com/wazuh/index.json"
-source "https://nuget.pkg.github.com/wazuh/index.json"

popd
else
echo "mono in not installed, remote binary caching not being enabled"
fi
Expand All @@ -107,7 +117,7 @@ fi

# Download source code if it is not shared from the local host
if [ ! -d "/wazuh-local-src" ] ; then
git clone --branch ${WAZUH_BRANCH} --single-branch --recurse-submodules https://github.com/wazuh/wazuh-agent.git
git clone --branch ${WAZUH_BRANCH} --single-branch https://github.com/wazuh/wazuh-agent.git
short_commit_hash="$(curl -s https://api.github.com/repos/wazuh/wazuh-agent/commits/${WAZUH_BRANCH} \
| grep '"sha"' | head -n 1| cut -d '"' -f 4 | cut -c 1-11)"
else
Expand Down
1 change: 0 additions & 1 deletion packages/debs/SPECS/wazuh-agent/debian/rules
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ override_dh_auto_install:
override_dh_install:

# Build the binaries
git submodule update --init --recursive
cmake src -B build -DINSTALL_ROOT=${TARGET_DIR}$(INSTALLATION_DIR)
cmake --build build --parallel $(JOBS)

Expand Down
16 changes: 8 additions & 8 deletions packages/macos/generate_wazuh_packages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,10 @@ function build_package_binaries() {
if [ -n "$BRANCH_TAG" ]; then
SOURCES_DIRECTORY="${CURRENT_PATH}/repository"
WAZUH_PATH="${SOURCES_DIRECTORY}/wazuh"
git clone -b ${BRANCH_TAG} --single-branch --recurse-submodules ${WAZUH_SOURCE_REPOSITORY} "${WAZUH_PATH}"
git clone -b ${BRANCH_TAG} --single-branch ${WAZUH_SOURCE_REPOSITORY} "${WAZUH_PATH}"
else
WAZUH_PATH="${CURRENT_PATH}/../.."
cd $WAZUH_PATH && git submodule update --init --recursive
cd $WAZUH_PATH
fi

short_commit_hash="$(cd "${WAZUH_PATH}" && git rev-parse --short HEAD)"
Expand Down Expand Up @@ -230,7 +230,7 @@ function testdep() {
echo "Error: brew not found. Download and install it."
echo "Use $0 -x for install it."
exit 1
fi
fi

if [[ ! $(munkipkg --version 2>/dev/null) =~ [0-9] ]]; then
echo "Error: munkipkg not found. Download and install dependencies."
Expand All @@ -243,7 +243,7 @@ function testdep() {
echo "Error: mono not found. Download and install dependencies."
echo "Use $0 -i for install it."
exit 1
fi
fi
fi
}

Expand All @@ -255,7 +255,7 @@ function install_deps() {
# Install mono tool
echo "Installing mono"
brew install mono
fi
fi

if [[ $(munkipkg --version 2>/dev/null) =~ [0-9] ]]; then
echo "munkipkg already installed"
Expand Down Expand Up @@ -468,7 +468,7 @@ function main() {

testdep
check_root

case "$BUILD_TYPE" in
binaries)
echo "Building only the binaries for the package."
Expand All @@ -495,9 +495,9 @@ function main() {
esac

if [ "${NOTARIZE}" = "yes" ] && { [ "${BUILD_TYPE}" = "package" ] || [ "${BUILD_TYPE}" = "full_package" ]; }; then

notarization_path="${DESTINATION}/${pkg_name}.pkg"

if [ -z "${notarization_path}" ]; then
echo "The path of the package to be notarized has not been specified."
help 1
Expand Down
18 changes: 14 additions & 4 deletions packages/macos/package_files/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,27 @@ set_vcpkg_remote_binary_cache(){

if [[ $(mono --version 2>/dev/null) =~ [0-9] ]]; then
echo "mono already installed, proceeding"

git clone --branch master --single-branch https://github.com/microsoft/vcpkg.git
pushd vcpkg

export VCPKG_ROOT="$(pwd)"

git checkout "2024.09.30"

export VCPKG_BINARY_SOURCES="clear;nuget,GitHub,readwrite"
$WAZUH_PATH/src/vcpkg/bootstrap-vcpkg.sh
mono `$WAZUH_PATH/src/vcpkg/vcpkg fetch nuget | tail -n 1` \
./bootstrap-vcpkg.sh
mono `./vcpkg fetch nuget | tail -n 1` \
sources add \
-source "https://nuget.pkg.github.com/wazuh/index.json" \
-name "GitHub" \
-username "wazuh" \
-password "$vcpkg_token"
mono `$WAZUH_PATH/src/vcpkg/vcpkg fetch nuget | tail -n 1` \
mono `./vcpkg fetch nuget | tail -n 1` \
setapikey "$vcpkg_token" \
-source "https://nuget.pkg.github.com/wazuh/index.json"
-source "https://nuget.pkg.github.com/wazuh/index.json"

popd
else
echo "mono is not installed, remote binary caching not being enabled"
fi
Expand Down
1 change: 0 additions & 1 deletion packages/rpms/SPECS/wazuh_agent.spec
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ log analysis, file integrity monitoring, intrusions detection and policy and com

%build
pushd src
git submodule update --init --recursive
mkdir build
pushd build
cmake .. -DINSTALL_ROOT=%{buildroot}%{_localstatedir} && make -j $(nproc)
Expand Down
44 changes: 29 additions & 15 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
cmake_minimum_required(VERSION 3.22)

set(CMAKE_TOOLCHAIN_FILE "${CMAKE_SOURCE_DIR}/vcpkg/scripts/buildsystems/vcpkg.cmake")
if(DEFINED ENV{VCPKG_ROOT})
message(STATUS "VCPKG is installed. VCPKG_ROOT: $ENV{VCPKG_ROOT}")
set(CMAKE_TOOLCHAIN_FILE "$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" CACHE FILEPATH "")
else()
message(STATUS "VCPKG is not installed or VCPKG_ROOT is not set. Fetching vcpkg...")

include(FetchContent)
FetchContent_Declare(vcpkg
GIT_REPOSITORY https://github.com/microsoft/vcpkg/
GIT_TAG 2024.09.30
)

FetchContent_MakeAvailable(vcpkg)

set(CMAKE_TOOLCHAIN_FILE "${vcpkg_SOURCE_DIR}/scripts/buildsystems/vcpkg.cmake" CACHE FILEPATH "")
endif()

get_filename_component(SRC_FOLDER ${CMAKE_SOURCE_DIR}/../ ABSOLUTE)
get_filename_component(CONFIG_FOLDER ${CMAKE_SOURCE_DIR}/../etc/config/ ABSOLUTE)
Expand All @@ -9,7 +24,7 @@ get_filename_component(WINDOWS_FOLDER ${CMAKE_SOURCE_DIR}/../packages/windows/ A
project(wazuh-agent)

if(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "Darwin")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libstdc++")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libstdc++")
endif()

include(cmake/CommonSettings.cmake)
Expand All @@ -26,6 +41,7 @@ else()
add_subdirectory(common/networkHelper)
add_subdirectory(common/filesystem_wrapper)
endif()

add_subdirectory(modules)
add_subdirectory(agent)

Expand All @@ -40,7 +56,7 @@ endif()
include(cmake/ConfigureTarget.cmake)
configure_target(wazuh-agent)

## Installation
# Installation
if(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "Darwin")
set(INSTALL_ROOT "" CACHE PATH "Root directory for installation")

Expand All @@ -50,14 +66,11 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "Darwin")

install(CODE "file(MAKE_DIRECTORY \"${INSTALL_ROOT}${DATA_INSTALL_DIR}\")")

install(TARGETS wazuh-agent
DESTINATION ${INSTALL_ROOT}${BIN_INSTALL_DIR})
install(TARGETS wazuh-agent DESTINATION ${INSTALL_ROOT}${BIN_INSTALL_DIR})

install(CODE "file(MAKE_DIRECTORY \"${INSTALL_ROOT}${CONFIG_INSTALL_DIR}\")")
install(FILES ${CONFIG_FOLDER}/wazuh-agent.yml
DESTINATION ${INSTALL_ROOT}${CONFIG_INSTALL_DIR})
install(TARGETS wazuh-agent
DESTINATION ${INSTALL_ROOT}${BIN_INSTALL_DIR})
install(FILES ${CONFIG_FOLDER}/wazuh-agent.yml DESTINATION ${INSTALL_ROOT}${CONFIG_INSTALL_DIR})
install(TARGETS wazuh-agent DESTINATION ${INSTALL_ROOT}${BIN_INSTALL_DIR})

message(STATUS "CMAKE_SYSTEM_NAME: ${CMAKE_SYSTEM_NAME}")

Expand All @@ -70,8 +83,7 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "Darwin")
file(WRITE "${OUTPUT_FILE}" "${FILE_CONTENTS}")

add_custom_target(generate_service_file ALL DEPENDS "${OUTPUT_FILE}")
install(FILES "${OUTPUT_FILE}"
DESTINATION "${INSTALL_ROOT}${SERVICE_INSTALL_DIR}")
install(FILES "${OUTPUT_FILE}" DESTINATION "${INSTALL_ROOT}${SERVICE_INSTALL_DIR}")

elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows")
set(CMAKE_INSTALL_SYSTEM_RUNTIME_DESTINATION .)
Expand All @@ -84,17 +96,19 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows")
set(CPACK_GENERATOR "WIX")
set(CPACK_PACKAGE_NAME "Wazuh Agent")
set(CPACK_PACKAGE_VERSION "5.0.0")

if(DEFINED ENV{CUSTOM_PACKAGE_NAME})
set(CPACK_PACKAGE_FILE_NAME "$ENV{CUSTOM_PACKAGE_NAME}")
else()
set(CPACK_PACKAGE_FILE_NAME "wazuh-agent-${CPACK_PACKAGE_VERSION}")
endif()

set(CPACK_PACKAGE_VENDOR "Wazuh, Inc.")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY
"Wazuh helps you to gain security visibility into your infrastructure "
"by monitoring hosts at an operating system and application level. "
"It provides capabilities like log analysis, file integrity monitoring, "
"intrusion detection, and compliance monitoring.")
"Wazuh helps you to gain security visibility into your infrastructure "
"by monitoring hosts at an operating system and application level. "
"It provides capabilities like log analysis, file integrity monitoring, "
"intrusion detection, and compliance monitoring.")
set(CPACK_PACKAGE_INSTALL_DIRECTORY "wazuh-agent")
set(CPACK_RESOURCE_FILE_LICENSE "${WINDOWS_FOLDER}/license.rtf")
set(CPACK_WIX_UPGRADE_GUID "F495AC57-7BDE-4C4B-92D8-DBE40A9AA5A0")
Expand Down
3 changes: 0 additions & 3 deletions src/agent/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
cmake_minimum_required(VERSION 3.22)

set(CMAKE_TOOLCHAIN_FILE "${CMAKE_SOURCE_DIR}/../vcpkg/scripts/buildsystems/vcpkg.cmake")
set(VCPKG_MANIFEST_DIR ${CMAKE_SOURCE_DIR}/../)

project(Agent)

include(../cmake/CommonSettings.cmake)
Expand Down
3 changes: 0 additions & 3 deletions src/agent/agent_info/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
cmake_minimum_required(VERSION 3.22)

set(CMAKE_TOOLCHAIN_FILE "${CMAKE_SOURCE_DIR}/../../vcpkg/scripts/buildsystems/vcpkg.cmake")
set(VCPKG_MANIFEST_DIR ${CMAKE_SOURCE_DIR}/../../)

project(AgentInfo)

include(../../cmake/CommonSettings.cmake)
Expand Down
3 changes: 0 additions & 3 deletions src/agent/command_handler/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
cmake_minimum_required(VERSION 3.22)

set(CMAKE_TOOLCHAIN_FILE "${CMAKE_SOURCE_DIR}/../../vcpkg/scripts/buildsystems/vcpkg.cmake")
set(VCPKG_MANIFEST_DIR ${CMAKE_SOURCE_DIR}/../../)

project(CommandHandler)

include(../../cmake/CommonSettings.cmake)
Expand Down
Loading

0 comments on commit 612e625

Please sign in to comment.