diff --git a/.gitignore b/.gitignore index ecbb94a..4dc5829 100644 --- a/.gitignore +++ b/.gitignore @@ -239,3 +239,6 @@ _Pvt_Extensions/ ModelManifest.xml .cache/ + +# Visual Studio Code +.vscode/ diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..f45e33b --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,11 @@ +{ + // See https://go.microsoft.com/fwlink/?LinkId=827846 to learn about workspace recommendations. + // Extension identifier format: ${publisher}.${name}. Example: vscode.csharp + + // List of extensions which should be recommended for users of this workspace. + "recommendations": [ + "ms-vscode.cmake-tools", // CMake for Debugging C/C++ + "llvm-vs-code-extensions.vscode-clangd", // Optional intellisense-like features with LLVM/clangd + "theodevelop.bison-flex-lang", // For flex/bison source files + ], +} \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..fd70387 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,34 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "(lldb) Launch", + "type": "lldb", + "request": "launch", + // Resolved by CMake Tools: + "program": "${command:cmake.launchTargetPath}", + // "--header-file=", "-o", "" + "args": [], + "cwd": "${workspaceFolder}", + "terminal": "integrated", + "stopOnEntry": false, + // Non-Windows is unnecessary but it helps to ensure PATH correctly + "env": { + "PATH": "${env:PATH}:${command:cmake.launchTargetDirectory}" + }, + "windows": { + // Warning: CodeLLDB is still slower than WinDbg (cppvsdbg) in Windows + // and don't support C++ (string/vector) for MSVC ABI - this codebase is C99 + "env": { + "PATH": "${env:PATH};${command:cmake.launchTargetDirectory}" + } + }, + "initCommands": [ + "settings set target.process.follow-fork-mode parent" + ] + }, + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..00ec248 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,17 @@ +{ + "editor.insertSpaces": true, + "editor.tabSize": 4, + "editor.detectIndentation": true, + "files.trimTrailingWhitespace": true, + "[markdown]": { + "files.trimTrailingWhitespace": false, + }, + "editor.rulers": [80,120], + "git.rebaseWhenSync": true, + "git.pruneOnFetch": true, + // "cmake.preferredGenerators": ["Ninja Multi-Config"], + "cmake.generator": "Ninja Multi-Config", + "cmake.options.statusBarVisibility": "compact", + "cmake.useCMakePresets": "never", + "C_Cpp.intelliSenseEngine": "disabled", +} \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 92e5563..3f7c61a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -61,6 +61,11 @@ if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) endforeach() message(STATUS "Using /MT STATIC runtime") endif () + + # MSVC's incremental linking is offering little to no benefit, + # disable it for faster link times (and prevent ilk binary bloat). + # NOTE: Frequent build with vscode is hitting resource busy for the the ilk files. + add_link_options("/INCREMENTAL:NO") endif () endif () diff --git a/README.md b/README.md index 68f21d0..ae7be1e 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,10 @@ The release page includes the full Changelog but you may also see the [changelog ## HowTo -You may use win_flex and win_bison directly on the command line or [use them via CustomBuildRules in VisualStudio](custom_build_rules/README.md). +You may use `win_flex` and `win_bison`: +- directly on the command line +- [via CustomBuildRules in VisualStudio](custom_build_rules/README.md). +- via [CMake Tools](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cmake-tools) in [vscode-like editors](vscode/README.md). ## Example flex/bison files diff --git a/vscode/1_compiler.png b/vscode/1_compiler.png new file mode 100644 index 0000000..a0edea6 Binary files /dev/null and b/vscode/1_compiler.png differ diff --git a/vscode/2_target.png b/vscode/2_target.png new file mode 100644 index 0000000..e4837ef Binary files /dev/null and b/vscode/2_target.png differ diff --git a/vscode/3_build.png b/vscode/3_build.png new file mode 100644 index 0000000..70eb63c Binary files /dev/null and b/vscode/3_build.png differ diff --git a/vscode/4_breakpoint.png b/vscode/4_breakpoint.png new file mode 100644 index 0000000..bdbfa53 Binary files /dev/null and b/vscode/4_breakpoint.png differ diff --git a/vscode/5_launch.png b/vscode/5_launch.png new file mode 100644 index 0000000..a9a8191 Binary files /dev/null and b/vscode/5_launch.png differ diff --git a/vscode/6_pause.png b/vscode/6_pause.png new file mode 100644 index 0000000..b48be51 Binary files /dev/null and b/vscode/6_pause.png differ diff --git a/vscode/README.md b/vscode/README.md new file mode 100644 index 0000000..039869b --- /dev/null +++ b/vscode/README.md @@ -0,0 +1,49 @@ + +# How to setup vscode-like editors for debugging win_flex/win_bison + +Here is a simple guide (based on the [MS documentation](https://code.visualstudio.com/docs/cpp/cmake-linux)): +1. Make sure the [Prerequisites](https://code.visualstudio.com/docs/cpp/cmake-linux#_prerequisites) are installed. +2. [Select a compiler kit](https://code.visualstudio.com/docs/cpp/cmake-linux#_select-a-kit), any of the native `amd64` version of MSVC is recommended for compatibility - any of the rest with `x86` is cross-compiling a 32-bit version of `win_flex`/`win_bison`. + +![Select a compiler kit](./1_compiler.png) + +NOTE: Click `Scan for kits` when setting up C/C++ debugging for the first time if there is no compiler kits found yet. + +3. Due to `win_flex`/`win_bison` being separate executables/targets, debugging will need to [select a launch target](https://github.com/microsoft/vscode-cmake-tools/blob/main/docs/debug-launch.md#select-a-launch-target). + +![Select a launch targe](./2_target.png) + +4. Optionally switch between build types - usually between `Release` or `Debug` builds, make sure `Debug` is selected when debugging or there will be no debug symbols to hit breakpoints. + +![Debug build type](./3_build.png) + +5. Both `win_flex` and `win_bison` requires arguments for the target input/output source files, just add the arguments as how `win_flex` or `win_bison` was called from the command line where each space-separated argument is an element in [.vscode/launch.json](.vscode/launch.json)'s `args` array separated by commas, based on [flex-bison-example](https://github.com/meyerd/flex-bison-example), + - here is a sample for `win_flex` target: +```json + "args": [ + "calc.l", + ], +``` + - here is a sample for `win_bison` target: +```json + "args": [ + "-d", + "calc.y", + ], +``` + - NOTE: This example uses source files without full path was achieved by setting `cwd` +```json + "cwd": "${workspaceFolder}/../flex-bison-example", +``` + +6. Setup the codebase for inspection [debugging](https://code.visualstudio.com/docs/editor/debugging), eg. breakpoints (with `F9`), [logpoints](https://github.com/vadimcn/codelldb/blob/master/MANUAL.md#logpoints). + +![Breakpoint](./4_breakpoint.png) + +7. Hit `F5` to start debugging, or click the `launch` button. + +![Launch](./5_launch.png) + +8. Here is how it looks like when the program pauses at a breakpoint, refer to the official [Debugging guide](https://code.visualstudio.com/docs/debugtest/debugging#_debugger-user-interface) for more information. + +![Pause](./6_pause.png) \ No newline at end of file