Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
158 changes: 158 additions & 0 deletions .github/copilot-instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
# GitHub Copilot Instructions for Eclipse Platform SWT

## Project Overview

This is the **Eclipse Platform SWT** (Standard Widget Toolkit) repository - a cross-platform GUI library for JVM-based desktop applications. SWT is the foundation for the Eclipse IDE and many other desktop applications.

## Architecture

SWT consists of two main parts:
1. **Java code** - Platform-independent widget implementations and APIs
2. **Native code (C)** - Platform-specific implementations using native windowing systems

### Platform Support
- **Linux**: GTK3 (stable) and GTK4 (experimental)
- **Windows**: Win32 API
- **macOS**: Cocoa

### Key Components
- `bundles/org.eclipse.swt` - Main SWT bundle with Java and native code
- `bundles/org.eclipse.swt.svg` - SVG support
- `bundles/org.eclipse.swt.tools` - Build and development tools
- `binaries/` - Platform-specific binary fragments
- `examples/` - Example code and snippets
- `tests/` - JUnit tests

## Build System

### Technology Stack
- **Build Tool**: Maven with Tycho plugin
- **Java Version**: Java 17 (compiler target), Java 21 (build/runtime in CI)
- **Supported Architectures**: x86_64, aarch64, loongarch64, ppc64le, riscv64

### Build Commands
```bash
# Build the entire project
mvn clean verify

# Build specific platform binary
mvn clean verify -Dnative=gtk.linux.x86_64

# Skip tests
mvn clean verify -DskipTests
```

### Building Natives
To rebuild native libraries:
1. Ensure the appropriate binary project is imported in your workspace (e.g., `binaries/org.eclipse.swt.gtk.linux.x86_64`)
2. Native build scripts are platform-specific and located in the binary fragments
3. For GTK on Linux: See `docs/gtk-dev-guide.md` for detailed instructions

## Coding Standards

### Java Code
- **Indentation**: Tabs (as per Eclipse project conventions)
- **Line Length**: Keep lines reasonably short, no strict limit
- **Naming**: Follow standard Java conventions (camelCase for methods/variables, PascalCase for classes)
- **Comments**: Use JavaDoc for public APIs; inline comments where needed for clarity
- **Assertions**: Use assertions for runtime checks (enabled in tests, disabled in production)

### Native Code (C)
- **Platform-specific**: Code goes in platform folders (gtk/, win32/, cocoa/)
- **JNI**: Communication between Java and native code uses JNI
- **OS.java**: Central file for native method declarations
- Do not commit binaries! They will be build and comitted by the CI.

### Code Organization
- Platform-independent code: `bundles/org.eclipse.swt/Eclipse SWT/common/`
- Platform-specific code: `bundles/org.eclipse.swt/Eclipse SWT/{gtk,win32,cocoa}/`
- Emulated widgets: `bundles/org.eclipse.swt/Eclipse SWT/emulated/`

## Testing

### Running Tests
```bash
# Run all tests
mvn clean verify

# Run specific test class
mvn test -Dtest=ClassName
```

### Test Location
- Main tests: `tests/org.eclipse.swt.tests/`
- Tests automatically run with assertions enabled

### Writing Tests
- Follow existing test patterns in the repository
- Platform-specific tests should be in appropriate fragments
- Use JUnit for all tests

## Development Workflow

### Making Changes

1. **Java-only changes**: Can be tested without rebuilding natives
2. **Native changes**: Require rebuilding the platform-specific binary fragment
3. **Cross-platform changes**: Test on all affected platforms

### Pull Request Guidelines
- Sign the Eclipse Foundation Contributor License Agreement (CLA)
- Ensure all tests pass
- Follow the contribution guidelines in CONTRIBUTING.md
- Reference related GitHub issues

### CI/CD
- GitHub Actions runs builds on Linux, Windows, and macOS
- Matrix builds test with Java 21 on all platforms
- All tests must pass before merge

## Important Files and Patterns

### Key Files
- `OS.java` - Central native method declarations for platform integration
- `Display.java` - Main event loop and display management
- `Widget.java` - Base class for all widgets
- `Control.java` - Base class for all controls

