Skip to content

Commit f595cea

Browse files
henderkesdunglas
andauthored
Add IDE (GoLand/CLion) setup to CONTRIBUTING.md (#2269)
Signed-off-by: Marc <m@pyc.ac> Co-authored-by: Kévin Dunglas <kevin@dunglas.fr>
1 parent 5734f46 commit f595cea

File tree

2 files changed

+141
-0
lines changed

2 files changed

+141
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@
1313
__debug_bin
1414
frankenphp.test
1515
*.log
16+
compile_flags.txt

CONTRIBUTING.md

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,146 @@ docker buildx bake -f docker-bake.hcl --pull --no-cache --push
249249

250250
9. When the bug is fixed, revert all these changes
251251

252+
## Development Environment Setup (WSL/Unix)
253+
254+
### Initial setup
255+
256+
Follow the instructions in [compiling from sources](https://frankenphp.dev/docs/compile/).
257+
The steps assume the following environment:
258+
259+
- Go installed at `/usr/local/go`
260+
- PHP source cloned to `~/php-src`
261+
- PHP built at: `/usr/local/bin/php`
262+
- FrankenPHP source cloned to `~/frankenphp`
263+
264+
### CLion Setup for CGO glue/PHP Source Development
265+
266+
1. Install CLion (on your host OS)
267+
268+
- Download from [JetBrains](https://www.jetbrains.com/clion/download/)
269+
- Launch (if on Windows, in WSL):
270+
271+
```bash
272+
clion &>/dev/null
273+
```
274+
275+
2. Open Project in CLion
276+
277+
- Open CLion → Open → Select the `~/frankenphp` directory
278+
- Add a build chain: Settings → Build, Execution, Deployment → Custom Build Targets
279+
- Select any Build Target, under `Build` set up an External Tool (call it e.g. go build)
280+
- Set up a wrapper script that builds frankenphp for you, called `go_compile_frankenphp.sh`
281+
282+
```bash
283+
CGO_CFLAGS="-O0 -g" ./go.sh
284+
```
285+
286+
- Under Program, select `go_compile_frankenphp.sh`
287+
- Leave Arguments blank
288+
- Working Directory: `~/frankenphp/caddy/frankenphp`
289+
290+
3. Configure Run Targets
291+
292+
- Go to Run → Edit Configurations
293+
- Create:
294+
- frankenphp:
295+
- Type: Native Application
296+
- Target: select the `go build` target you created
297+
- Executable: `~/frankenphp/caddy/frankenphp/frankenphp`
298+
- Arguments: the arguments you want to start frankenphp with, e.g. `php-cli test.php`
299+
300+
4. Debug Go files from CLion
301+
302+
- Right click on a *.go file in the Project view on the left
303+
- Override file type → C/C++
304+
305+
Now you can place breakpoints in C, C++ and Go files.
306+
To get syntax highlighting for imports from php-src, you may need to tell CLion about the include paths. Create a
307+
`compile_flags.txt` file in `~/frankenphp` with the following contents:
308+
309+
```gcc
310+
-I/usr/local/include/php
311+
-I/usr/local/include/php/Zend
312+
-I/usr/local/include/php/main
313+
-I/usr/local/include/php/TSRM
314+
```
315+
316+
---
317+
318+
### GoLand Setup for FrankenPHP Development
319+
320+
Use GoLand for primary Go development, but the debugger cannot debug C code.
321+
322+
1. Install GoLand (on your host OS)
323+
324+
- Download from [JetBrains](https://www.jetbrains.com/go/download/)
325+
326+
```bash
327+
goland &>/dev/null
328+
```
329+
330+
2. Open in GoLand
331+
332+
- Launch GoLand → Open → Select the `~/frankenphp` directory
333+
334+
---
335+
336+
### Go Configuration
337+
338+
- Select Go Build
339+
- Name `frankenphp`
340+
- Run kind: Directory
341+
- Directory: `~/frankenphp/caddy/frankenphp`
342+
- Output directory: `~/frankenphp/caddy/frankenphp`
343+
- Working directory: `~/frankenphp/caddy/frankenphp`
344+
- Environment (adjust for your $(php-config ...) output):
345+
`CGO_CFLAGS=-O0 -g -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib;CGO_LDFLAGS=-lm -lpthread -lsqlite3 -lxml2 -lbrotlienc -lbrotlidec -lbrotlicommon -lwatcher`
346+
- Go tool arguments: `-tags=nobadger,nomysql,nopgx`
347+
- Program arguments: e.g. `php-cli -i`
348+
349+
To debug C files from GoLand
350+
351+
- Right click on a *.c file in the Project view on the left
352+
- Override file type → Go
353+
354+
Now you can place breakpoints in C, C++ and Go files.
355+
356+
---
357+
358+
### GoLand Setup on Windows
359+
360+
1. Follow the [Windows Development section](#windows-development)
361+
362+
2. Install GoLand
363+
364+
- Download from [JetBrains](https://www.jetbrains.com/go/download/)
365+
- Launch GoLand
366+
367+
3. Open in GoLand
368+
369+
- Select **Open** → Choose the directory where you cloned `frankenphp`
370+
371+
4. Configure Go Build
372+
373+
- Go to **Run****Edit Configurations**
374+
- Click **+** and select **Go Build**
375+
- Name: `frankenphp`
376+
- Run kind: **Directory**
377+
- Directory: `.\caddy\frankenphp`
378+
- Output directory: `.\caddy\frankenphp`
379+
- Working directory: `.\caddy\frankenphp`
380+
- Go tool arguments: `-tags=nobadger,nomysql,nopgx`
381+
- Environment variables: see the [Windows Development section](#windows-development)
382+
- Program arguments: e.g. `php-server`
383+
384+
---
385+
386+
### Debugging and Integration Notes
387+
388+
- Use CLion for debugging PHP internals and `cgo` glue code
389+
- Use GoLand for primary Go development and debugging
390+
- FrankenPHP can be added as a run configuration in CLion for unified C/Go debugging if needed, but syntax highlighting won't work in Go files
391+
252392
## Misc Dev Resources
253393

254394
- [PHP embedding in uWSGI](https://github.com/unbit/uwsgi/blob/master/plugins/php/php_plugin.c)

0 commit comments

Comments
 (0)