Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,16 @@ find_package(Lua)
find_package(LibDataChannel)
find_package(re)
find_package(OpenDSSC)
find_package(FileSystem)

# Check for tools
find_program(PROTOBUFC_COMPILER NAMES protoc-c)
find_program(PROTOBUF_COMPILER NAMES protoc)
find_program(PASTE NAMES paste)
if(NOT PASTE)
message(SEND_ERROR "GNU paste is missing. Please install coreutils")
endif()

# Check programs
find_program(PROTOBUFC_COMPILER NAMES protoc-c)
find_program(PROTOBUF_COMPILER NAMES protoc)

# Build without any GPL-code
option(WITHOUT_GPL "Build VILLASnode without any GPL code" OFF)

set(ENV{PKG_CONFIG_PATH} "$ENV{PKG_CONFIG_PATH}:/usr/local/lib/pkgconfig:/usr/local/lib64/pkgconfig:/usr/local/share/pkgconfig:/usr/lib64/pkgconfig")

Expand Down Expand Up @@ -157,7 +154,15 @@ else()
set(FOUND_FPGA_SUBMODULES OFF)
endif()

if(CXX17_FILESYSTEM)
set(STDCXX_FS_NOT_FOUND OFF)
else()
set(STDCXX_FS_NOT_FOUND ON)
endif()

# Build options
cmake_dependent_option(WITHOUT_GPL "Build VILLASnode without any GPL code" OFF "" ON)
cmake_dependent_option(WITH_GHC_FS "Build using ghc::filesystem, a drop in replacement for std::filesystem" ON "STDCXX_FS_NOT_FOUND" OFF)
cmake_dependent_option(WITH_DEFAULTS "Defaults for non required build options" ON "" OFF)

