CoolFace
Apppublic

avciTheProgrammer/automotive-compiler

sourceHugging Faceupdated 7mo agoView on Hugging Face
0likes
App README

C Compiler API

Public API for compiling and running C code using GCC, Clang, or PC-Lint (Splint).

๐Ÿš€ Public Endpoints

Base URL: Replace with your actual space URL

GET /

Get API information and available endpoints

Example:

bash
curl https://YOUR-USERNAME-SPACE-NAME.hf.space/

GET /health

Health check endpoint

Example:

bash
curl https://YOUR-USERNAME-SPACE-NAME.hf.space/health

POST /compile

Compile and execute C code

Request Body:

json
{
  "code": "#include <stdio.h>\nint main() {\n    printf(\"Hello World\\n\");\n    return 0;\n}",
  "filename": "main.c",
  "compiler": "gcc"
}

Response:

json
{
  "success": true,
  "output": "",
  "errors": "",
  "executable_output": "Hello World\n"
}

Example with curl:

bash
curl -X POST https://YOUR-USERNAME-SPACE-NAME.hf.space/compile \
  -H "Content-Type: application/json" \
  -d '{
    "code": "#include <stdio.h>\nint main() { printf(\"Hello\\n\"); return 0; }",
    "compiler": "gcc"
  }'

Example with JavaScript:

javascript
const response = await fetch('https://YOUR-USERNAME-SPACE-NAME.hf.space/compile', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    code: '#include <stdio.h>\nint main() { printf("Hello\\n"); return 0; }',
    compiler: 'gcc'
  })
});
const result = await response.json();
console.log(result);

๐Ÿ”ง Supported Compilers

  • โ€”gcc - GNU C Compiler
  • โ€”clang - Clang C Compiler
  • โ€”pclint - PC-Lint (uses Splint as open-source alternative)

๐Ÿ“š API Documentation

Interactive API docs available at:

  • โ€”Swagger UI: /docs
  • โ€”ReDoc: /redoc

โš™๏ธ Features

  • โ€”โœ… Compile C code with multiple compilers
  • โ€”โœ… Execute compiled programs safely
  • โ€”โœ… Get compilation errors and warnings
  • โ€”โœ… Capture program output
  • โ€”โœ… CORS enabled for web applications
  • โ€”โœ… Automatic timeout protection

๐Ÿ”’ Security

  • โ€”Code execution is sandboxed in temporary directories
  • โ€”10-second compilation timeout
  • โ€”5-second execution timeout
  • โ€”Automatic cleanup of temporary files
  • โ€”No persistent storage

๐Ÿ“ Notes

  • โ€”This API is public and free to use
  • โ€”Rate limits may apply based on Hugging Face Spaces limits
  • โ€”For PC-Lint, this uses Splint (open-source alternative) as PC-Lint is proprietary