Skip to content

Commit

Permalink
v.pref: allow for -os wasm32_emscripten and later filtering `_d_was…
Browse files Browse the repository at this point in the history
…m32_emscripten.c.v` and `_notd_wasm32_emscripten.c.v` files.
  • Loading branch information
spytheman committed Feb 23, 2025
1 parent 3c88926 commit 5049fc7
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 21 deletions.
2 changes: 2 additions & 0 deletions vlib/v/pref/pref.v
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,8 @@ pub fn parse_args_and_show_errors(known_external_commands []string, args []strin
}
res.os = target_os_kind
res.build_options << '${arg} ${target_os}'
res.compile_defines << target_os
res.compile_defines_all << target_os
}
'-printfn' {
res.printfn_list << cmdline.option(args[i..], '-printfn', '').split(',')
Expand Down
45 changes: 24 additions & 21 deletions vlib/v/pref/should_compile.v
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,9 @@ pub fn (prefs &Preferences) should_compile_filtered_files(dir string, files_ []s
|| file.all_before_last('.v').all_before_last('.').ends_with('_test') {
continue
}
if prefs.backend in [.c, .interpret] && !prefs.should_compile_c(file) {
continue
}
if prefs.backend.is_js() && !prefs.should_compile_js(file) {
continue
}
if prefs.backend == .native && !prefs.should_compile_native(file) {
continue
}
if !prefs.backend.is_js() && !prefs.should_compile_asm(file) {
continue
}
if file.starts_with('.#') {
continue
}
if !prefs.prealloc && !prefs.output_cross_c && file.ends_with('prealloc.c.v') {
continue
}
if prefs.nofloat && file.ends_with('float.c.v') {
continue
}
mut is_d_notd_file := false
if file.contains('_d_') {
is_d_notd_file = true
if prefs.compile_defines_all.len == 0 {
continue
}
Expand All @@ -58,6 +39,7 @@ pub fn (prefs &Preferences) should_compile_filtered_files(dir string, files_ []s
}
}
if file.contains('_notd_') {
is_d_notd_file = true
mut allowed := true
for cdefine in prefs.compile_defines {
file_postfixes := ['_notd_${cdefine}.v', '_notd_${cdefine}.c.v']
Expand All @@ -75,6 +57,27 @@ pub fn (prefs &Preferences) should_compile_filtered_files(dir string, files_ []s
continue
}
}
if prefs.backend in [.c, .interpret] && !is_d_notd_file && !prefs.should_compile_c(file) {
continue
}
if prefs.backend.is_js() && !prefs.should_compile_js(file) {
continue
}
if prefs.backend == .native && !prefs.should_compile_native(file) {
continue
}
if !prefs.backend.is_js() && !prefs.should_compile_asm(file) {
continue
}
if file.starts_with('.#') {
continue
}
if !prefs.prealloc && !prefs.output_cross_c && file.ends_with('prealloc.c.v') {
continue
}
if prefs.nofloat && file.ends_with('float.c.v') {
continue
}
if prefs.exclude.len > 0 {
full_file_path := os.join_path(dir, file)
for epattern in prefs.exclude {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module main

fn abc() {
println('This is abc_d_wasm32_emscripten.c.v')
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module main

fn abc() {
println('This is abc_notd_wasm32_emscripten.c.v')
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import os

const vexe = os.quoted_path(@VEXE)
const project_folder = os.dir(@FILE)
const output_path = os.join_path(os.vtmp_dir(), 'check_wasm_works')

fn testsuite_begin() {
os.mkdir_all(output_path) or {}
os.chdir(output_path)!
dump(os.getwd())
}

fn testsuite_end() {
os.system('ls -la .')
os.chdir(os.home_dir()) or {}
os.rmdir_all(output_path) or {}
}

fn test_normal() {
defer { println('done ${@FN}') }
dump(vexe)
res := os.system('${os.quoted_path(vexe)} -o normal.exe ${os.quoted_path(project_folder)}')
assert res == 0
dump(res)
assert os.exists('normal.exe')
content := os.read_file('normal.exe')!
assert content.contains('This is abc_notd_wasm32_emscripten.c.v')
}

fn test_emcc() {
defer { println('done ${@FN}') }
emcc := os.find_abs_path_of_executable('emcc') or {
println('skipping ${@FN} since `emcc` is not found')
return
}
dump(emcc)
res := os.system('${os.quoted_path(vexe)} -os wasm32_emscripten -o wasm_check.html ${os.quoted_path(project_folder)}')
assert res == 0
dump(res)
assert os.exists('wasm_check.html')
assert os.exists('wasm_check.js')
assert os.exists('wasm_check.wasm')
content := os.read_file('wasm_check.wasm')!
assert content.contains('This is abc_d_wasm32_emscripten.c.v')
}
6 changes: 6 additions & 0 deletions vlib/v/tests/project_compiling_to_wasm/main.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module main

fn main() {
abc()
println('hi from main.v')
}
Empty file.

0 comments on commit 5049fc7

Please sign in to comment.