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 C support #8

Open evgenyigumnov opened 1 month ago

evgenyigumnov commented 1 month ago

Launch example

rustsn --lang=c

Example query:

take 2 params and add them and return result

Example generation:

Makefile

CC = gcc
CFLAGS = -Wall -Wextra -g
TARGET = solution
TEST_TARGET = test_solution

all: $(TARGET)

$(TARGET): src/solution.c include/solution.h
    $(CC) $(CFLAGS) -o $(TARGET) src/solution.c

test: $(TEST_TARGET)
    ./$(TEST_TARGET)

$(TEST_TARGET): tests/test_solution.c src/solution.c include/solution.h
    $(CC) $(CFLAGS) -o $(TEST_TARGET) tests/test_solution.c src/solution.c

clean:
    rm -f $(TARGET) $(TEST_TARGET)

include/solution.h

#ifndef SOLUTION_H
#define SOLUTION_H

int solution(int a, int b);

#endif // SOLUTION_H

src/solution.c

#include "solution.h"

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

tests/test_solution.c

#include <assert.h>
#include "solution.h"

int main() {
    // Test 1
    assert(solution(1, 2) == 3);

    // Test 2
    assert(solution(-1, -2) == -3);

    // Test 3
    // Note: C is statically typed, so adding a string and an integer isn't directly applicable.
    // This test is omitted or can be adapted as needed.

    return 0;
}

Example install dependencies

Ensure you have GCC installed. On most systems, you can install it using:

# For Debian/Ubuntu
sudo apt-get update
sudo apt-get install build-essential

# For macOS using Homebrew
brew install gcc

Example launch compilation

make

Example launch test

make test

Directory Structure:

c/
├── Makefile
├── logic.md
├── prompt.txt
├── include/
│   └── solution.h
├── src/
│   └── solution.c
└── tests/
    └── test_solution.c
evgenyigumnov commented 1 month ago

Issues have to be optimazed for Linux OS