Skip to content

Commit

Permalink
fix -usecache
Browse files Browse the repository at this point in the history
  • Loading branch information
spytheman committed Feb 23, 2025
1 parent 5049fc7 commit 15cbd27
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 5 deletions.
8 changes: 6 additions & 2 deletions vlib/v/pref/default.v
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ fn (mut p Preferences) setup_os_and_arch_when_not_explicitly_set() {
host_os := if p.backend == .wasm { OS.wasi } else { get_host_os() }
if p.os == ._auto {
p.os = host_os
p.build_options << '-os ${host_os}'
p.build_options << '-os ${host_os.lower()}'
}

if !p.output_cross_c {
Expand Down Expand Up @@ -189,13 +189,17 @@ pub fn (mut p Preferences) fill_with_defaults() {
}
}
}

final_os := p.os.lower()
p.parse_define(final_os)

// Prepare the cache manager. All options that can affect the generated cached .c files
// should go into res.cache_manager.vopts, which is used as a salt for the cache hash.
vhash := @VHASH
p.cache_manager = vcache.new_cache_manager([
vhash,
// ensure that different v versions use separate build artefacts
'${p.backend} | ${p.os} | ${p.ccompiler} | ${p.is_prod} | ${p.sanitize}',
'${p.backend} | ${final_os} | ${p.ccompiler} | ${p.is_prod} | ${p.sanitize}',
p.cflags.trim_space(),
p.third_party_option.trim_space(),
p.compile_defines_all.str(),
Expand Down
35 changes: 35 additions & 0 deletions vlib/v/pref/os.v
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,41 @@ pub fn os_from_string(os_str string) !OS {
}
}

// lower returns the name that could be used with `-os osname`, for each OS enum value
// NOTE: it is important to not change the names here, they should match 1:1, since they
// are used as part of the cache keys, when -usecache is passed.
pub fn (o OS) lower() string {
return match o {
._auto { '' }
.linux { 'linux' }
.windows { 'windows' }
.macos { 'macos' }
.ios { 'ios' }
.freebsd { 'freebsd' }
.openbsd { 'openbsd' }
.netbsd { 'netbsd' }
.dragonfly { 'dragonfly' }
.js_node { 'js' }
.js_freestanding { 'js_freestanding' }
.js_browser { 'js_browser' }
.solaris { 'solaris' }
.serenity { 'serenity' }
.qnx { 'qnx' }
.plan9 { 'plan9' }
.vinix { 'vinix' }
.android { 'android' }
.termux { 'termux' }
.haiku { 'haiku' }
.raw { 'raw' }
.wasm32 { 'wasm32' }
.wasm32_wasi { 'wasm32_wasi' }
.wasm32_emscripten { 'wasm32_emscripten' }
.browser { 'browser' }
.wasi { 'wasi' }
.all { 'all' }
}
}

pub fn (o OS) str() string {
// TODO: check more thoroughly, why this method needs to exist at all,
// and why should it override the default autogenerated .str() method,
Expand Down
4 changes: 1 addition & 3 deletions vlib/v/pref/pref.v
Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,7 @@ pub fn parse_args_and_show_errors(known_external_commands []string, args []strin
res.build_options << '${arg}'
}
'-os' {
target_os := cmdline.option(args[i..], '-os', '')
target_os := cmdline.option(args[i..], '-os', '').to_lower_ascii()
i++
target_os_kind := os_from_string(target_os) or {
if target_os == 'cross' {
Expand All @@ -850,8 +850,6 @@ 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

0 comments on commit 15cbd27

Please sign in to comment.