cmake_dependent_option(WITH_API "Build with remote control API" "${WITH_DEFAULTS}" "" OFF)
Expand Down Expand Up @@ -206,7 +211,7 @@ cmake_dependent_option(WITH_NODE_WEBSOCKET "Build with websocket node-type"
cmake_dependent_option(WITH_NODE_ZEROMQ "Build with zeromq node-type" "${WITH_DEFAULTS}" "LIBZMQ_FOUND; NOT WITHOUT_GPL" OFF)
cmake_dependent_option(WITH_NODE_OPENDSS "Build with opendss node-type" "${WITH_DEFAULTS}" "OpenDSSC_FOUND" OFF)

# set a default for the build type
# Set a default for the build type
if("${CMAKE_BUILD_TYPE}" STREQUAL "")
set(CMAKE_BUILD_TYPE "Debug")
endif()
Expand All @@ -227,6 +232,11 @@ else()
add_compile_options(-Wno-error)
endif()

if(WITH_GHC_FS)
find_package(ghc_filesystem 1.5.14 REQUIRED)
include_directories($<TARGET_PROPERTY:ghcFilesystem::ghc_filesystem,INTERFACE_INCLUDE_DIRECTORIES>)
endif()

# Get version info and buildid from Git
GetVersion(${PROJECT_SOURCE_DIR} "CMAKE_PROJECT")

Expand Down
22 changes: 22 additions & 0 deletions cmake/FindFileSystem.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# CMakeLists.txt.
#
# Author: Steffen Vogel <post@steffenvogel.de>
# SPDX-FileCopyrightText: 2025 Steffen Vogel <steffen.vogel@opal-rt.com>
# SPDX-License-Identifier: Apache-2.0

set(FILESYSTEM_TEST_CODE "
#include <filesystem>

int main(void) {
return std::filesystem::is_regular_file(\"/\") ? 0 : 1;
}
")

include(CheckCXXSourceCompiles)
include(CMakePushCheckState)

cmake_push_check_state(RESET)
check_cxx_source_compiles("${FILESYSTEM_TEST_CODE}" CXX17_FILESYSTEM)
cmake_pop_check_state()

unset(FILESYSTEM_TEST_CODE)
1 change: 1 addition & 0 deletions common/include/villas/config.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,6 @@

// Library features
#cmakedefine FMT_LEGACY_OSTREAM_FORMATTER
#cmakedefine WITH_GHC_FS

// clang-format on
16 changes: 16 additions & 0 deletions common/include/villas/fs.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/* std::filesystem compatibility wrapper
*
* Author: Steffen Vogel <steffen.vogel@opal-rt.com>
* SPDX-FileCopyrightText: 2025, OPAL-RT Germany GmbH
* SPDX-License-Identifier: Apache-2.0
*/

#include <villas/config.hpp>

#ifdef WITH_GHC_FS
#include <ghc/filesystem.hpp>
namespace fs = ghc::filesystem;
#else
#include <filesystem>
namespace fs = std::filesystem;
#endif
6 changes: 3 additions & 3 deletions common/include/villas/kernel/devices/device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

#pragma once

#include <filesystem>
#include <optional>

#include <villas/fs.hpp>
#include <villas/kernel/devices/driver.hpp>

namespace villas {
Expand All @@ -24,8 +24,8 @@ class Device {
virtual std::optional<std::unique_ptr<Driver>> driver() const = 0;
virtual std::optional<int> iommu_group() const = 0;
virtual std::string name() const = 0;
virtual std::filesystem::path override_path() const = 0;
virtual std::filesystem::path path() const = 0;
virtual fs::path override_path() const = 0;
virtual fs::path path() const = 0;
virtual void probe() const = 0;
};

Expand Down
11 changes: 5 additions & 6 deletions common/include/villas/kernel/devices/ip_device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

#pragma once

#include <filesystem>
#include <vector>

#include <villas/fs.hpp>
#include <villas/kernel/devices/platform_device.hpp>

namespace villas {
Expand All @@ -19,21 +19,20 @@ namespace devices {

class IpDevice : public PlatformDevice {
public:
static IpDevice from(const std::filesystem::path unsafe_path);
static bool is_path_valid(const std::filesystem::path unsafe_path);
static IpDevice from(const fs::path unsafe_path);
static bool is_path_valid(const fs::path unsafe_path);

private:
IpDevice() = delete;
IpDevice(
const std::filesystem::path valid_path) //! Dont allow unvalidated paths
IpDevice(const fs::path valid_path) //! Dont allow unvalidated paths
: PlatformDevice(valid_path){};

public:
size_t addr() const;
std::string ip_name() const;

static std::vector<villas::kernel::devices::IpDevice>
from_directory(std::filesystem::path devices_directory);
from_directory(fs::path devices_directory);
};

} // namespace devices
Expand Down
19 changes: 9 additions & 10 deletions common/include/villas/kernel/devices/linux_driver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

#pragma once

#include <filesystem>
#include <fstream>
#include <iostream>

#include <villas/fs.hpp>
#include <villas/kernel/devices/driver.hpp>

namespace villas {
Expand All @@ -24,20 +24,19 @@ class LinuxDriver : public Driver {
static constexpr char UNBIND_DEFAULT[] = "unbind";

public:
const std::filesystem::path path;
const fs::path path;

private:
const std::filesystem::path bind_path;
const std::filesystem::path unbind_path;
const fs::path bind_path;
const fs::path unbind_path;

public:
LinuxDriver(const std::filesystem::path path)
: LinuxDriver(path, path / std::filesystem::path(BIND_DEFAULT),
path / std::filesystem::path(UNBIND_DEFAULT)){};
LinuxDriver(const fs::path path)
: LinuxDriver(path, path / fs::path(BIND_DEFAULT),
path / fs::path(UNBIND_DEFAULT)){};

LinuxDriver(const std::filesystem::path path,
const std::filesystem::path bind_path,
const std::filesystem::path unbind_path)
LinuxDriver(const fs::path path, const fs::path bind_path,
const fs::path unbind_path)
: path(path), bind_path(bind_path), unbind_path(unbind_path){};

public:
Expand Down
24 changes: 11 additions & 13 deletions common/include/villas/kernel/devices/platform_device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@

#pragma once

#include <filesystem>

#include <villas/fs.hpp>
#include <villas/kernel/devices/device.hpp>
#include <villas/kernel/devices/driver.hpp>

Expand All @@ -23,27 +22,26 @@ class PlatformDevice : public Device {
static constexpr char OVERRIDE_DEFAULT[] = "driver_override";

private:
const std::filesystem::path m_path;
const std::filesystem::path m_probe_path;
const std::filesystem::path m_override_path;
const fs::path m_path;
const fs::path m_probe_path;
const fs::path m_override_path;

public:
PlatformDevice(const std::filesystem::path path)
: PlatformDevice(path, std::filesystem::path(PROBE_DEFAULT),
path / std::filesystem::path(OVERRIDE_DEFAULT)){};
PlatformDevice(const fs::path path)
: PlatformDevice(path, fs::path(PROBE_DEFAULT),
path / fs::path(OVERRIDE_DEFAULT)){};

PlatformDevice(const std::filesystem::path path,
const std::filesystem::path probe_path,
const std::filesystem::path override_path)
PlatformDevice(const fs::path path, const fs::path probe_path,
const fs::path override_path)
: m_path(path), m_probe_path(probe_path),
m_override_path(override_path){};

// Implement device interface
std::optional<std::unique_ptr<Driver>> driver() const override;
std::optional<int> iommu_group() const override;
std::string name() const override;
std::filesystem::path override_path() const override;
std::filesystem::path path() const override;
fs::path override_path() const override;
fs::path path() const override;
void probe() const override;
};

Expand Down
7 changes: 3 additions & 4 deletions common/include/villas/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include <cassert>
#include <cstdint>
#include <cstdlib>
#include <filesystem>
#include <list>
#include <string>
#include <vector>
Expand All @@ -22,6 +21,7 @@
#include <sys/types.h>

#include <villas/config.hpp>
#include <villas/fs.hpp>

#ifdef __GNUC__
#define LIKELY(x) __builtin_expect((x), 1)
Expand Down Expand Up @@ -212,9 +212,8 @@ template <class... Ts> struct overloaded : Ts... {
// Explicit deduction guide (not needed as of C++20)
template <class... Ts> overloaded(Ts...) -> overloaded<Ts...>;

void write_to_file(std::string data, const std::filesystem::path file);
std::vector<std::string>
read_names_in_directory(const std::filesystem::path &directory);
void write_to_file(std::string data, const fs::path file);
std::vector<std::string> read_names_in_directory(const fs::path &directory);

namespace base64 {

Expand Down
3 changes: 1 addition & 2 deletions common/lib/kernel/devices/device_connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ DeviceConnection DeviceConnection::from(
auto logger = villas::Log::get("Builder: DeviceConnection");

// Bind the devicetree device to vfio driver
LinuxDriver driver(
std::filesystem::path("/sys/bus/platform/drivers/vfio-platform"));
LinuxDriver driver(fs::path("/sys/bus/platform/drivers/vfio-platform"));
driver.attach(device);

// Attach vfio container to the iommu group
Expand Down
11 changes: 5 additions & 6 deletions common/lib/kernel/devices/ip_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@
* SPDX-License-Identifier: Apache-2.0
*/

#include <filesystem>
#include <regex>
#include <stdexcept>

#include <villas/exceptions.hpp>
#include <villas/fs.hpp>
#include <villas/kernel/devices/ip_device.hpp>
#include <villas/utils.hpp>

using villas::kernel::devices::IpDevice;

IpDevice IpDevice::from(const std::filesystem::path unsafe_path) {
IpDevice IpDevice::from(const fs::path unsafe_path) {
if (!is_path_valid(unsafe_path))
throw RuntimeError(
"Path {} failed validation as IpDevicePath [adress in hex].[name] ",
Expand All @@ -42,7 +42,7 @@ size_t IpDevice::addr() const {
return addr;
}

bool IpDevice::is_path_valid(const std::filesystem::path unsafe_path) {
bool IpDevice::is_path_valid(const fs::path unsafe_path) {
std::string assumed_device_name = unsafe_path.filename();

// Match format of hexaddr.devicename
Expand All @@ -55,15 +55,14 @@ bool IpDevice::is_path_valid(const std::filesystem::path unsafe_path) {
}

std::vector<villas::kernel::devices::IpDevice>
IpDevice::from_directory(std::filesystem::path devices_directory) {
IpDevice::from_directory(fs::path devices_directory) {
std::vector<villas::kernel::devices::IpDevice> devices;

const std::vector<std::string> devicetree_names =
villas::utils::read_names_in_directory(devices_directory);

for (auto devicetree_name : devicetree_names) {
auto path_to_device =
devices_directory / std::filesystem::path(devicetree_name);
auto path_to_device = devices_directory / fs::path(devicetree_name);
try {
auto device = villas::kernel::devices::IpDevice::from(path_to_device);
devices.push_back(device);
Expand Down
19 changes: 7 additions & 12 deletions common/lib/kernel/devices/platform_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,36 +15,31 @@ using villas::kernel::devices::PlatformDevice;
using villas::utils::write_to_file;

std::optional<std::unique_ptr<Driver>> PlatformDevice::driver() const {
std::filesystem::path driver_symlink =
this->m_path / std::filesystem::path("driver");
fs::path driver_symlink = this->m_path / fs::path("driver");

if (!std::filesystem::is_symlink(driver_symlink))
if (!fs::is_symlink(driver_symlink))
return std::nullopt;

std::filesystem::path driver_path =
std::filesystem::canonical(driver_symlink);
fs::path driver_path = fs::canonical(driver_symlink);
return std::make_optional(std::make_unique<LinuxDriver>(driver_path));
}

std::optional<int> PlatformDevice::iommu_group() const {
std::filesystem::path symlink =
std::filesystem::path(this->m_path.u8string() + "/iommu_group");
fs::path symlink = fs::path(this->m_path.u8string() + "/iommu_group");

std::filesystem::path link = std::filesystem::read_symlink(symlink);
fs::path link = fs::read_symlink(symlink);
std::string delimiter = "iommu_groups/";
int pos = link.u8string().find(delimiter);
int iommu_group = std::stoi(link.u8string().substr(pos + delimiter.length()));
return std::make_optional<int>(iommu_group);
}

std::filesystem::path PlatformDevice::path() const { return this->m_path; };
fs::path PlatformDevice::path() const { return this->m_path; };

void PlatformDevice::probe() const {
write_to_file(this->name(), this->m_probe_path);
}

std::filesystem::path PlatformDevice::override_path() const {
return this->m_override_path;
}
fs::path PlatformDevice::override_path() const { return this->m_override_path; }

std::string PlatformDevice::name() const { return this->m_path.filename(); }
Loading