diff --git a/.gitignore b/.gitignore index 4e75a70..a2ecb25 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ __pycache__ /.mypy_cache .test-gadget/ build +.cache diff --git a/Dockerfile b/Dockerfile index d7341ad..08db015 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,6 +3,10 @@ FROM alpine:3.23 AS builder RUN apk update RUN apk add --no-cache build-base git RUN apk add --no-cache cmake cmake-doc cmake-extras pkgconf +RUN apk add --no-cache clang + +ENV CC=/usr/bin/clang +ENV CXX=/usr/bin/clang WORKDIR /usr/src/compiler @@ -10,6 +14,7 @@ COPY compiler . RUN rm -rf build + RUN mkdir build/ && cd build && cmake .. && make -j8 diff --git a/compiler/CMakeLists.txt b/compiler/CMakeLists.txt index 3df7f96..19b5df6 100644 --- a/compiler/CMakeLists.txt +++ b/compiler/CMakeLists.txt @@ -15,4 +15,4 @@ add_executable(compilers_compiler src/main.cpp) target_include_directories(compilers_compiler PRIVATE include) target_include_directories(compilers_compiler_lib PRIVATE include) -target_link_libraries(compilers_compiler compilers_compiler_lib -static) +target_link_libraries(compilers_compiler compilers_compiler_lib -static-libgcc -static-libstdc++) diff --git a/compiler/src/main.cpp b/compiler/src/main.cpp index 16b989c..e036282 100644 --- a/compiler/src/main.cpp +++ b/compiler/src/main.cpp @@ -1,11 +1,13 @@ +#include #include int main(int argc, char *argv[]) { - if (argc >= 2) { - std::cout << argv[1] << std::endl; - } else { - std::cout << "No args :(" << std::endl; + if (argc < 3) { + std::cout << "Incorrect arg count :(" << std::endl; + return 1; } + std::cout << argv[1] << argv[2] << std::endl; std::cout << "Hello world!" << std::endl; - return 0; + + std::ofstream result_file(argv[2]); } diff --git a/python-src/compiler/__main__.py b/python-src/compiler/__main__.py index 132c528..e823664 100644 --- a/python-src/compiler/__main__.py +++ b/python-src/compiler/__main__.py @@ -13,10 +13,25 @@ def call_compiler(source_code: str) -> bytes: # Raise an exception on compilation error. # *** TODO *** print("Compiling:", "./compilers_compiler", source_code) - response = subprocess.run(["./compilers_compiler", source_code], check=True, capture_output=True).stdout + import uuid + + # Give the compiler a file to write the result to + filename = "compile-result-" + str(uuid.uuid4()) + response = subprocess.run(["./compilers_compiler", source_code, filename], check=True, capture_output=True).stdout print(response) - return response + try: + # Read the updated file and fetch compiler result + with open(filename,"rb") as file_content: + content = file_content.read() + print(content) + + except FileNotFoundError as e: + print("File not found", filename, e) + content = b"" + + + return content def main() -> int: