diff --git a/src/compilerServices/clangService.ts b/src/compilerServices/clangService.ts index 43eea7596..e03eaa4dd 100644 --- a/src/compilerServices/clangService.ts +++ b/src/compilerServices/clangService.ts @@ -31,23 +31,26 @@ export class ClangService implements CompilerService { async compile(input: ServiceInput): Promise { const files = Object.values(input.files); - if (files.length !== 1) { - throw new Error(`Supporting compilation of a single file, but ${files.length} file(s) found`); - } const [ fileRef ] = Object.keys(input.files); - const src = files[0].content; const from = this.lang; + const inputFile=Object.keys(input.files); + const File = function(inputFile:any,file:any){ + const compileFile =[]; + for(let i=0;i { + static async compileFiles(files: Array, from: Language, to: Language, options = ""): Promise<{ [name: string]: (string|ArrayBuffer); }> { gaEvent("compile", "Service", `${from}->${to}`); const service = await createCompilerService(from, to); - - const fileNameMap: {[name: string]: File} = files.reduce((acc: any, f: File) => { + const fileNameMap: {[name: string]: File} = files[0].reduce((acc: any, f: any) => { acc[getProjectFilePath(f)] = f; return acc; }, {} as any); const input = { - files: files.reduce((acc: any, f: File) => { + files: files[0].reduce((acc: any, f: File) => { acc[getProjectFilePath(f)] = { content: f.getData(), }; @@ -218,7 +218,7 @@ export class Service { }; const result = await service.compile(input); - for (const file of files) { + for (const file of files[0]) { file.setProblems([]); } diff --git a/templates/hello_world_c/build.ts b/templates/hello_world_c/build.ts index 626bb3aad..f7249addf 100644 --- a/templates/hello_world_c/build.ts +++ b/templates/hello_world_c/build.ts @@ -2,7 +2,7 @@ import * as gulp from "gulp"; import { Service, project } from "@wasm/studio-utils"; gulp.task("build", async () => { - const data = await Service.compileFile(project.getFile("src/main.c"), "c", "wasm", "-g -O3"); + const data = await Service.compileFile([project.getFile("src/main.c"),project.getFile("src/header.h")], "c", "wasm", "-g -O3"); const outWasm = project.newFile("out/main.wasm", "wasm", true); outWasm.setData(data); }); diff --git a/templates/hello_world_c/src/header.h b/templates/hello_world_c/src/header.h new file mode 100644 index 000000000..63063556d --- /dev/null +++ b/templates/hello_world_c/src/header.h @@ -0,0 +1,3 @@ +int hello(int a,int b){ +return a+b; +} diff --git a/templates/hello_world_c/src/main.c b/templates/hello_world_c/src/main.c index 241126fc9..a02cb79e3 100644 --- a/templates/hello_world_c/src/main.c +++ b/templates/hello_world_c/src/main.c @@ -1,10 +1,13 @@ #include #include +#include "header.h" #define WASM_EXPORT __attribute__((visibility("default"))) WASM_EXPORT int main(void) { + int c= hello(3,2);//you can define any function in headerfile and use it here.It is just an example. + printf("%d",c); printf("Hello World\n"); }