### Common Patterns
- **Resource Management**: Always dispose of SWT resources (Display, Shell, Image, etc.)
- **Threading**: UI operations must run on the UI thread (use `Display.asyncExec()` or `Display.syncExec()`)
- **Event Handling**: Use listeners (typed or untyped) for event handling
- **Layout Management**: Use layout managers (GridLayout, FillLayout, etc.) instead of absolute positioning

## Platform-Specific Considerations

### GTK (Linux)
- Communication from Java to C happens through `OS.java`
- GTK3 is stable; GTK4 is experimental
- Can be toggled using `SWT_GTK4` environment variable
- See `docs/gtk-dev-guide.md` for comprehensive GTK development guide

### Windows
- Uses Win32 API
- WebView2 support available (see `Readme.WebView2.md`)
- Platform-specific code in `win32/` directories

### macOS
- Uses Cocoa framework
- Supports both x86_64 and aarch64 (Apple Silicon)
- Platform-specific code in `cocoa/` directories

## Resources

- **Main README**: [`README.md`](../README.md)
- **Contributing Guide**: [`CONTRIBUTING.md`](../CONTRIBUTING.md)
- **GTK Development Guide**: [`docs/gtk-dev-guide.md`](../docs/gtk-dev-guide.md)
- **GitHub Discussions**: Use for questions and general discussions
- **GitHub Issues**: Use for bug reports and feature requests

## Tips for Copilot

- When generating SWT code, always include proper resource disposal
- Remember that SWT is not thread-safe - UI operations need Display.syncExec/asyncExec
- Platform-specific code should go in the appropriate platform directory
- When adding native methods, declare them in `OS.java` first
- Follow existing code patterns in the repository for consistency
- Use snippets in `examples/org.eclipse.swt.snippets/` as reference examples
- Consider cross-platform compatibility when making changes
10 changes: 10 additions & 0 deletions .github/instructions/GTK.instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
applyTo: "bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/*.c,bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/*.h"
---

- Due to the copilot environment setup in copilot-setup-steps.yml we always use x86_64 architecture
- Always carefully investigate exsiting GTK functions the gtk-dev files are installed in the system
- The GTK docs can be found here https://www.gtk.org/docs/
- Be carefull between the difference of GTK3 and GTK4 we need to check for specific versions in some places already
- The GTK3 > GTK4 migration guide can be found here https://docs.gtk.org/gtk4/migrating-3to4.html
- You will find a shell script ./build_gtk.sh that must be used to compile the code for testing changes
44 changes: 44 additions & 0 deletions .github/workflows/copilot-setup-steps.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: "Copilot Setup Steps"

# Automatically run the setup steps when they are changed to allow for easy validation, and
# allow manual testing through the repository's "Actions" tab
on:
workflow_dispatch:
pull_request:
paths:
- .github/workflows/copilot-setup-steps.yml

jobs:
# The job MUST be called `copilot-setup-steps` or it will not be picked up by Copilot.
copilot-setup-steps:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
lfs: false

- name: Set up JDK
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'temurin'
cache: 'maven'

- name: Set up Maven
uses: stCarolas/setup-maven@v5
with:
maven-version: '3.9.11'
- name: Prepare Linux Build
run: |
sudo apt-get update -qq
sudo apt-get install -qq -y libgtk-3-dev libgtk-4-dev freeglut3-dev webkit2gtk-driver
mkdir -p /home/runner/build/gtk && mkdir -p /home/runner/build/tmp

echo "cd $GITHUB_WORKSPACE/bundles/org.eclipse.swt && java -Dws=gtk -Darch=x86_64 build-scripts/CollectSources.java -nativeSources '/home/runner/build/gtk'" >> $GITHUB_WORKSPACE/build_gtk.sh
echo "cd /home/runner/build/gtk && SWT_JAVA_HOME=${JAVA_HOME} MODEL=x86_64 OUTPUT_DIR=/home/runner/build/tmp ./build.sh install clean" >> $GITHUB_WORKSPACE/build_gtk.sh
echo "cd $GITHUB_WORKSPACE" >> $GITHUB_WORKSPACE/build_gtk.sh
chmod +x $GITHUB_WORKSPACE/build_gtk.sh

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ pom.tycho

/binaries/org.eclipse.swt.*/src/
tmpdir/
‎build_gtk.sh
Loading
Loading