Skip to content

Commit 8b0e95a

Browse files
committed
remove clang options
1 parent a436463 commit 8b0e95a

File tree

1 file changed

+12
-50
lines changed

1 file changed

+12
-50
lines changed

c2wasm-api/src/chooks.ts

Lines changed: 12 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ const requestBodySchema = z.object({
4545
})),
4646
link_options: z.string().optional(),
4747
compress: z.boolean().optional(),
48-
strip: z.boolean().optional(),
49-
optimize: z.boolean().optional()
48+
strip: z.boolean().optional()
5049
});
5150

5251
type RequestBody = z.infer<typeof requestBodySchema>;
@@ -98,20 +97,10 @@ function shell_exec(cmd: string, cwd: string) {
9897
return result;
9998
}
10099

101-
const optimization_options = [
102-
/* default '-O0' not included */ '-O1', '-O2', '-O3', '-O4', '-Oz'
103-
];
100+
const optimization_level = '-03'
104101

105-
function get_optimization_options(options: string, optimize: boolean) {
106-
let optimization_level = '';
107-
for (let o of optimization_options) {
108-
if (options.includes(o)) {
109-
optimization_level += ' ' + o;
110-
}
111-
}
112-
113-
let safe_options = '';
114-
const _options = [
102+
function get_optimization_options() {
103+
const options = [
115104
'--shrink-level=100000000',
116105
'--coalesce-locals-learning',
117106
'--vacuum',
@@ -138,33 +127,13 @@ function get_optimization_options(options: string, optimize: boolean) {
138127
optimization_level
139128
]
140129

141-
if (optimize) {
142-
for (let o of _options) {
143-
safe_options += ' ' + o;
144-
}
145-
} else {
146-
safe_options = optimization_level
147-
}
148-
149-
return safe_options;
130+
return options.join(' ');
150131
}
151132

152-
function get_clang_options(options: string) {
133+
function get_clang_options() {
153134
const clang_flags = `--sysroot=${sysroot} -xc -I/app/clang/includes -fdiagnostics-print-source-range-info -Werror=implicit-function-declaration`;
154-
const miscellaneous_options = [
155-
'-ffast-math', '-fno-inline', '-std=c99', '-std=c89'
156-
];
157135

158-
let safe_options = '';
159-
for (let o of miscellaneous_options) {
160-
if (options.includes(o)) {
161-
safe_options += ' ' + o;
162-
} else if (o.includes('-std=') && options.toLowerCase().includes(o)) {
163-
safe_options += ' ' + o;
164-
}
165-
}
166-
167-
return clang_flags + safe_options;
136+
return clang_flags;
168137
}
169138

170139
function get_lld_options(options: string) {
@@ -204,17 +173,11 @@ function validate_filename(name: string) {
204173
return parts;
205174
}
206175

207-
function link_c_files(source_files: string[], compile_options: string, link_options: string, cwd: string, output: string, result_obj: Task) {
176+
function link_c_files(source_files: string[], link_options: string, cwd: string, output: string, result_obj: Task) {
208177
const files = source_files.join(' ');
209178
const clang = llvmDir + '/bin/clang';
210-
let optimization_level = '';
211179

212-
for (let o of optimization_options) {
213-
if (compile_options.includes(o)) {
214-
optimization_level == o;
215-
}
216-
}
217-
const cmd = clang + ' ' + optimization_level + ' ' + get_clang_options(compile_options) + ' ' + get_lld_options(link_options) + ' ' + files + ' -o ' + output;
180+
const cmd = clang + ' ' + optimization_level + ' ' + get_clang_options() + ' ' + get_lld_options(link_options) + ' ' + files + ' -o ' + output;
218181

219182
const out = shell_exec(cmd, cwd);
220183
result_obj.console = sanitize_shell_output(out);
@@ -295,7 +258,6 @@ export function build_project(project: RequestBody, base: string) {
295258
const output = project.output;
296259
const compress = project.compress;
297260
const strip = project.strip;
298-
const optimize = project.optimize;
299261
let build_result: ResponseData = {
300262
success: false,
301263
message: '',
@@ -359,11 +321,11 @@ export function build_project(project: RequestBody, base: string) {
359321
name: 'building wasm'
360322
};
361323
build_result.tasks.push(link_result_obj);
362-
if (!link_c_files(sources, options || '', link_options || '', dir, result, link_result_obj)) {
324+
if (!link_c_files(sources, link_options || '', dir, result, link_result_obj)) {
363325
return complete(false, 'Build error');
364326
}
365327

366-
const opt_options = get_optimization_options(options || '', optimize);
328+
const opt_options = get_optimization_options();
367329
if (opt_options) {
368330
const opt_obj = {
369331
name: 'optimizing wasm'
@@ -384,7 +346,7 @@ export function build_project(project: RequestBody, base: string) {
384346
}
385347
}
386348

387-
if (optimize && opt_options) {
349+
if (opt_options) {
388350
const opt_obj = {
389351
name: 'optimizing wasm'
390352
};

0 commit comments

Comments
 (0)