Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
No results found
Show changes
Commits on Source (9)
......@@ -2,9 +2,15 @@
> Node.js library for GCC and G++ compilers
[![](https://img.shields.io/npm/v/gnucc.svg?style=flat-square)](https://www.npmjs.com/package/gnucc)
[![](https://img.shields.io/npm/dt/gnucc.svg?style=flat-square)](https://www.npmjs.com/package/gnucc)
[![](https://img.shields.io/david/insertish/gnucc.svg?style=flat-square)](https://www.npmjs.com/package/gnucc)
[![](https://img.shields.io/bundlephobia/minzip/gnucc.svg?style=flat-square)](https://www.npmjs.com/package/gnucc)
- Simplified options and usage
- Types and intellisense support
- Supports compilation of C and C++ files through `gcc` and `g++`
- Also can be easily used with emscripten.
## Quick Start
......@@ -33,6 +39,10 @@ await gnucc({
includes: [
'src/headers'
],
binaries: {
"gcc": 'gcc',
"g++": 'g++'
},
optimisation: OPTIMISATION.HIGH,
warning: [WARN.ALL]
});
......
{
"name": "gnucc",
"version": "1.0.4",
"version": "1.1.5",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
......
{
"name": "gnucc",
"version": "1.0.4",
"version": "1.1.5",
"description": "Wrapper for GCC and G++",
"main": "dist/index.js",
"types": "dist/index.d.ts",
......@@ -36,10 +36,12 @@
"url": "https://gitlab.insrt.uk/insert/gnucc.git"
},
"keywords": [
"gnu",
"gcc",
"g++",
"c++",
"c",
"compiler"
"compiler",
"emscripten"
]
}
......@@ -54,4 +54,18 @@ export function ProcessGppOpt(opts: GPPOptions): string[] {
opts.std && args.push(`--std=${opts.std}`);
return args;
}
export function ProcessEnv(opts: ProjectOptions): NodeJS.ProcessEnv {
let env = process.env;
if (opts.env) {
Object.assign(env, opts.env);
}
if (opts.path) {
opts.path.forEach(x => env['PATH'] = x + ';' + env['PATH']);
}
return env;
}
\ No newline at end of file
......@@ -204,6 +204,12 @@ export interface CompilerOptions extends PreprocessorOptions {
logCompile?: boolean,
/** Any additional arguments */
args?: string[],
/** Binaries to use */
binaries?: {
'gcc'?: string,
'g++'?: string
}
};
export interface LinkerOptions extends CompilerOptions {
......@@ -236,7 +242,11 @@ export interface ProjectOptions extends LinkerOptions {
/** Link libraries, -l */
link?: string[],
/** Output logs when compiling */
log?: boolean
log?: boolean,
/** Environment variables to attach */
env?: NodeJS.ProcessEnv,
/** PATH paths to prepend */
path?: string[]
};
export interface GCCOptions extends ProjectOptions {
......
......@@ -8,7 +8,7 @@ export interface Result {
exitCode: Number
};
export default function Run(args: string[], log?: boolean): Promise<Result> {
export default function Run(args: string[], log?: boolean, env?: NodeJS.ProcessEnv): Promise<Result> {
let command = args.join(' ');
log && LogOutput(command);
const proc = spawn(args.shift() || 'echo', args);
......
import Run, { Result } from '../Runner';
import { GPPOptions } from '../Options';
import { ProcessGppOpt } from '../Config';
import { ProcessGppOpt, ProcessEnv } from '../Config';
/**
* Compiles a source file with G++
......@@ -17,15 +17,19 @@ export default async function gpp(opt: GPPOptions): Promise<Result>;
export default async function gpp(optOrInput: GPPOptions | string, output?: string, log: boolean = true) {
let binary = 'g++';
let args: string[] = [binary];
let args: string[] = [];
let env;
if (typeof optOrInput === 'string') {
args.push(optOrInput);
output && args.push('-o', output);
} else {
env = ProcessEnv(optOrInput);
if (optOrInput.binaries && optOrInput.binaries["g++"]) binary = optOrInput.binaries["g++"];
args.push(...ProcessGppOpt(optOrInput));
log = optOrInput.log || false;
}
return await Run(args, log);
args.unshift(binary);
return await Run(args, log, env);
};
\ No newline at end of file
import Run, { Result } from '../Runner';
import { GCCOptions } from '../Options';
import { ProcessGccOpt } from '../Config';
import { ProcessGccOpt, ProcessEnv } from '../Config';
/**
* Compiles a source file with GCC
......@@ -17,15 +17,19 @@ export default async function gcc(opt: GCCOptions): Promise<Result>;
export default async function gcc(optOrInput: GCCOptions | string, output?: string, log: boolean = true) {
let binary = 'gcc';
let args: string[] = [binary];
let args: string[] = [];
let env;
if (typeof optOrInput === 'string') {
args.push(optOrInput);
output && args.push('-o', output);
} else {
env = ProcessEnv(optOrInput);
if (optOrInput.binaries && optOrInput.binaries.gcc) binary = optOrInput.binaries.gcc;
args.push(...ProcessGccOpt(optOrInput));
log = optOrInput.log || false;
}
return await Run(args, log);
args.unshift(binary);
return await Run(args, log, env);
};
\ No newline at end of file
......@@ -49,7 +49,7 @@ export async function gnucc(optOrInput: GCCOptions | GPPOptions | string, output
inp.forEach(x => globbed.push(...globSync(x)));
inp = globbed;
let objects = inp.map(x => resolve(<string> optOrInput.objOut, x.replace(/\\|\//g, '_') + '.o'));
let objects = inp.map(x => resolve(<string> optOrInput.objOut, x.replace(/\\|\/|\:/g, '_') + '.o'));
let compiler: Function = gnucc;
inp.forEach(x => {
......