-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pref: support file_notd_freestanding.v + file_d_freestanding.v, remov…
…e dependency to `os`, of $embed_file(), when compiling with -freestanding (#20712)
- Loading branch information
Showing
11 changed files
with
70 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module embed_file | ||
|
||
// do nothing, `os` is not available for that target | ||
fn reload_from_file_at_runtime(mut ed EmbedFileData) { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
module embed_file | ||
|
||
import os | ||
|
||
fn reload_from_file_at_runtime(mut ed EmbedFileData) { | ||
mut path := os.resource_abs_path(ed.path) | ||
if !os.is_file(path) { | ||
path = ed.apath | ||
if !os.is_file(path) { | ||
panic('EmbedFileData error: files "${ed.path}" and "${ed.apath}" do not exist') | ||
} | ||
} | ||
bytes := os.read_bytes(path) or { | ||
panic('EmbedFileData error: "${path}" could not be read: ${err}') | ||
} | ||
ed.uncompressed = bytes.data | ||
ed.free_uncompressed = true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
vlib/v/gen/c/testdata/freestanding_define/a_d_freestanding.c.v
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module freestanding_define | ||
|
||
const f = $embed_file(@FILE).len | ||
|
||
pub fn hi() { | ||
println('hi from a_d_freestanding.c.v') | ||
println('f.len: ${freestanding_define.f}') | ||
} |
8 changes: 8 additions & 0 deletions
8
vlib/v/gen/c/testdata/freestanding_define/a_notd_freestanding.c.v
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module freestanding_define | ||
|
||
const f = $embed_file(@FILE).len | ||
|
||
pub fn hi() { | ||
println('hi from a_notd_freestanding.c.v') | ||
println('f.len: ${freestanding_define.f}') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
hi from a_notd_freestanding.c.v | ||
f.len: 166 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// vtest vflags: -cc gcc | ||
import v.gen.c.testdata.freestanding_define | ||
|
||
freestanding_define.hi() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
hi from a_d_freestanding.c.v | ||
f.len: 163 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// vtest vflags: -cc gcc -freestanding | ||
import v.gen.c.testdata.freestanding_define | ||
|
||
freestanding_define.hi() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters