Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
164 changes: 145 additions & 19 deletions .github/workflows/demo-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,44 @@ jobs:
GLFW_INCLUDE: /usr/include
GLFW_LIB: /usr/lib/x86_64-linux-gnu
steps:
- uses: actions/checkout@v7
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
path: source/modules/antono2/imgui
submodules: recursive
- uses: actions/checkout@v7
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
repository: antono2/vulkan
ref: v2.0.0
path: source/modules/antono2/vulkan
- uses: actions/checkout@v7
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
repository: antono2/glfw
ref: e9a367938577919b4a5140a477c1250112978d8e
path: source/modules/antono2/glfw
- uses: actions/checkout@v7
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
repository: antono2/v_imgui_examples
ref: c2b5083d42f052cfe73952542e86e4163c64ce79
ref: 1e444971dd4f70a6edf281ce648e136c01d08ab6
path: source/demo
- uses: actions/checkout@v7
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
repository: vlang/v
ref: 1f128c94619fb6e4863c5f81883e1b860405c8fa
path: toolchain/v
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
repository: vlang/vc
ref: 4a1ba4d772f19c2752c9850d3b5421c71f54a4d6
path: toolchain/v/vc
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
repository: vlang/tccbin
ref: d6e7ac1b1bcc98aed734a6ecbfa8509f24606c74
path: toolchain/v/thirdparty/tcc
- name: Build official V compiler
working-directory: toolchain/v
run: |
make
make local=1
echo "$GITHUB_WORKSPACE/toolchain/v" >> "$GITHUB_PATH"
- name: Install native dependencies
run: sudo apt-get update && sudo apt-get install -y build-essential cmake libglfw3-dev libvulkan-dev libvulkan-volk-dev patchelf pkg-config xvfb zip
Expand Down Expand Up @@ -106,7 +118,7 @@ jobs:
unzip -t "$RUNNER_TEMP/$archive" >/dev/null
sha256sum "$RUNNER_TEMP/$archive"
- name: Upload Ubuntu demo package
uses: actions/upload-artifact@v7
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
with:
path: ${{ runner.temp }}/v-imgui-demo-${{ steps.variant.outputs.name }}-ubuntu24-amd64.zip
archive: false
Expand All @@ -117,39 +129,44 @@ jobs:
runs-on: windows-2022
timeout-minutes: 45
steps:
- uses: actions/checkout@v7
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
path: source/modules/antono2/imgui
submodules: recursive
- uses: actions/checkout@v7
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
repository: antono2/vulkan
ref: d9ad9fc5151aa19f58cd2fed1b6bcda9b210f098
ref: v2.0.0
path: source/modules/antono2/vulkan
- uses: actions/checkout@v7
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
repository: antono2/glfw
ref: 3d7c1ddacb7215a7bbeb5fef0d7a68c90ba392ed
path: source/modules/antono2/glfw
- uses: actions/checkout@v7
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
repository: antono2/v_imgui_examples
ref: c2b5083d42f052cfe73952542e86e4163c64ce79
ref: 1e444971dd4f70a6edf281ce648e136c01d08ab6
path: source/demo
- uses: actions/checkout@v7
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
repository: vlang/v
ref: 1f128c94619fb6e4863c5f81883e1b860405c8fa
path: toolchain/v
- uses: actions/checkout@v7
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
repository: vlang/vc
ref: 4a1ba4d772f19c2752c9850d3b5421c71f54a4d6
path: toolchain/v/vc
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
repository: zeux/volk
ref: 58689c063427f5bad4f133625049b1a3c5dd8287
path: source/third_party/volk
- name: Build official V compiler
shell: cmd
working-directory: toolchain/v
run: makev.bat
run: makev.bat -msvc --local
- name: Add V compiler to PATH
shell: pwsh
run: |
Expand Down Expand Up @@ -211,22 +228,131 @@ jobs:
}
Get-FileHash -Algorithm SHA256 $Archive
- name: Upload Windows demo package
uses: actions/upload-artifact@v7
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
with:
path: ${{ runner.temp }}/v-imgui-demo-${{ steps.variant.outputs.name }}-windows-x64.zip
archive: false
retention-days: 7
if-no-files-found: error

strict-v3-frontend:
name: Required pinned V3 frontend
runs-on: ubuntu-24.04
timeout-minutes: 45
env:
VMODULES: ${{ github.workspace }}/source/modules
VULKAN_SDK: /usr
GLFW_INCLUDE: /usr/include
GLFW_LIB: /usr/lib/x86_64-linux-gnu
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
path: source/modules/antono2/imgui
submodules: recursive
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
repository: antono2/vulkan
ref: 42e6c381e37952ef07f4cd560c9996fd2435cd41
path: source/modules/antono2/vulkan
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
repository: antono2/glfw
ref: e9a367938577919b4a5140a477c1250112978d8e
path: source/modules/antono2/glfw
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
repository: antono2/v_imgui_examples
ref: 1e444971dd4f70a6edf281ce648e136c01d08ab6
path: source/demo
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
repository: vlang/v
ref: f59b886d2564e37d8626d715236fdfa928e13dda
path: toolchain/v
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
repository: vlang/vc
ref: 4598bc7e4894c154b27391e4442005fff2fbbd68
path: toolchain/v/vc
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
repository: vlang/tccbin
ref: d6e7ac1b1bcc98aed734a6ecbfa8509f24606c74
path: toolchain/v/thirdparty/tcc
- name: Build pinned V3 compiler
run: |
make -C toolchain/v local=1
echo "$GITHUB_WORKSPACE/toolchain/v" >> "$GITHUB_PATH"
- name: Check generated bindings and demo
run: |
v -new-compiler -check-syntax source/modules/antono2/imgui/imgui.v
v -new-compiler -check-syntax source/modules/antono2/imgui/implot/implot.v
v -new-compiler -check -path "$VMODULES/antono2|@vlib|@vmodules" source/demo

linux-v-master:
name: Advisory current V master and dependency masters
continue-on-error: true
runs-on: ubuntu-24.04
timeout-minutes: 45
env:
VMODULES: ${{ github.workspace }}/source/modules
VULKAN_SDK: /usr
GLFW_INCLUDE: /usr/include
GLFW_LIB: /usr/lib/x86_64-linux-gnu
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
path: source/modules/antono2/imgui
submodules: recursive
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
repository: antono2/vulkan
ref: master
path: source/modules/antono2/vulkan
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
repository: antono2/glfw
ref: master
path: source/modules/antono2/glfw
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
repository: antono2/v_imgui_examples
ref: 1e444971dd4f70a6edf281ce648e136c01d08ab6
path: source/demo
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
repository: vlang/v
ref: master
path: toolchain/v
- name: Build current V master
run: |
make -C toolchain/v
echo "$GITHUB_WORKSPACE/toolchain/v" >> "$GITHUB_PATH"
- name: Install native dependencies
run: sudo apt-get update && sudo apt-get install -y build-essential cmake libglfw3-dev libvulkan-dev libvulkan-volk-dev pkg-config
- name: Check generated bindings with V3
working-directory: source/modules/antono2/imgui
run: |
v -check-syntax imgui.v
v -check-syntax implot/implot.v
- name: Build and compile demo with V3
run: |
cd source/modules/antono2/imgui
v run build_vimgui.vsh --linkage shared --glfw system
cd "$GITHUB_WORKSPACE"
v -no-memory-limit -path "$VMODULES/antono2|@vlib|@vmodules" -cc gcc -o "$RUNNER_TEMP/v_imgui_demo" source/demo

required-checks:
if: always()
needs: [ubuntu24, windows-native]
needs: [ubuntu24, windows-native, strict-v3-frontend]
runs-on: ubuntu-24.04
steps:
- name: Verify required jobs
env:
UBUNTU_RESULT: ${{ needs.ubuntu24.result }}
WINDOWS_RESULT: ${{ needs.windows-native.result }}
V3_RESULT: ${{ needs.strict-v3-frontend.result }}
run: |
test "$UBUNTU_RESULT" = success
test "$WINDOWS_RESULT" = success
test "$V3_RESULT" = success
2 changes: 1 addition & 1 deletion QUICKSTART.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Install `gcc-c++`, `cmake`, `git`, `glfw-devel`, `vulkan-loader-devel`,
Install the two V dependencies and then use the same build and demo commands:

