From fbd40e4aea76b1db8f3da039be8f71dc85a82fef Mon Sep 17 00:00:00 2001 From: antono2 Date: Sat, 12 Sep 2026 11:21:25 +0200 Subject: [PATCH] Add cross-platform one-command setup --- .github/workflows/demo-release.yml | 5 +- QUICKSTART.md | 3 +- README.md | 9 +++ setup.vsh | 97 ++++++++++++++++++++++++++++++ 4 files changed, 112 insertions(+), 2 deletions(-) create mode 100644 setup.vsh diff --git a/.github/workflows/demo-release.yml b/.github/workflows/demo-release.yml index 06469b0..8a7295e 100644 --- a/.github/workflows/demo-release.yml +++ b/.github/workflows/demo-release.yml @@ -55,7 +55,9 @@ jobs: 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 - name: Verify generated upstream variant working-directory: source/modules/antono2/imgui - run: ./scripts/check_upstream_variant.sh + run: | + v run setup.vsh --check + ./scripts/check_upstream_variant.sh - name: Select package variant id: variant working-directory: source/modules/antono2/imgui @@ -176,6 +178,7 @@ jobs: if (-not $InstallPath) { throw 'Visual Studio C++ tools were not found' } Import-Module (Join-Path $InstallPath 'Common7\Tools\Microsoft.VisualStudio.DevShell.dll') Enter-VsDevShell -VsInstallPath $InstallPath -SkipAutomaticLocation -DevCmdArguments '-arch=x64 -host_arch=x64' + v -check-syntax ./source/modules/antono2/imgui/setup.vsh ./source/modules/antono2/imgui/scripts/run_demo_windows.ps1 -BuildOnly -DemoDirectory "$env:GITHUB_WORKSPACE\source\demo" - name: Package and verify shell: pwsh diff --git a/QUICKSTART.md b/QUICKSTART.md index e868af7..3ea20b3 100644 --- a/QUICKSTART.md +++ b/QUICKSTART.md @@ -1,6 +1,7 @@ # Quick start -The generated V bindings are already committed. Most users only need to build +The generated V bindings are already committed. Most users can prepare the +checkout on Linux, macOS, or Windows with `v run setup.vsh`. They only need to build the native Dear ImGui/ImPlot library; LuaJIT and the binding generator are not required. diff --git a/README.md b/README.md index 98c281a..ddfbd90 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,15 @@ For a fresh-clone setup and a one-command GLFW/Vulkan demo, see [`QUICKSTART.md`](QUICKSTART.md). +The cross-platform setup entry point installs prerequisites and builds the +native library without regenerating bindings: + +```sh +v run setup.vsh +``` + +Use `v run setup.vsh --check` for read-only diagnostics. + This is an automated process to generate `imgui.v` and `implot.v` - generate C for imgui using [cimgui](https://github.com/cimgui/cimgui) - generate C for implot using [cimplot](https://github.com/cimgui/cimplot) diff --git a/setup.vsh b/setup.vsh new file mode 100644 index 0000000..8bcc3a0 --- /dev/null +++ b/setup.vsh @@ -0,0 +1,97 @@ +#!/usr/bin/env -S v run + +// Cross-platform entry point for the native Dear ImGui/ImPlot build. + +import os + +fn run(command string) ! { + println('\n> ${command}') + result := os.execute(command) + if result.output.trim_space() != '' { + println(result.output.trim_right('\r\n')) + } + if result.exit_code != 0 { + return error('command failed with exit code ${result.exit_code}') + } +} + +fn setup_vulkan(mode string) ! { + if mode == '--install' { + run('v install antono2.vulkan')! + } + setup := os.join_path(os.vmodules_dir(), 'antono2', 'vulkan', 'setup.vsh') + if !os.is_file(setup) { + return error('antono2.vulkan does not include setup.vsh; install or update it first') + } + run('v run ${os.quoted_path(setup)} ${mode}')! + $if windows { + value := os.execute('powershell -NoProfile -Command "[Environment]::GetEnvironmentVariable(\'VULKAN_SDK\', \'Machine\')"') + if value.exit_code == 0 && value.output.trim_space() != '' { + os.setenv('VULKAN_SDK', value.output.trim_space(), true) + } + } +} + +fn main() { + if os.args.len > 2 || (os.args.len == 2 && os.args[1] !in ['--install', '--check', '-h', '--help']) { + eprintln('Usage: v run setup.vsh [--install|--check]') + exit(2) + } + if os.args.len == 2 && os.args[1] in ['-h', '--help'] { + println('Usage: v run setup.vsh [--install|--check]\n\nDefault: install dependencies and build the native ImGui library.\n--check: report prerequisites without changing the system or build tree.') + return + } + install := os.args.len == 1 || os.args[1] == '--install' + mode := if install { '--install' } else { '--check' } + project_dir := os.dir(os.real_path(@FILE)) + $if linux { + run('bash ${os.quoted_path(os.join_path(project_dir, 'scripts', 'setup_linux.sh'))} ${mode}') or { + panic(err) + } + if install { + run('git -C ${os.quoted_path(project_dir)} submodule update --init --recursive') or { + panic(err) + } + run('v run ${os.quoted_path(os.join_path(project_dir, 'build_vimgui.vsh'))} --linkage shared --glfw system') or { + panic(err) + } + } + } $else $if macos { + setup_vulkan(mode) or { panic(err) } + if !os.exists_in_system_path('brew') { + eprintln('Homebrew is required for automatic CMake and GLFW installation: https://brew.sh') + exit(1) + } + if install { + run('brew install cmake glfw') or { panic(err) } + run('v install antono2.glfw') or { panic(err) } + run('git -C ${os.quoted_path(project_dir)} submodule update --init --recursive') or { + panic(err) + } + prefix := os.execute('brew --prefix glfw').output.trim_space() + os.setenv('GLFW_INCLUDE', os.join_path(prefix, 'include'), true) + os.setenv('GLFW_LIB', os.join_path(prefix, 'lib'), true) + run('v run ${os.quoted_path(os.join_path(project_dir, 'build_vimgui.vsh'))} --linkage shared --glfw system') or { + panic(err) + } + } + } $else $if windows { + setup_vulkan(mode) or { panic(err) } + script := if install { 'run_demo_windows.ps1' } else { 'check_windows.ps1' } + mut command := 'powershell -NoProfile -ExecutionPolicy Bypass -File ${os.quoted_path(os.join_path(project_dir, 'scripts', script))}' + if install { + command += ' -NativeOnly' + } else { + command += ' -BundledGlfw' + } + run(command) or { panic(err) } + } $else { + eprintln('Automatic setup is unsupported on this operating system.') + exit(1) + } + if install { + println('\nDear ImGui/ImPlot native libraries are ready. Run `./scripts/run_demo.sh` (Linux/macOS) or `scripts\\run_demo_windows.ps1` to launch the demo.') + } else { + println('\nDear ImGui/ImPlot prerequisite check passed.') + } +}