mirror of
https://github.com/momo5502/emulator.git
synced 2026-01-18 03:13:55 +00:00
Add Android support (#77)
This commit is contained in:
23
.github/workflows/build.yml
vendored
23
.github/workflows/build.yml
vendored
@@ -56,6 +56,8 @@ jobs:
|
||||
- Linux GCC
|
||||
- Linux Clang
|
||||
- macOS
|
||||
- Android x86_64
|
||||
- Android arm64-v8a
|
||||
configuration:
|
||||
- Debug
|
||||
- Release
|
||||
@@ -73,6 +75,12 @@ jobs:
|
||||
clang-version: 18
|
||||
- platform: macOS
|
||||
runner: macos-latest
|
||||
- platform: Android x86_64
|
||||
runner: ubuntu-24.04
|
||||
abi: x86_64
|
||||
- platform: Android arm64-v8a
|
||||
runner: ubuntu-24.04
|
||||
abi: arm64-v8a
|
||||
steps:
|
||||
- name: Checkout Source
|
||||
uses: actions/checkout@v4
|
||||
@@ -100,8 +108,23 @@ jobs:
|
||||
uses: ilammy/msvc-dev-cmd@v1.13.0
|
||||
if: "${{ matrix.platform == 'Windows' }}"
|
||||
|
||||
- uses: nttld/setup-ndk@v1
|
||||
id: setup-ndk
|
||||
if: ${{ startsWith(matrix.platform, 'Android') }}
|
||||
with:
|
||||
ndk-version: r26d
|
||||
add-to-path: false
|
||||
|
||||
- name: CMake Build
|
||||
run: cmake --preset=${{matrix.preset}} -DCMAKE_TOOLCHAIN_FILE=${{ github.workspace }}/cmake/toolchain/android-ndk.cmake && cmake --build --preset=${{matrix.preset}}
|
||||
if: ${{ startsWith(matrix.platform, 'Android') }}
|
||||
env:
|
||||
ANDROID_NDK_ROOT: ${{ steps.setup-ndk.outputs.ndk-path }}
|
||||
ANDROID_ABI: ${{matrix.abi}}
|
||||
|
||||
- name: CMake Build
|
||||
run: cmake --workflow --preset=${{matrix.preset}}
|
||||
if: ${{ !startsWith(matrix.platform, 'Android') }}
|
||||
|
||||
- name: Upload Artifacts
|
||||
uses: actions/upload-artifact@v4
|
||||
|
||||
6
cmake/toolchain/android-ndk.cmake
Normal file
6
cmake/toolchain/android-ndk.cmake
Normal file
@@ -0,0 +1,6 @@
|
||||
set(CMAKE_SYSTEM_NAME "Android")
|
||||
set(CMAKE_ANDROID_NDK "$ENV{ANDROID_NDK_ROOT}")
|
||||
|
||||
set(ANDROID_ABI "$ENV{ANDROID_ABI}")
|
||||
set(CMAKE_ANDROID_ARCH_ABI "${ANDROID_ABI}")
|
||||
set(CMAKE_ANDROID_API "24")
|
||||
61
src/common/utils/path_key.hpp
Normal file
61
src/common/utils/path_key.hpp
Normal file
@@ -0,0 +1,61 @@
|
||||
#pragma once
|
||||
|
||||
#include "string.hpp"
|
||||
#include <filesystem>
|
||||
|
||||
namespace utils
|
||||
{
|
||||
class path_key
|
||||
{
|
||||
public:
|
||||
path_key() = default;
|
||||
path_key(const std::filesystem::path& p)
|
||||
: path_(canonicalize_path(p))
|
||||
{
|
||||
}
|
||||
|
||||
path_key(const path_key&) = default;
|
||||
path_key(path_key&&) noexcept = default;
|
||||
|
||||
path_key& operator=(const path_key&) = default;
|
||||
path_key& operator=(path_key&&) noexcept = default;
|
||||
|
||||
~path_key() = default;
|
||||
|
||||
const std::filesystem::path& get() const
|
||||
{
|
||||
return this->path_;
|
||||
}
|
||||
|
||||
bool operator==(const path_key& other) const
|
||||
{
|
||||
return this->get() == other.get();
|
||||
}
|
||||
|
||||
bool operator!=(const path_key& other) const
|
||||
{
|
||||
return !this->operator==(other);
|
||||
}
|
||||
|
||||
static std::filesystem::path canonicalize_path(const std::filesystem::path& key)
|
||||
{
|
||||
auto path = key.lexically_normal().wstring();
|
||||
return utils::string::to_lower_consume(path);
|
||||
}
|
||||
|
||||
private:
|
||||
std::filesystem::path path_{};
|
||||
};
|
||||
}
|
||||
|
||||
namespace std
|
||||
{
|
||||
template <>
|
||||
struct hash<utils::path_key>
|
||||
{
|
||||
size_t operator()(const utils::path_key& p) const noexcept
|
||||
{
|
||||
return hash<std::filesystem::path::string_type>()(p.get().native());
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <span>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <stdexcept>
|
||||
#include <cstring>
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
#include <chrono>
|
||||
#include <filesystem>
|
||||
#include <utils/path_key.hpp>
|
||||
|
||||
namespace utils
|
||||
{
|
||||
@@ -44,4 +45,14 @@ namespace utils
|
||||
{
|
||||
path = buffer.read_string<char16_t>();
|
||||
}
|
||||
|
||||
inline void serialize(buffer_serializer& buffer, const path_key& path)
|
||||
{
|
||||
buffer.write(path.get());
|
||||
}
|
||||
|
||||
inline void deserialize(buffer_deserializer& buffer, path_key& path)
|
||||
{
|
||||
path = buffer.read<std::filesystem::path>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,12 +7,6 @@
|
||||
|
||||
namespace
|
||||
{
|
||||
std::filesystem::path canonicalize_path(const std::filesystem::path& key)
|
||||
{
|
||||
auto path = key.lexically_normal().wstring();
|
||||
return utils::string::to_lower_consume(path);
|
||||
}
|
||||
|
||||
bool is_subpath(const std::filesystem::path& root, const std::filesystem::path& p)
|
||||
{
|
||||
auto root_it = root.begin();
|
||||
@@ -32,7 +26,7 @@ namespace
|
||||
void register_hive(registry_manager::hive_map& hives, const std::filesystem::path& key,
|
||||
const std::filesystem::path& file)
|
||||
{
|
||||
hives[canonicalize_path(key)] = std::make_unique<hive_parser>(file);
|
||||
hives[key] = std::make_unique<hive_parser>(file);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,22 +74,22 @@ void registry_manager::deserialize(utils::buffer_deserializer& buffer)
|
||||
|
||||
std::filesystem::path registry_manager::normalize_path(const std::filesystem::path& path) const
|
||||
{
|
||||
auto canonical_path = canonicalize_path(path);
|
||||
const utils::path_key canonical_path = path;
|
||||
|
||||
for (const auto& mapping : this->path_mapping_)
|
||||
{
|
||||
if (is_subpath(mapping.first, canonical_path))
|
||||
if (is_subpath(mapping.first.get(), canonical_path.get()))
|
||||
{
|
||||
return mapping.second / canonical_path.lexically_relative(mapping.first);
|
||||
return mapping.second.get() / canonical_path.get().lexically_relative(mapping.first.get());
|
||||
}
|
||||
}
|
||||
|
||||
return canonical_path;
|
||||
return canonical_path.get();
|
||||
}
|
||||
|
||||
void registry_manager::add_path_mapping(const std::filesystem::path& key, const std::filesystem::path& value)
|
||||
{
|
||||
this->path_mapping_[canonicalize_path(key)] = canonicalize_path(value);
|
||||
this->path_mapping_[key] = value;
|
||||
}
|
||||
|
||||
std::optional<registry_key> registry_manager::get_key(const std::filesystem::path& key)
|
||||
@@ -116,7 +110,7 @@ std::optional<registry_key> registry_manager::get_key(const std::filesystem::pat
|
||||
}
|
||||
|
||||
registry_key reg_key{};
|
||||
reg_key.hive = iterator->first;
|
||||
reg_key.hive = iterator->first.get();
|
||||
reg_key.path = normal_key.lexically_relative(reg_key.hive);
|
||||
|
||||
if (reg_key.path.empty())
|
||||
@@ -161,7 +155,7 @@ registry_manager::hive_map::iterator registry_manager::find_hive(const std::file
|
||||
{
|
||||
for (auto i = this->hives_.begin(); i != this->hives_.end(); ++i)
|
||||
{
|
||||
if (is_subpath(i->first, key))
|
||||
if (is_subpath(i->first.get(), key))
|
||||
{
|
||||
return i;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include "../std_include.hpp"
|
||||
#include <serialization_helper.hpp>
|
||||
#include "hive_parser.hpp"
|
||||
#include "serialization_helper.hpp"
|
||||
|
||||
struct registry_key
|
||||
{
|
||||
@@ -33,7 +33,7 @@ class registry_manager
|
||||
{
|
||||
public:
|
||||
using hive_ptr = std::unique_ptr<hive_parser>;
|
||||
using hive_map = std::unordered_map<std::filesystem::path, hive_ptr>;
|
||||
using hive_map = std::unordered_map<utils::path_key, hive_ptr>;
|
||||
|
||||
registry_manager();
|
||||
registry_manager(const std::filesystem::path& hive_path);
|
||||
@@ -54,7 +54,7 @@ class registry_manager
|
||||
private:
|
||||
std::filesystem::path hive_path_{};
|
||||
hive_map hives_{};
|
||||
std::unordered_map<std::filesystem::path, std::filesystem::path> path_mapping_{};
|
||||
std::unordered_map<utils::path_key, utils::path_key> path_mapping_{};
|
||||
|
||||
std::filesystem::path normalize_path(const std::filesystem::path& path) const;
|
||||
void add_path_mapping(const std::filesystem::path& key, const std::filesystem::path& value);
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <list>
|
||||
#include <span>
|
||||
#include <array>
|
||||
#include <deque>
|
||||
#include <queue>
|
||||
@@ -52,6 +53,7 @@
|
||||
#include <stdexcept>
|
||||
#include <string_view>
|
||||
#include <unordered_set>
|
||||
#include <unordered_map>
|
||||
#include <condition_variable>
|
||||
|
||||
#include <cassert>
|
||||
|
||||
Reference in New Issue
Block a user