evgenyigumnov / rustsn

This Rust-based tool generates, compiles, and tests code using LLMs, resolves dependencies, and provides explanations of existing code through embeddings.
Apache License 2.0
60 stars 15 forks source link

Add CPP support #9

Open evgenyigumnov opened 1 month ago

evgenyigumnov commented 1 month ago

Launch example

rustsn --lang=cpp

Example query:

take 2 params and add them and return result

Example generation:

CMakeLists.txt

cmake_minimum_required(VERSION 3.10)
project(solution)

set(CMAKE_CXX_STANDARD 17)

# Enable testing
enable_testing()

# Add the solution library
add_library(solution src/solution.cpp)

# Find GoogleTest
find_package(GTest REQUIRED)
include_directories(${GTEST_INCLUDE_DIRS})

# Add the test executable
add_executable(solution_test tests/solution_test.cpp)

# Link libraries
target_link_libraries(solution_test solution ${GTEST_LIBRARIES} pthread)

# Add tests
add_test(NAME SolutionTest COMMAND solution_test)

src/solution.cpp

#include "solution.h"

int solution(int a, int b) {
    return a + b;
}

src/solution.h

#ifndef SOLUTION_H
#define SOLUTION_H

int solution(int a, int b);

#endif // SOLUTION_H

tests/solution_test.cpp

#include <gtest/gtest.h>
#include "solution.h"

TEST(SolutionTest, Test1) {
    EXPECT_EQ(solution(1, 2), 3);
}

TEST(SolutionTest, Test2) {
    EXPECT_EQ(solution(-1, -2), -3);
}

TEST(SolutionTest, Test3) {
    EXPECT_EQ(solution(1, -2), -1);
}

Example install dependencies

# Install build essentials and CMake
sudo apt-get update
sudo apt-get install -y build-essential cmake

# Install Google Test
sudo apt-get install -y libgtest-dev
cd /usr/src/gtest
sudo cmake .
sudo make
sudo cp libgtest*.a /usr/lib/

# Navigate back to your project directory
cd ~/path_to_your_project/cpp

Example build

mkdir build
cd build
cmake ..
make

Example launch tests

ctest
evgenyigumnov commented 1 month ago

Issues have to be optimazed for Windows OS