Skip to content
This repository has been archived by the owner on Mar 8, 2024. It is now read-only.
/ clang.js Public archive

☁️ Run C/C++ in the Browser. | 在浏览器实时运行 C/C++ 代码

License

Notifications You must be signed in to change notification settings

luoxuhai/clang.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Clang.js

Run C/C++ in the Browser.

Overview

Live Demo

This repo is extending the great work from Ben Smith published in his CppCon 2019 WebAssembly talk. The WebAssembly binaries are copied from Ben's fork of llvm-project.

Installation

# NPM
npm install clang.js

# Yarn
yarn add clang.js

Usage

import { init, run } from 'clang.js';

async function main() {
  await init({
    // The path to the wasm resources:
    // - clang.wasm
    // - lld.wasm
    // - memfs.wasm
    // - sysroot.tar
    path: 'https://cdn.jsdelivr.net/npm/clang.js/dist',
  });

  const code = `
    #include <iostream>
    using namespace std;

    int fib(int n) {
      if (n < 2) return n;
      return fib(n-1) + fib(n-2);
    }

    int main() {
      cout << "fib(10) = " << fib(10) << endl;
    }`;
  
  run(code);
}

main();

Roadmap

  • Support for multiple code files
  • Support operation WebGL

License

Apache-2.0