Search code examples
pythonrustcompilation

The ability to compile a rust program using python


I would like to call the compilation of a rust program from a python script. Are there any options to pull this off?

def compile():
    binary_file = rust_compile(path, release=True)
    return binary_file

Solution

  • You can use the library subprocess to execute console commands and doing so execute the rust compiler.

    subprocess.run(["rustc","program.rc"])

    And then get the path of the binary file