this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat: add flake and basic program

+404 -1
.cache/clangd/index/main.cpp.47C66B394CD74271.idx

This is a binary file and will not be displayed.

+1
.envrc
··· 1 + use flake
+6
.gitignore
··· 1 + .crush 2 + result 3 + .direnv 4 + .clangd 5 + compile_commands.json 6 + build/
+41
CMakeLists.txt
··· 1 + cmake_minimum_required(VERSION 3.16) 2 + project(HelloWorldApp CXX) 3 + 4 + # Generate compile_commands.json for editor support 5 + set(CMAKE_EXPORT_COMPILE_COMMANDS ON) 6 + 7 + # Target Windows XP compatibility 8 + add_definitions(-DWINVER=0x0501) 9 + add_definitions(-D_WIN32_WINNT=0x0501) 10 + 11 + add_executable(HelloWorldApp WIN32 main.cpp) 12 + target_link_libraries(HelloWorldApp user32 gdi32) 13 + 14 + # Minimal static linking 15 + target_link_options(HelloWorldApp PRIVATE 16 + -static-libgcc 17 + -static-libstdc++ 18 + -Wl,--subsystem,windows:5.01 19 + ) 20 + 21 + # Configurable output directory 22 + if(DEFINED OUTPUT_DIR) 23 + set_target_properties(HelloWorldApp PROPERTIES 24 + RUNTIME_OUTPUT_DIRECTORY "${OUTPUT_DIR}" 25 + RUNTIME_OUTPUT_DIRECTORY_DEBUG "${OUTPUT_DIR}" 26 + RUNTIME_OUTPUT_DIRECTORY_RELEASE "${OUTPUT_DIR}" 27 + ) 28 + endif() 29 + 30 + set_target_properties(HelloWorldApp PROPERTIES 31 + OUTPUT_NAME "HelloWorld" 32 + ) 33 + 34 + # Configurable output directory 35 + if(DEFINED OUTPUT_DIR) 36 + set_target_properties(HelloWorldApp PROPERTIES 37 + RUNTIME_OUTPUT_DIRECTORY "${OUTPUT_DIR}" 38 + RUNTIME_OUTPUT_DIRECTORY_DEBUG "${OUTPUT_DIR}" 39 + RUNTIME_OUTPUT_DIRECTORY_RELEASE "${OUTPUT_DIR}" 40 + ) 41 + endif()
+38 -1
README.md
··· 6 6 7 7 ## Install 8 8 9 - You can download a pre-built binary from the releases or you can cross compile the app for windows xp; i'll add a nix way soonish 9 + You can download a pre-built binary from the releases or build it yourself using the nix flake. 10 + 11 + ## Development 12 + 13 + this project uses nix for cross-compilation to windows xp. the key was using an older nixpkgs (22.05) since newer mingw toolchains use windows apis that don't exist in xp. 14 + 15 + ### Quick Start 16 + 17 + ```bash 18 + # enter the dev environment (or use direnv) 19 + nix develop 20 + 21 + # build the app 22 + nix build 23 + 24 + # deploy to my xp vm folder 25 + deploy-to-xp 26 + ``` 27 + 28 + ### Editor Setup (Zed) 29 + 30 + to get proper intellisense for win32 apis in zed: 31 + 32 + ```bash 33 + # generate .clangd config with proper mingw headers 34 + setup-dev 35 + 36 + # restart zed 37 + ``` 38 + 39 + this creates a `.clangd` file that points to the actual mingw-w64 headers and avoids gcc intrinsics that cause clang issues. 40 + 41 + ### Build Details 42 + 43 + - uses mingw-w64 cross-compiler targeting i686-w64-mingw32 44 + - statically links runtime to avoid dll dependencies 45 + - targets windows xp (winver=0x0501) for maximum compatibility 46 + - older nixpkgs (22.05) prevents "procedure entry point" errors on xp 10 47 11 48 ~ 12 49
+77
flake.lock
··· 1 + { 2 + "nodes": { 3 + "flake-parts": { 4 + "inputs": { 5 + "nixpkgs-lib": "nixpkgs-lib" 6 + }, 7 + "locked": { 8 + "lastModified": 1751413152, 9 + "narHash": "sha256-Tyw1RjYEsp5scoigs1384gIg6e0GoBVjms4aXFfRssQ=", 10 + "owner": "hercules-ci", 11 + "repo": "flake-parts", 12 + "rev": "77826244401ea9de6e3bac47c2db46005e1f30b5", 13 + "type": "github" 14 + }, 15 + "original": { 16 + "owner": "hercules-ci", 17 + "repo": "flake-parts", 18 + "type": "github" 19 + } 20 + }, 21 + "nixpkgs": { 22 + "locked": { 23 + "lastModified": 1685573264, 24 + "narHash": "sha256-Zffu01pONhs/pqH07cjlF10NnMDLok8ix5Uk4rhOnZQ=", 25 + "owner": "NixOS", 26 + "repo": "nixpkgs", 27 + "rev": "380be19fbd2d9079f677978361792cb25e8a3635", 28 + "type": "github" 29 + }, 30 + "original": { 31 + "owner": "NixOS", 32 + "ref": "nixos-22.05", 33 + "repo": "nixpkgs", 34 + "type": "github" 35 + } 36 + }, 37 + "nixpkgs-lib": { 38 + "locked": { 39 + "lastModified": 1751159883, 40 + "narHash": "sha256-urW/Ylk9FIfvXfliA1ywh75yszAbiTEVgpPeinFyVZo=", 41 + "owner": "nix-community", 42 + "repo": "nixpkgs.lib", 43 + "rev": "14a40a1d7fb9afa4739275ac642ed7301a9ba1ab", 44 + "type": "github" 45 + }, 46 + "original": { 47 + "owner": "nix-community", 48 + "repo": "nixpkgs.lib", 49 + "type": "github" 50 + } 51 + }, 52 + "root": { 53 + "inputs": { 54 + "flake-parts": "flake-parts", 55 + "nixpkgs": "nixpkgs", 56 + "systems": "systems" 57 + } 58 + }, 59 + "systems": { 60 + "locked": { 61 + "lastModified": 1681028828, 62 + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", 63 + "owner": "nix-systems", 64 + "repo": "default", 65 + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", 66 + "type": "github" 67 + }, 68 + "original": { 69 + "owner": "nix-systems", 70 + "repo": "default", 71 + "type": "github" 72 + } 73 + } 74 + }, 75 + "root": "root", 76 + "version": 7 77 + }
+141
flake.nix
··· 1 + { 2 + description = "Win32 Hello World App with About dropdown"; 3 + 4 + inputs = { 5 + nixpkgs.url = "github:NixOS/nixpkgs/nixos-22.05"; 6 + flake-parts.url = "github:hercules-ci/flake-parts"; 7 + systems.url = "github:nix-systems/default"; 8 + }; 9 + 10 + outputs = inputs@{ flake-parts, systems, ... }: 11 + flake-parts.lib.mkFlake { inherit inputs; } { 12 + imports = [ ]; 13 + systems = import systems; 14 + perSystem = { self', pkgs, ... }: { 15 + packages = { 16 + hello-world-app = pkgs.stdenv.mkDerivation { 17 + name = "hello-world-app"; 18 + version = "1.0.0"; 19 + src = ./.; 20 + 21 + nativeBuildInputs = with pkgs; [ 22 + cmake 23 + pkgsCross.mingw32.buildPackages.gcc 24 + ]; 25 + 26 + buildInputs = with pkgs.pkgsCross.mingw32; [ 27 + windows.mingw_w64 28 + ]; 29 + 30 + configurePhase = '' 31 + export CC=${pkgs.pkgsCross.mingw32.buildPackages.gcc}/bin/i686-w64-mingw32-gcc 32 + export CXX=${pkgs.pkgsCross.mingw32.buildPackages.gcc}/bin/i686-w64-mingw32-g++ 33 + export CMAKE_SYSTEM_NAME=Windows 34 + export CMAKE_C_COMPILER=$CC 35 + export CMAKE_CXX_COMPILER=$CXX 36 + ''; 37 + 38 + buildPhase = '' 39 + cmake -DCMAKE_BUILD_TYPE=Release \ 40 + -DCMAKE_SYSTEM_NAME=Windows \ 41 + -DCMAKE_C_COMPILER=$CC \ 42 + -DCMAKE_CXX_COMPILER=$CXX . 43 + make VERBOSE=1 44 + ''; 45 + 46 + installPhase = '' 47 + mkdir -p $out/bin 48 + cp HelloWorld.exe $out/bin/ 49 + ''; 50 + }; 51 + 52 + deploy-to-xp = pkgs.writeShellScriptBin "deploy-to-xp" '' 53 + XP_DIR="$HOME/Documents/xp-drive" 54 + mkdir -p "$XP_DIR" 55 + cp ${self'.packages.hello-world-app}/bin/HelloWorld.exe "$XP_DIR/" 56 + echo "Deployed HelloWorld.exe to $XP_DIR" 57 + ''; 58 + 59 + setup-dev = pkgs.writeShellScriptBin "setup-dev" '' 60 + echo "Setting up development environment for Zed..." 61 + 62 + # Get the proper MinGW headers - use the known path from our build 63 + MINGW_MAIN_INCLUDE="/nix/store/hhbkp872dkayzd2qxfhkdc4rgn393g52-mingw-w64-i686-w64-mingw32-9.0.0-dev/include" 64 + 65 + # Verify it exists, if not try to find it dynamically 66 + if [ ! -f "$MINGW_MAIN_INCLUDE/windows.h" ]; then 67 + echo "Static path not found, searching dynamically..." 68 + MINGW_MAIN_INCLUDE=$(i686-w64-mingw32-gcc -v -E - < /dev/null 2>&1 | sed -n '/mingw-w64.*-dev\/include/p' | head -1 | awk '{print $2}') 69 + 70 + if [ -z "$MINGW_MAIN_INCLUDE" ] || [ ! -f "$MINGW_MAIN_INCLUDE/windows.h" ]; then 71 + echo "Error: Could not find proper MinGW headers with windows.h" 72 + exit 1 73 + fi 74 + fi 75 + 76 + # Create simplified .clangd config to avoid intrinsics issues 77 + cat > .clangd << EOF 78 + CompileFlags: 79 + Add: 80 + - -target 81 + - i686-w64-mingw32 82 + - -DWINVER=0x0501 83 + - -D_WIN32_WINNT=0x0501 84 + - -DWIN32_LEAN_AND_MEAN 85 + - -D_WIN32 86 + - -DWIN32 87 + - -std=c++17 88 + - -fno-builtin 89 + - -D__NO_INLINE__ 90 + - -isystem 91 + - $MINGW_MAIN_INCLUDE 92 + Remove: 93 + - -I*/gcc/*/include 94 + EOF 95 + 96 + # Create simplified compile_commands.json 97 + cat > compile_commands.json << EOF 98 + [ 99 + { 100 + "directory": "$(pwd)", 101 + "command": "clang++ -target i686-w64-mingw32 -DWINVER=0x0501 -D_WIN32_WINNT=0x0501 -DWIN32_LEAN_AND_MEAN -D_WIN32 -DWIN32 -fno-builtin -isystem \"$MINGW_MAIN_INCLUDE\" -std=c++17 -c main.cpp", 102 + "file": "main.cpp" 103 + } 104 + ] 105 + EOF 106 + 107 + echo "Generated simplified .clangd config and compile_commands.json" 108 + echo "Using MinGW headers: $MINGW_MAIN_INCLUDE" 109 + echo "" 110 + echo "This avoids GCC intrinsics that cause clang issues" 111 + echo "Restart Zed for the changes to take effect" 112 + ''; 113 + 114 + default = self'.packages.hello-world-app; 115 + }; 116 + 117 + devShells = { 118 + default = pkgs.mkShell { 119 + buildInputs = with pkgs; [ 120 + cmake 121 + pkgsCross.mingw32.buildPackages.gcc 122 + self'.packages.deploy-to-xp 123 + self'.packages.setup-dev 124 + ]; 125 + 126 + shellHook = '' 127 + echo "Win32 development environment loaded (older toolchain)" 128 + echo "Available commands:" 129 + echo " nix build - Build the application" 130 + echo " deploy-to-xp - Deploy to XP VM folder" 131 + echo " setup-dev - Generate compile_commands.json for Zed editor" 132 + echo "" 133 + echo "For Zed editor support:" 134 + echo " 1. Run 'setup-dev' to generate compile_commands.json" 135 + echo " 2. Open project in Zed for IntelliSense support" 136 + ''; 137 + }; 138 + }; 139 + }; 140 + }; 141 + }
+100
main.cpp
··· 1 + #include <windows.h> 2 + 3 + #define ID_ABOUT 1001 4 + #define ID_EXIT 1002 5 + 6 + LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); 7 + 8 + int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int nCmdShow) { 9 + const char* CLASS_NAME = "HelloWorldWindow"; 10 + 11 + WNDCLASS wc = {}; 12 + wc.lpfnWndProc = WindowProc; 13 + wc.hInstance = hInstance; 14 + wc.lpszClassName = CLASS_NAME; 15 + wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); 16 + wc.hCursor = LoadCursor(NULL, IDC_ARROW); 17 + 18 + RegisterClass(&wc); 19 + 20 + HWND hwnd = CreateWindow( 21 + CLASS_NAME, 22 + "Hello World App", 23 + WS_OVERLAPPEDWINDOW, 24 + CW_USEDEFAULT, CW_USEDEFAULT, 400, 300, 25 + NULL, 26 + NULL, 27 + hInstance, 28 + NULL 29 + ); 30 + 31 + if (hwnd == NULL) { 32 + return 0; 33 + } 34 + 35 + // Create menu 36 + HMENU hMenu = CreateMenu(); 37 + HMENU hSubMenu = CreatePopupMenu(); 38 + 39 + AppendMenu(hSubMenu, MF_STRING, ID_ABOUT, "&About"); 40 + AppendMenu(hSubMenu, MF_SEPARATOR, 0, NULL); 41 + AppendMenu(hSubMenu, MF_STRING, ID_EXIT, "E&xit"); 42 + AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT_PTR)hSubMenu, "&Help"); 43 + 44 + SetMenu(hwnd, hMenu); 45 + 46 + ShowWindow(hwnd, nCmdShow); 47 + UpdateWindow(hwnd); 48 + 49 + MSG msg = {}; 50 + while (GetMessage(&msg, NULL, 0, 0)) { 51 + TranslateMessage(&msg); 52 + DispatchMessage(&msg); 53 + } 54 + 55 + return 0; 56 + } 57 + 58 + LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { 59 + switch (uMsg) { 60 + case WM_DESTROY: 61 + PostQuitMessage(0); 62 + return 0; 63 + 64 + case WM_PAINT: { 65 + PAINTSTRUCT ps; 66 + HDC hdc = BeginPaint(hwnd, &ps); 67 + 68 + RECT rect; 69 + GetClientRect(hwnd, &rect); 70 + 71 + // Center the text 72 + SetTextAlign(hdc, TA_CENTER); 73 + SetBkMode(hdc, TRANSPARENT); 74 + TextOut(hdc, rect.right / 2, rect.bottom / 2 - 10, "Hello World!", 12); 75 + 76 + EndPaint(hwnd, &ps); 77 + return 0; 78 + } 79 + 80 + case WM_COMMAND: 81 + switch (LOWORD(wParam)) { 82 + case ID_ABOUT: { 83 + const char* aboutText = "Hello World App\n\n" 84 + "Version: 1.0.0\n" 85 + "Built by: Kieran Klukas\n\n" 86 + "A simple Win32 application\n" 87 + "compatible with Windows XP"; 88 + MessageBox(hwnd, aboutText, "About Hello World App", 89 + MB_OK | MB_ICONINFORMATION); 90 + break; 91 + } 92 + case ID_EXIT: 93 + PostQuitMessage(0); 94 + break; 95 + } 96 + return 0; 97 + } 98 + 99 + return DefWindowProc(hwnd, uMsg, wParam, lParam); 100 + }