mirror of
https://github.com/vlang/v.git
synced 2025-09-13 06:22:26 +03:00
v: add support for @OS
, @CCOMPILER
@BACKEND
and @PLATFORM
(#25174)
Some checks failed
wasm backend CI / wasm-backend (windows-2022) (push) Has been cancelled
Graphics CI / gg-regressions (push) Has been cancelled
vlib modules CI / build-module-docs (push) Has been cancelled
native backend CI / native-backend-ubuntu (push) Has been cancelled
native backend CI / native-backend-windows (push) Has been cancelled
Shy and PV CI / v-compiles-puzzle-vibes (push) Has been cancelled
Sanitized CI / sanitize-undefined-clang (push) Has been cancelled
Sanitized CI / sanitize-undefined-gcc (push) Has been cancelled
Sanitized CI / tests-sanitize-address-clang (push) Has been cancelled
Sanitized CI / sanitize-address-msvc (push) Has been cancelled
Sanitized CI / sanitize-address-gcc (push) Has been cancelled
Sanitized CI / sanitize-memory-clang (push) Has been cancelled
sdl CI / v-compiles-sdl-examples (push) Has been cancelled
Time CI / time-linux (push) Has been cancelled
Time CI / time-macos (push) Has been cancelled
Time CI / time-windows (push) Has been cancelled
toml CI / toml-module-pass-external-test-suites (push) Has been cancelled
Tools CI / tools-linux (clang) (push) Has been cancelled
Tools CI / tools-linux (gcc) (push) Has been cancelled
Tools CI / tools-linux (tcc) (push) Has been cancelled
Tools CI / tools-macos (clang) (push) Has been cancelled
Tools CI / tools-windows (gcc) (push) Has been cancelled
Tools CI / tools-windows (msvc) (push) Has been cancelled
Tools CI / tools-windows (tcc) (push) Has been cancelled
Tools CI / tools-docker-ubuntu-musl (push) Has been cancelled
vab CI / vab-compiles-v-examples (push) Has been cancelled
vab CI / v-compiles-os-android (push) Has been cancelled
wasm backend CI / wasm-backend (ubuntu-22.04) (push) Has been cancelled
Some checks failed
wasm backend CI / wasm-backend (windows-2022) (push) Has been cancelled
Graphics CI / gg-regressions (push) Has been cancelled
vlib modules CI / build-module-docs (push) Has been cancelled
native backend CI / native-backend-ubuntu (push) Has been cancelled
native backend CI / native-backend-windows (push) Has been cancelled
Shy and PV CI / v-compiles-puzzle-vibes (push) Has been cancelled
Sanitized CI / sanitize-undefined-clang (push) Has been cancelled
Sanitized CI / sanitize-undefined-gcc (push) Has been cancelled
Sanitized CI / tests-sanitize-address-clang (push) Has been cancelled
Sanitized CI / sanitize-address-msvc (push) Has been cancelled
Sanitized CI / sanitize-address-gcc (push) Has been cancelled
Sanitized CI / sanitize-memory-clang (push) Has been cancelled
sdl CI / v-compiles-sdl-examples (push) Has been cancelled
Time CI / time-linux (push) Has been cancelled
Time CI / time-macos (push) Has been cancelled
Time CI / time-windows (push) Has been cancelled
toml CI / toml-module-pass-external-test-suites (push) Has been cancelled
Tools CI / tools-linux (clang) (push) Has been cancelled
Tools CI / tools-linux (gcc) (push) Has been cancelled
Tools CI / tools-linux (tcc) (push) Has been cancelled
Tools CI / tools-macos (clang) (push) Has been cancelled
Tools CI / tools-windows (gcc) (push) Has been cancelled
Tools CI / tools-windows (msvc) (push) Has been cancelled
Tools CI / tools-windows (tcc) (push) Has been cancelled
Tools CI / tools-docker-ubuntu-musl (push) Has been cancelled
vab CI / vab-compiles-v-examples (push) Has been cancelled
vab CI / v-compiles-os-android (push) Has been cancelled
wasm backend CI / wasm-backend (ubuntu-22.04) (push) Has been cancelled
This commit is contained in:
parent
efe611ed99
commit
9e1273ae71
6 changed files with 52 additions and 2 deletions
|
@ -6138,6 +6138,10 @@ that are substituted at compile time:
|
|||
- `@BUILD_DATE` => replaced with the build date, for example '2024-09-13' .
|
||||
- `@BUILD_TIME` => replaced with the build time, for example '12:32:07' .
|
||||
- `@BUILD_TIMESTAMP` => replaced with the build timestamp, for example '1726219885' .
|
||||
- `@OS` => replaced with the OS type, for example 'linux' .
|
||||
- `@CCOMPILER` => replaced with the C compiler type, for example 'gcc' .
|
||||
- `@BACKEND` => replaced with current language backend, for example 'c' or 'golang' .
|
||||
- `@PLATFORM` => replaced with the platform type, for example 'amd64' .
|
||||
Note: `@BUILD_DATE`, `@BUILD_TIME`, `@BUILD_TIMESTAMP` represent times in the UTC timezone.
|
||||
By default, they are based on the current time of the compilation/build. They can be overridden
|
||||
by setting the environment variable `SOURCE_DATE_EPOCH`. That is also useful while making
|
||||
|
|
|
@ -4030,6 +4030,18 @@ fn (mut c Checker) at_expr(mut node ast.AtExpr) ast.Type {
|
|||
.build_timestamp {
|
||||
node.val = util.stable_build_time.unix().str()
|
||||
}
|
||||
.os {
|
||||
node.val = pref.get_host_os().lower()
|
||||
}
|
||||
.ccompiler {
|
||||
node.val = c.pref.ccompiler_type.str()
|
||||
}
|
||||
.backend {
|
||||
node.val = c.pref.backend.str()
|
||||
}
|
||||
.platform {
|
||||
node.val = c.pref.arch.str()
|
||||
}
|
||||
.unknown {
|
||||
c.error('unknown @ identifier: ${node.name}. Available identifiers: ${token.valid_at_tokens}',
|
||||
node.pos)
|
||||
|
|
|
@ -511,6 +511,10 @@ fn (mut p Parser) at() ast.AtExpr {
|
|||
'@BUILD_DATE' { token.AtKind.build_date }
|
||||
'@BUILD_TIME' { token.AtKind.build_time }
|
||||
'@BUILD_TIMESTAMP' { token.AtKind.build_timestamp }
|
||||
'@OS' { token.AtKind.os }
|
||||
'@CCOMPILER' { token.AtKind.ccompiler }
|
||||
'@BACKEND' { token.AtKind.backend }
|
||||
'@PLATFORM' { token.AtKind.platform }
|
||||
else { token.AtKind.unknown }
|
||||
}
|
||||
expr := ast.AtExpr{
|
||||
|
|
|
@ -5,4 +5,5 @@ vlib/v/scanner/tests/unknown_comptime_var_err.vv:2:9: error: @ must be used befo
|
|||
3 | }
|
||||
Details: available compile time variables: @VROOT, @VMODROOT, @VEXEROOT, @FN, @METHOD, @MOD,
|
||||
@STRUCT, @VEXE, @FILE, @DIR, @LINE, @COLUMN, @VHASH, @VCURRENTHASH, @VMOD_FILE, @VMODHASH,
|
||||
@FILE_LINE, @LOCATION, @BUILD_DATE, @BUILD_TIME, @BUILD_TIMESTAMP
|
||||
@FILE_LINE, @LOCATION, @BUILD_DATE, @BUILD_TIME, @BUILD_TIMESTAMP, @OS, @CCOMPILER,
|
||||
@BACKEND, @PLATFORM
|
||||
|
|
|
@ -198,3 +198,27 @@ fn test_at_build_date_time_timestamp() {
|
|||
now_utc := dump(time.utc().unix())
|
||||
assert now_utc >= bts.i64()
|
||||
}
|
||||
|
||||
fn test_at_os() {
|
||||
println('Current OS is ${@OS}')
|
||||
assert @OS in ['termux', 'android', 'wasm32_emscripten', 'linux', 'ios', 'macos', 'windows',
|
||||
'freebsd', 'openbsd', 'netbsd', 'dragonfly', 'serenity', 'plan9', 'vinix', 'solaris', 'haiku',
|
||||
'js_node', 'js_freestanding', 'js_browser']
|
||||
}
|
||||
|
||||
fn test_at_ccompiler() {
|
||||
println('Current C Compiler is ${@CCOMPILER}')
|
||||
assert @CCOMPILER in ['gcc', 'tinyc', 'clang', 'emcc', 'mingw', 'msvc', 'cplusplus']
|
||||
}
|
||||
|
||||
fn test_at_backend() {
|
||||
println('Current language backend is ${@BACKEND}')
|
||||
assert @BACKEND in ['c', 'golang', 'interpret', 'js_node', 'js_browser', 'js_freestanding',
|
||||
'native', 'wasm']
|
||||
}
|
||||
|
||||
fn test_at_platform() {
|
||||
println('Current Platform is ${@PLATFORM}')
|
||||
assert @PLATFORM in ['amd64', 'arm64', 'arm32', 'rv64', 'rv32', 'i386', 's390x', 'ppc64le',
|
||||
'loongarch64', 'js_node', 'js_browser', 'js_freestanding', 'wasm32']
|
||||
}
|
||||
|
|
|
@ -189,6 +189,10 @@ pub enum AtKind {
|
|||
build_date
|
||||
build_time
|
||||
build_timestamp
|
||||
os
|
||||
ccompiler
|
||||
backend
|
||||
platform
|
||||
}
|
||||
|
||||
pub const assign_tokens = [Kind.assign, .decl_assign, .plus_assign, .minus_assign, .mult_assign,
|
||||
|
@ -197,7 +201,8 @@ pub const assign_tokens = [Kind.assign, .decl_assign, .plus_assign, .minus_assig
|
|||
|
||||
pub const valid_at_tokens = ['@VROOT', '@VMODROOT', '@VEXEROOT', '@FN', '@METHOD', '@MOD', '@STRUCT',
|
||||
'@VEXE', '@FILE', '@DIR', '@LINE', '@COLUMN', '@VHASH', '@VCURRENTHASH', '@VMOD_FILE',
|
||||
'@VMODHASH', '@FILE_LINE', '@LOCATION', '@BUILD_DATE', '@BUILD_TIME', '@BUILD_TIMESTAMP']
|
||||
'@VMODHASH', '@FILE_LINE', '@LOCATION', '@BUILD_DATE', '@BUILD_TIME', '@BUILD_TIMESTAMP', '@OS',
|
||||
'@CCOMPILER', '@BACKEND', '@PLATFORM']
|
||||
|
||||
pub const token_str = build_token_str()
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue