Skip to content

Commit

Permalink
Support Ninja wasm builds
Browse files Browse the repository at this point in the history
  • Loading branch information
RobDangerous committed Mar 13, 2024
1 parent cd79ef5 commit 7fcc7d9
Show file tree
Hide file tree
Showing 45 changed files with 222 additions and 590 deletions.
6 changes: 3 additions & 3 deletions kmake/src/Exporters/AndroidExporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ export class AndroidExporter extends Exporter {
compileCommands: CompilerCommandsExporter;
safeName: string;

constructor() {
super();
this.compileCommands = new CompilerCommandsExporter();
constructor(options: any) {
super(options);
this.compileCommands = new CompilerCommandsExporter(options);
}

async exportSolution(project: Project, from: string, to: string, platform: string, vrApi: any, options: any) {
Expand Down
4 changes: 2 additions & 2 deletions kmake/src/Exporters/CLionExporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import * as child_process from 'child_process';
import { Exporter } from 'kmake/Exporters/Exporter';

export class CLionExporter extends Exporter {
constructor() {
super();
constructor(options: any) {
super(options);
}

async exportSolution(project: Project, from: string, to: string, platform: string, vrApi: any, options: any): Promise<void> {
Expand Down
4 changes: 2 additions & 2 deletions kmake/src/Exporters/CompileCommandsExporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import * as child_process from 'child_process';
import { Exporter } from 'kmake/Exporters/Exporter';

export class CompilerCommandsExporter extends Exporter {
constructor() {
super();
constructor(options: any) {
super(options);
}

async exportSolution(project: Project, _from: string, to: string, platform: string, vrApi: any, options: any): Promise<void> {
Expand Down
6 changes: 3 additions & 3 deletions kmake/src/Exporters/EmscriptenExporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import { CompilerCommandsExporter } from 'kmake/Exporters/CompileCommandsExporte
export class EmscriptenExporter extends Exporter {
compileCommands: CompilerCommandsExporter;

constructor() {
super();
this.compileCommands = new CompilerCommandsExporter();
constructor(options: any) {
super(options);
this.compileCommands = new CompilerCommandsExporter(options);
}

exportMakefile(project: Project, from: string, to: string, platform: string, vrApi: any, options: any) {
Expand Down
2 changes: 1 addition & 1 deletion kmake/src/Exporters/Exporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export abstract class Exporter {
outFile: number = 0;
outString: string = null;

constructor() {
constructor(options: any) {

}

Expand Down
6 changes: 3 additions & 3 deletions kmake/src/Exporters/FreeBSDExporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import { CLionExporter } from 'kmake/Exporters/CLionExporter';
export class FreeBSDExporter extends Exporter {
clion: CLionExporter;

constructor() {
super();
this.clion = new CLionExporter();
constructor(options: any) {
super(options);
this.clion = new CLionExporter(options);
}

async exportSolution(project: Project, from: string, to: string, platform: string, vrApi: any, options: any) {
Expand Down
4 changes: 2 additions & 2 deletions kmake/src/Exporters/JsonExporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import * as fs from 'kmake/fsextra';
import * as path from 'path';

export class JsonExporter extends Exporter {
constructor() {
super();
constructor(options: any) {
super(options);
}

async exportSolution(project: Project, from: string, to: string, platform: string, vrApi: any, options: any) {
Expand Down
26 changes: 18 additions & 8 deletions kmake/src/Exporters/LinuxExporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,26 @@ export class LinuxExporter extends Exporter {
clion: CLionExporter;
compileCommands: CompilerCommandsExporter;

constructor() {
super();
let linkerParams = '-static-libgcc -static-libstdc++ -pthread';
constructor(options: any) {
super(options);

let linkerFlags = '-static-libgcc -static-libstdc++ -pthread';
if (Options.compiler === Compiler.MuslGcc || this.getOS().includes('Alpine')) {
linkerParams += ' -static';
linkerFlags += ' -static';
}
this.ninja = new NinjaExporter(this.getCCompiler(), this.getCPPCompiler(), linkerParams);
this.make = new MakeExporter(this.getCCompiler(), this.getCPPCompiler(), linkerParams);
this.clion = new CLionExporter();
this.compileCommands = new CompilerCommandsExporter();

let outputExtension = '';
if (options.lib) {
outputExtension = '.a';
}
else if (options.dynlib) {
outputExtension = '.so';
}

this.ninja = new NinjaExporter(options, this.getCCompiler(), this.getCPPCompiler(), '', '', linkerFlags, outputExtension);
this.make = new MakeExporter(options, this.getCCompiler(), this.getCPPCompiler(), '', '', linkerFlags, outputExtension);
this.clion = new CLionExporter(options);
this.compileCommands = new CompilerCommandsExporter(options);
}

async exportSolution(project: Project, from: string, to: string, platform: string, vrApi: any, options: any) {
Expand Down
37 changes: 16 additions & 21 deletions kmake/src/Exporters/MakeExporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,19 @@ import * as path from 'path';
export class MakeExporter extends Exporter {
cCompiler: string;
cppCompiler: string;
linkerParams: string;
cFlags: string;
cppFlags: string;
linkerFlags: string;
outputExtension: string;

constructor(cCompiler: string, cppCompiler: string, linkerParams: string) {
super();
constructor(options: any, cCompiler: string, cppCompiler: string, cFlags: string, cppFlags: string, linkerFlags: string, outputExtension: string) {
super(options);
this.cCompiler = cCompiler;
this.cppCompiler = cppCompiler;
this.linkerParams = linkerParams;
this.cFlags = cFlags;
this.cppFlags = cppFlags;
this.linkerFlags = linkerFlags;
this.outputExtension = outputExtension;
}

async exportSolution(project: Project, from: string, to: string, platform: string, vrApi: any, options: any) {
Expand Down Expand Up @@ -79,7 +85,7 @@ export class MakeExporter extends Exporter {
}
this.p('INC=' + incline);

let libsline = this.linkerParams;
let libsline = this.linkerFlags;
for (let lib of project.getLibs()) {
libsline += ' -l' + lib;
}
Expand All @@ -103,7 +109,7 @@ export class MakeExporter extends Exporter {
this.p('DEF=' + defline);
this.p();

let cline = '';
let cline = this.cFlags;
if (project.cStd !== '') {
cline = '-std=' + project.cStd + ' ';
}
Expand All @@ -115,7 +121,7 @@ export class MakeExporter extends Exporter {
}
this.p('CFLAGS=' + cline);

let cppline = '';
let cppline = this.cppFlags;
if (project.cppStd !== '') {
cppline = '-std=' + project.cppStd + ' ';
}
Expand All @@ -138,23 +144,12 @@ export class MakeExporter extends Exporter {
executableName = project.getExecutableName();
}

if (options.lib) {
this.p(executableName + '.a: ' + gchfilelist + ofilelist);
}
else if (options.dynlib) {
this.p(executableName + '.so: ' + gchfilelist + ofilelist);
}
else {
this.p(executableName + ': ' + gchfilelist + ofilelist);
}
this.p(executableName + this.outputExtension + ': ' + gchfilelist + ofilelist);

let cpp = '';

let output = '-o "' + executableName + '"';
if (options.lib) {
output = '-o "' + executableName + '.a"';
}
else if (options.dynlib) {
let output = '-o "' + executableName + this.outputExtension + '"';
if (options.dynlib) {
output = '-shared -o "' + executableName + '.so"';
}

Expand Down
28 changes: 14 additions & 14 deletions kmake/src/Exporters/NinjaExporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,19 @@ import * as path from 'path';
export class NinjaExporter extends Exporter {
cCompiler: string;
cppCompiler: string;
linkerParams: string;
cFlags: string;
cppFlags: string;
linkerFlags: string;
outputExtension: string;

constructor(cCompiler: string, cppCompiler: string, linkerParams: string) {
super();
constructor(options: any, cCompiler: string, cppCompiler: string, cFlags: string, cppFlags: string, linkerFlags: string, outputExtension: string) {
super(options);
this.cCompiler = cCompiler;
this.cppCompiler = cppCompiler;
this.linkerParams = linkerParams;
this.cFlags = cFlags;
this.cppFlags = cppFlags;
this.linkerFlags = linkerFlags;
this.outputExtension = outputExtension;
}

async exportSolution(project: Project, from: string, to: string, platform: string, vrApi: any, options: any) {
Expand Down Expand Up @@ -59,7 +65,7 @@ export class NinjaExporter extends Exporter {
incline += '-I' + inc + ' ';
}

let libsline = this.linkerParams;
let libsline = this.linkerFlags;
for (let lib of project.getLibs()) {
libsline += ' -l' + lib;
}
Expand Down Expand Up @@ -87,7 +93,7 @@ export class NinjaExporter extends Exporter {
}
else optimization = '-g';

let cline = this.cCompiler + ' ';
let cline = this.cCompiler + ' ' + this.cFlags + ' ';
if (project.cStd !== '') {
cline += '-std=' + project.cStd + ' ';
}
Expand All @@ -102,7 +108,7 @@ export class NinjaExporter extends Exporter {
cline += defline;
this.p('rule cc\n deps = gcc\n depfile = $out.d\n command = ' + cline + '-MD -MF $out.d -c $in -o $out\n');

let cppline = this.cppCompiler + ' ';
let cppline = this.cppCompiler + ' ' + this.cppFlags + ' ';
if (project.cppStd !== '') {
cppline += '-std=' + project.cppStd + ' ';
}
Expand Down Expand Up @@ -152,13 +158,7 @@ export class NinjaExporter extends Exporter {
executableName = project.getExecutableName();
}

let outputname = executableName;
if (options.lib) {
outputname = executableName + '.a';
}
else if (options.dynlib) {
outputname = executableName + '.so';
}
let outputname = executableName + this.outputExtension;

this.p('build ' + outputname + ': link ' + ofilelist);

Expand Down
6 changes: 3 additions & 3 deletions kmake/src/Exporters/VSCodeExporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import { CompilerCommandsExporter } from 'kmake/Exporters/CompileCommandsExporte
export class VSCodeExporter extends Exporter {
compileCommands: CompilerCommandsExporter;

constructor() {
super();
this.compileCommands = new CompilerCommandsExporter();
constructor(options: any) {
super(options);
this.compileCommands = new CompilerCommandsExporter(options);
}

configName(platform: string): string {
Expand Down
6 changes: 3 additions & 3 deletions kmake/src/Exporters/VisualStudioExporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ function getShaderLang() {
export class VisualStudioExporter extends Exporter {
clion: CLionExporter;

constructor() {
super();
this.clion = new CLionExporter();
constructor(options: any) {
super(options);
this.clion = new CLionExporter(options);
if (this.overrideVisualStudioVersion() !== null) {
Options.visualStudioVersion = this.overrideVisualStudioVersion();
}
Expand Down
Loading

0 comments on commit 7fcc7d9

Please sign in to comment.