```sh
v install antono2.vulkan
v install antono2.vulkan@v2.0.0
v install antono2.glfw
v run build_vimgui.vsh --linkage shared --glfw system
./scripts/run_demo.sh
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ The configuration functions return `false` on the standard branch. Dockspace
and secondary-viewport rendering helpers become safe no-ops there.

## Dependencies
`v install antono2.vulkan`<br>
`v install antono2.vulkan@v2.0.0`<br>
`v install antono2.glfw`

## Install
Expand Down
86 changes: 86 additions & 0 deletions cleanup_imgui_implot.vsh
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ mut:
fn usage() {
eprintln('Usage: v run cleanup_imgui_implot.vsh input.v output.v imgui|implot')
eprintln(' v run cleanup_imgui_implot.vsh --self-test')
eprintln(' v run cleanup_imgui_implot.vsh --v3-fixed-arrays binding.v')
}

fn config_for(kind string) !Config {
Expand Down Expand Up @@ -1576,6 +1577,78 @@ fn insert_after_version(input string, addition string) string {
return input[..after] + addition + input[after..]
}

// V3 interprets an uppercase C field followed by `[N]Type` as an embedded
// struct with attributes. A named fixed-array type preserves the C field name,
// its layout, and compatibility with both V compilers.
fn name_c_fixed_array_fields(input string) string {
mut aliases := map[string]string{}
mut scalar_aliases := map[string]string{}
for line in input.split_into_lines() {
if name, rhs := type_alias(line) {
if rhs in ['i8', 'u8', 'i16', 'u16', 'i32', 'u32', 'i64', 'u64', 'f32', 'f64'] {
scalar_aliases[name] = rhs
}
}
}
mut declarations := []string{}
mut lines := []string{}
mut in_c_struct := false
for line in input.split_into_lines() {
trimmed := line.trim_space()
if trimmed.starts_with('pub struct C.') && trimmed.ends_with('{') {
in_c_struct = true
} else if in_c_struct && trimmed == '}' {
in_c_struct = false
}
if in_c_struct {
if field, typ := field_decl(line) {
// V3 treats `ID ID` as an embedded ID. The scalar backing
// type has the same ABI and disambiguates the C field.
if field == typ && field in scalar_aliases {
lines << line[..line.last_index(typ) or { 0 }] + scalar_aliases[field]
continue
}
if field == 'ID' && typ == 'imgui.ID' {
lines << line[..line.last_index(typ) or { 0 }] + 'u32'
continue
}
if starts_upper(field) && typ.starts_with('[') {
if typ.contains('&') {
// Keeping pointer arrays direct avoids a V2 cgen dependency
// cycle for self-referential structs such as DockNode.
lines << '\t${field}${typ}'
continue
}
mut alias := aliases[typ]
if alias == '' {
alias = 'BindingFixedArray${aliases.len + 1}'
aliases[typ] = alias
declarations << 'pub type ${alias} = ${typ}'
}
lines << '\t${field} ${alias}'
continue
}
}
}
lines << line
}
mut output := lines.join('\n') + '\n'
if declarations.len > 0 {
output = insert_after_version(output, declarations.join('\n') + '\n\n')
}
// ImVec1 is a by-value C struct, so its binding needs its actual field.
output = replace_struct_block(output, 'ImVec1', 'pub struct C.ImVec1 {\npub mut:\n\tx f32\n}')
// These ImPlot structs are stored by value. Keep their declarations in
// sync with the corresponding definitions in cimplot.h.
output = replace_struct_block(output, 'ImPlotDateTimeSpec_c', 'pub struct C.ImPlotDateTimeSpec_c {\npub mut:\n\tDate DateFmt\n\tTime TimeFmt\n\tUseISO8601 bool\n\tUse24HourClock bool\n}')
output = replace_struct_block(output, 'ImPlotSpec_c', 'pub struct C.ImPlotSpec_c {\npub mut:\n\tLineColor ImVec4_c\n\tLineColors &u32\n\tLineWeight f32\n\tFillColor ImVec4_c\n\tFillColors &u32\n\tFillAlpha f32\n\tMarker i32\n\tMarkerSize f32\n\tMarkerSizes &f32\n\tMarkerLineColor ImVec4_c\n\tMarkerLineColors &u32\n\tMarkerFillColor ImVec4_c\n\tMarkerFillColors &u32\n\tSize f32\n\tOffset int\n\tStride int\n\tFlags ItemFlags\n}')
output = output.replace('pub type DateTimeSpec = C.DateTimeSpec_c', 'pub type DateTimeSpec = DateTimeSpec_c')
output = output.replace('pub type Spec = C.Spec_c', 'pub type Spec = Spec_c')
output = output.replace('@[typedef]\npub struct C.DateTimeSpec_c {}\n\n', '')
output = output.replace('@[typedef]\npub struct C.Spec_c {}\n\n', '')
return output
}

fn clean_one(kind string, input_path string, output_path string) ! {
cfg := config_for(kind)!
source := os.read_file(input_path)!
Expand Down Expand Up @@ -1716,6 +1789,7 @@ fn clean_one(kind string, input_path string, output_path string) ! {
final = insert_after_version(final, header_alias_decls(ctx, final))
final = insert_after_version(final, missing_c_alias_target_decls(final, imported_structs))
final = final_sanitize(kind, final)
final = name_c_fixed_array_fields(final)
os.write_file(output_path, final)!
println('cleaned ${kind}: ${input_path} -> ${output_path}')
}
Expand All @@ -1731,6 +1805,12 @@ fn self_test() {
assert clean_type_expr('imgui', '&ImGuiContext') == '&Context'
assert clean_type_expr('implot', 'C.ImPlotSpec_c') == 'C.Spec_c'
assert clean_type_expr('implot', '&ImGuiContext') == '&imgui.Context'
assert name_c_fixed_array_fields('pub const version_num = 1\n\npub struct C.Sample {\npub mut:\n\tColors [3]f32\n}\n') == 'pub const version_num = 1\n\npub type BindingFixedArray1 = [3]f32\n\npub struct C.Sample {\npub mut:\n\tColors BindingFixedArray1\n}\n'
assert name_c_fixed_array_fields('pub struct C.Node {\npub mut:\n\tChildren [2]&Node\n}\n') == 'pub struct C.Node {\npub mut:\n\tChildren[2]&Node\n}\n'
assert name_c_fixed_array_fields('pub type ID = u32\npub struct C.Sample {\npub mut:\n\tID ID\n}\n') == 'pub type ID = u32\npub struct C.Sample {\npub mut:\n\tID u32\n}\n'
assert name_c_fixed_array_fields('pub struct C.ImVec1 {}\n').contains('x f32')
assert name_c_fixed_array_fields('pub struct C.ImPlotSpec_c {}\n').contains('Marker i32')
assert name_c_fixed_array_fields('pub type Spec = C.Spec_c\n') == 'pub type Spec = Spec_c\n'
assert postprocess_identifiers('value int, callback C.int(x), args va_list, c C.va_list') == 'value i32, callback (x), args Va_list, c C.va_list'
known := {
'first': i64(1 << 4)
Expand All @@ -1744,6 +1824,12 @@ fn main() {
self_test()
return
}
if os.args.len == 3 && os.args[1] == '--v3-fixed-arrays' {
path := os.args[2]
content := os.read_file(path) or { panic(err) }
os.write_file(path, name_c_fixed_array_fields(content)) or { panic(err) }
return
}
if os.args.len != 4 {
usage()
exit(2)
Expand Down
5 changes: 5 additions & 0 deletions generate.vsh
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ fn main() {
run_at('v run ${os.quoted_path(cleanup)} ${os.quoted_path(imgui_binding)} ${os.quoted_path(imgui_binding)} imgui', repo_dir) or { panic(err) }
run_at('v run ${os.quoted_path(cleanup)} ${os.quoted_path(implot_binding)} ${os.quoted_path(implot_binding)} implot', repo_dir) or { panic(err) }
run_at('v fmt -w ${os.quoted_path(imgui_binding)}', repo_dir) or { panic(err) }
// vfmt restores a space before fixed-array types. V3 currently treats that
// form as an embedded-struct attribute when the C field name is uppercase.
run_at('v run ${os.quoted_path(cleanup)} --v3-fixed-arrays ${os.quoted_path(imgui_binding)}', repo_dir) or {
panic(err)
}
// Do not format ImPlot: its C field/type pair `Marker Marker` is currently
// collapsed by vfmt into invalid V.
run_at('v run ${os.quoted_path(os.join_path(repo_dir, 'build_vimgui.vsh'))}', repo_dir) or {
Expand Down
Loading
Loading