Skip to content

Commit 79954b1

Browse files
committed
[windows CI] get protobuf binaries from external source
1 parent 94fdac9 commit 79954b1

5 files changed

Lines changed: 53 additions & 23 deletions

File tree

.github/workflows/windows.yml

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,31 +15,36 @@ jobs:
1515

1616
- name: Install LLVM
1717
run: choco install -y llvm
18-
if: runner.os == 'Windows'
18+
- name: Install Ninja
19+
run: choco install -y ninja
1920

20-
- name: windows vcpkg shit
21-
# https://vcpkg.io/en/getting-started.html
21+
- name: Download protobuf
2222
run: |
23-
git clone https://github.com/Microsoft/vcpkg.git
24-
./vcpkg/bootstrap-vcpkg.sh
25-
vcpkg install protobuf protobuf:x64-windows
26-
vcpkg owns protobuf
27-
ls vcpkg/scripts/buildsystems/vcpkg.cmake
23+
Invoke-WebRequest "https://github.com/protocolbuffers/protobuf/releases/download/v21.12/protoc-21.12-win64.zip" -OutFile protoc_x64-windows.zip
24+
mkdir protoc_x64-windows
25+
7z x protoc_x64-windows.zip -oprotoc_x64-windows
26+
dir
27+
Invoke-WebRequest "https://www.dropbox.com/scl/fi/te9p80zrzcwgswrkw21en/protobuf_x64-windows.zip?rlkey=btmzjokhh256xxns348o3re7m&dl=1" -OutFile protobuf_x64-windows.zip
28+
7z x protobuf_x64-windows.zip
29+
dir
30+
2831
- name: CMake generate
32+
shell: bash
2933
env:
3034
ARTIFACT_NAME: ppc2cpp-${{ runner.os }}
3135
run: |
32-
echo $WINDOWS_FLAGS
33-
cmake --version
34-
cmake -B build \
36+
cmake -S . -B build -GNinja \
3537
-DCMAKE_INSTALL_PREFIX=$ARTIFACT_NAME \
3638
-DCMAKE_BUILD_TYPE=Release \
3739
-DBUILD_TESTING=OFF \
3840
-DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ \
39-
-S . -DCMAKE_TOOLCHAIN_FILE=vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-windows-static -DCMAKE_GENERATOR_PLATFORM=x64
40-
shell: bash
41+
-DEXTERNAL_LIBPROTOBUF_PATH=protobuf_x64-windows \
42+
-DEXTERNAL_PROTOC_PATH=protoc_x64-windows
4143
- name: Build
42-
run: cmake --build build --target install -j
44+
shell: bash
45+
working-directory: ${{github.workspace}}/build
46+
run: |
47+
cmake --build . --target install --parallel
4348
4449
- uses: actions/upload-artifact@v3
4550
if: github.ref == 'refs/heads/main' && github.repository == 'em-eight/ppc2cpp'

CMakeLists.txt

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,37 @@ CPMAddPackage("gh:fmtlib/fmt#10.0.0")
3434

3535
set(Protobuf_USE_STATIC_LIBS ON)
3636

