Skip to content

Commit 9a61d48

Browse files
Add comprehensive Copilot instructions for stackman repository
Co-authored-by: kristjanvalur <6009543+kristjanvalur@users.noreply.github.com>
1 parent a24bcf9 commit 9a61d48

File tree

1 file changed

+96
-0
lines changed

1 file changed

+96
-0
lines changed

.github/copilot-instructions.md

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# Copilot Instructions for stackman
2+
3+
## Overview
4+
Low-level C library for stack manipulation (continuations/co-routines). ~600 lines of C + assembly. Zero dependencies. Platforms: Linux (x86/x64/ARM), Windows (x86/x64/ARM). Toolchains: GCC, Clang, MSVC.
5+
6+
## Build Commands (FAST: <1 second)
7+
8+
**Always run in order:**
9+
```bash
10+
make clean # Clean build artifacts
11+
make all # Build library (0.1s) → lib/[ABI]/libstackman.a
12+
make test # Build + run 4 test suites (0.7s)
13+
make abiname # Print platform ABI (e.g., sysv_amd64)
14+
```
15+
16+
**Success output:** `*** All test suites passed ***`
17+
18+
**Cross-compile x86:** `make PLATFORMFLAGS=-m32 test`
19+
**Cross-compile ARM:** `make PLATFORM_PREFIX=arm-linux-gnueabi- EMULATOR=qemu-arm test`
20+
**Windows:** `msbuild vs2022\stackman.sln /p:Platform=x64` then `vs2022\x64\Debug\test.exe`
21+
22+
## Critical Build Notes
23+
24+
1. **Intel CET:** `-fcf-protection=none` flag REQUIRED (auto-added by disable_cet script). Stack switching incompatible with Shadow Stack.
25+
2. **Libraries ARE Committed:** `lib/**/*.a` and `lib/**/*.lib` are version controlled (unlike typical projects). CI rebuilds and commits them.
26+
3. **Expected Warning:** Linker warning "missing .note.GNU-stack section" in test_asm is NORMAL - ignore it.
27+
4. **Artifacts:** `*.o`, `bin/`, `tmp/` NOT committed. Libraries in `lib/[ABI]/` ARE committed.
28+
5. **Incremental OK:** After code changes, just `make test`. Only clean when switching platforms.
29+
30+
## Project Structure
31+
32+
**Key Directories:**
33+
- `stackman/` - Main source: `stackman.h` (API), `stackman_switch.h`, `stackman_impl.h`, `platforms/` (15+ platform files)
34+
- `tests/` - 4 test files: `test.c` (6 tests), `test_cc.cc`, `test_static.c`, `test_asm.c/.S`
35+
- `lib/[ABI]/` - Pre-built libraries (COMMITTED to git)
36+
- `vs2017/`, `vs2019/`, `vs2022/` - Visual Studio projects
37+
- `tools/` - `abiname.sh`, `strip-lib.py`
38+
39+
**Core API (2 functions only):**
40+
```c
41+
void *stackman_switch(stackman_cb_t callback, void *context); // Main stack switch
42+
void *stackman_call(stackman_cb_t callback, void *context, void *stack); // Call with different stack
43+
```
44+
45+
**Architecture:** `platforms/platform.h` detects OS/arch/compiler → includes appropriate `switch_[abi]_[compiler].h/S/asm`
46+
47+
## CI Validation (.github/workflows/buildcommit.yml)
48+
49+
**Triggers:** Push to master/dev, PRs to master
50+
51+
**Jobs:**
52+
1. **build-linux-gnu** (AMD64, i386, arm, aarch64) - installs cross-tools → `make all` → `make test` (qemu for ARM)
53+
2. **build-windows** (x86, x64, arm, arm64) - MSBuild → strip-lib.py → rebuild (MUST rebuild after strip!)
54+
3. **commit-artifacts** (push only) - downloads artifacts → commits libs → pushes
55+
56+
**Local validation:**
57+
```bash
58+
make clean && make test # Test native platform
59+
git status # Verify no bin/, tmp/, *.o tracked
60+
```
61+
62+
## Key Patterns & Workarounds
63+
64+
**Making Changes:**
65+
- Platform code: edit `stackman/platforms/switch_*.h` or `.S` - reference `switch_template.h`
66+
- Always run `make test` after changes (fast: 0.7s)
67+
- Test on actual hardware if modifying assembly (arch-specific!)
68+
69+
**Known Issues/Workarounds:**
70+
- **CET:** `-fcf-protection=none` REQUIRED (auto-added by disable_cet script)
71+
- **Inline asm:** May be inlined by optimizer → use separate .S files or volatile pointer (see stackman_impl.h)
72+
- **Stack align:** Use `STACKMAN_SP_ALIGN` macro
73+
74+
**Testing:** 4 test executables, 6 tests each (assertions fail hard). Success: "test_XX ok" + "*** All test suites passed ***"
75+
76+
**Include patterns:**
77+
- User code: `#include "stackman.h"`
78+
- Library impl: `#include "stackman_impl.h"` (once)
79+
80+
## Configuration Files
81+
- **Build:** Makefile (Linux), vs2022/*.vcxproj (Windows)
82+
- **CI:** .github/workflows/buildcommit.yml
83+
- **Linting:** None configured
84+
- **Testing:** `make test` target
85+
- **.gitignore:** Excludes *.o, bin/, tmp/ BUT includes lib/**/*.a, lib/**/*.lib
86+
87+
## Development Tips
88+
89+
1. **Trust these instructions first** - search only if info incomplete/incorrect
90+
2. **Build is FAST** - rebuild freely (clean+test <1s)
91+
3. **Test after every change** - `make test` is fast and comprehensive
92+
4. **Cross-compilation optional** - CI validates all platforms, native x64 sufficient for most changes
93+
5. **Binary files in git** - lib/**/*.a, lib/**/*.lib ARE tracked (expect binary diffs)
94+
6. **Zero dependencies** - don't add any
95+
7. **Minimal changes** - stable library, surgical edits only
96+
8. **Low-level code** - assembly is platform-specific, test on actual hardware

0 commit comments

Comments
 (0)