37-
find_package(protobuf CONFIG)
38-
if(NOT protobuf_FOUND) # Legacy protobuf support
39-
message(STATUS "Trying legacy method of finding protobuf")
37+
if(DEFINED EXTERNAL_LIBPROTOBUF_PATH AND DEFINED EXTERNAL_PROTOC_PATH)
38+
# In case protobuf location is defined externally (Windows/CI hack)
39+
find_package(Protobuf) # fails but defines protobuf_generate_cpp lmaoooo
40+
cmake_path(SET Protobuf_LIBRARIES ${EXTERNAL_LIBPROTOBUF_PATH}/lib/libprotobuf.lib)
41+
cmake_path(SET PROTOBUF_INCLUDE_DIRS ${EXTERNAL_LIBPROTOBUF_PATH}/include)
42+
cmake_path(SET Protobuf_PROTOC_EXECUTABLE ${EXTERNAL_PROTOC_PATH}/bin/protoc.exe)
43+
44+
message(STATUS "GONNA DEBUG STUFF")
45+
get_filename_component(ABSOLUTE_PROTOC_EXE ${Protobuf_PROTOC_EXECUTABLE} ABSOLUTE)
46+
message(STATUS ${ABSOLUTE_PROTOC_EXE})
47+
set(Protobuf_PROTOC_EXECUTABLE ${ABSOLUTE_PROTOC_EXE})
48+
49+
get_filename_component(ABSOLUTE_PROTOBUF_INCLUDE ${PROTOBUF_INCLUDE_DIRS} ABSOLUTE)
50+
message(STATUS ${ABSOLUTE_PROTOBUF_INCLUDE})
51+
set(PROTOBUF_INCLUDE_DIRS ${ABSOLUTE_PROTOBUF_INCLUDE})
52+
53+
get_filename_component(ABSOLUTE_PROTOBUF_LIB ${Protobuf_LIBRARIES} ABSOLUTE)
54+
message(STATUS ${ABSOLUTE_PROTOBUF_LIB})
55+
set(Protobuf_LIBRARIES ${ABSOLUTE_PROTOBUF_LIB})
56+
57+
add_executable(protobuf::protoc IMPORTED)
58+
set_target_properties(protobuf::protoc PROPERTIES IMPORTED_LOCATION "${Protobuf_PROTOC_EXECUTABLE}")
4059
set(protobuf_MODULE_COMPATIBLE ON)
41-
include(FindProtobuf)
42-
find_package(Protobuf REQUIRED)
60+
else()
61+
find_package(protobuf CONFIG)
62+
if(NOT protobuf_FOUND) # Legacy protobuf support
63+
message(STATUS "Trying legacy method of finding protobuf")
64+
set(protobuf_MODULE_COMPATIBLE ON)
65+
include(FindProtobuf)
66+
find_package(Protobuf REQUIRED)
67+
endif()
4368
endif()
4469

4570
# Generate Protobuf files

src/cli/ppc2cpp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ void cli_create(int argc, char** argv) {
5454
print_create_usage(5);
5555
}
5656
if (options.projectName.size() == 0) {
57-
options.projectName = options.projectFile.stem();
57+
options.projectName = options.projectFile.stem().string();
5858
}
5959
if (options.inputFiles.size() == 0) {
6060
print_create_usage(6);

src/program_loader/Binary.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
namespace ppc2cpp {
88
Binary::Binary(std::filesystem::path binaryPath) {
99
this->filepath = binaryPath;
10-
this->name = binaryPath.filename();
10+
this->name = binaryPath.filename().string();
1111

1212
std::ifstream fstream(binaryPath, std::ios::binary | std::ios::in);
1313
if (!fstream.is_open()) throw std::runtime_error("Input file " + binaryPath.string() + " was not found");
@@ -27,7 +27,7 @@ std::optional<BinaryLocation> Binary::resolveVMA(uint32_t vma) {
2727
}
2828

2929
void Binary::toProto(persistence::ProgramLoaderBinary* binaryProto) const {
30-
binaryProto->set_filepath(this->filepath);
30+
binaryProto->set_filepath(this->filepath.string());
3131
binaryProto->set_data(this->data);
3232
}
3333
}

src/program_loader/NinProgramLoader.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
namespace ppc2cpp {
1414
NinProgramLoader::NinProgramLoader(const std::vector<std::filesystem::path>& binaryPaths) {
1515
for (const auto& binaryPath : binaryPaths) {
16-
std::string filename = binaryPath.filename();
16+
std::string filename = binaryPath.filename().string();
1717
std::ifstream fstream(binaryPath, std::ios::binary | std::ios::in);
1818
if (!fstream.is_open()) throw std::runtime_error("Input file " + binaryPath.string() + " was not found");
1919
std::stringstream sstream;

0 commit comments

Comments
 (0)