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
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
* text=auto eol=lf
*.a binary
*.bat text eol=crlf
*.cj text
*.dll binary
*.gif binary
Expand Down
118 changes: 118 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
name: build

on: [push, pull_request]

env:
VCPKG_BINARY_SOURCES: "clear;x-gha,readwrite"

jobs:
build:
name: ${{ matrix.preset }}
runs-on: ${{ matrix.os }}

strategy:
# Set fail-fast to false to ensure that feedback is delivered for all matrix combinations.
# Consider changing this to true when your workflow is stable.
fail-fast: false

# Set up a matrix to run the following configurations:
matrix:
preset:
- linux-release
- windows-release
os:
- ubuntu-latest
- windows-latest
include:
- preset: linux-release
os: ubuntu-latest
triplet: x64-linux
toolchain: /usr/local/share/vcpkg/scripts/buildsystems/vcpkg.cmake
- preset: windows-release
os: windows-latest
triplet: x64-mingw-dynamic
toolchain: C:/vcpkg/scripts/buildsystems/vcpkg.cmake
exclude:
- os: ubuntu-latest
preset: windows-release
- os: windows-latest
preset: linux-release

steps:
- uses: actions/checkout@v3

- name: Install CMake
uses: lukka/get-cmake@latest
with:
cmakeVersion: "3.31.5"

- name: Enable GitHub Actions cache
uses: actions/github-script@v6
with:
script: |
core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || '');
core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || '');

- name: Install CSFML dependencies
if: runner.os == 'Linux'
uses: awalsh128/cache-apt-pkgs-action@latest
with:
packages: libx11-dev libxrandr-dev libxcursor-dev libxi-dev libudev-dev libgl1-mesa-dev nasm
version: 1.0
execute_install_scripts: true

- name: Setup w64devkit
if: runner.os == 'Windows'
run: |
Invoke-WebRequest -Uri "https://github.com/skeeto/w64devkit/releases/download/v2.1.0/w64devkit-x64-2.1.0.exe" -OutFile "w64devkit-x64-2.1.0.exe"
Start-Process -FilePath "w64devkit-x64-2.1.0.exe" -ArgumentList "-oC:\", "-y" -Wait
echo "C:\w64devkit\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append

- name: Verify w64devkit installation
if: runner.os == 'Windows'
run: |
gcc --version
g++ --version

- name: Setup Ninja
uses: turtlesec-no/get-ninja@main

- name: Setup Cangjie
if: runner.os == 'Linux'
run: |
curl -L -o Cangjie-0.53.18-linux_x64.tar.gz https://github.com/causerp/cangjie/releases/download/v0.53.18/Cangjie-0.53.18-linux_x64.tar.gz
tar -xzf Cangjie-0.53.18-linux_x64.tar.gz -C .

- name: Setup Cangjie
if: runner.os == 'Windows'
run: |
Invoke-WebRequest -Uri "https://github.com/causerp/cangjie/releases/download/v0.53.18/Cangjie-0.53.18-windows_x64.zip" -OutFile "Cangjie-0.53.18-windows_x64.zip"
Expand-Archive -Path "Cangjie-0.53.18-windows_x64.zip" -DestinationPath "."

- name: Download CSFML
shell: bash
run: ./download_csfml.sh

- name: Install vcpkg dependencies
run: |
vcpkg install sfml --triplet=${{ matrix.triplet }}

- name: Build CSFML
run: |
cd csfml
cmake --preset ${{ matrix.preset }} -DCMAKE_TOOLCHAIN_FILE=${{ matrix.toolchain }}
cmake --build --preset ${{ matrix.preset }} --target install

- name: Build and test cjsfml
if: runner.os == 'Linux'
shell: bash
run: |
source ./cangjie/envsetup.sh
cjpm build
cjpm test

- name: Build cjsfml
if: runner.os == 'Windows'
run: |
.\cangjie\envsetup.ps1
cjpm build
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
.svn
.vs
.vscode
csfml
target
96 changes: 96 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
{
"version": 3,
"configurePresets": [
{
"name": "linux-base",
"hidden": true,
"generator": "Ninja",
"binaryDir": "${sourceDir}/build",
"installDir": "${sourceDir}/install",
"cacheVariables": {
"BUILD_SHARED_LIBS": true
},
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Linux"
}
},
{
"name": "linux-debug",
"displayName": "Debug",
"inherits": "linux-base",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug"
}
},
{
"name": "linux-release",
"displayName": "Release",
"inherits": "linux-debug",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release"
}
},
{
"name": "windows-base",
"hidden": true,
"generator": "Ninja",
"binaryDir": "${sourceDir}/build",
"installDir": "${sourceDir}/install",
"cacheVariables": {
"BUILD_SHARED_LIBS": true,
"CMAKE_C_COMPILER": "gcc",
"CMAKE_CXX_COMPILER": "g++",
"CMAKE_TOOLCHAIN_FILE": {
"value": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake",
"type": "FILEPATH"
},
"VCPKG_TARGET_TRIPLET": "x64-mingw-dynamic"
},
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Windows"
}
},
{
"name": "windows-debug",
"displayName": "Debug",
"inherits": "windows-base",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug"
}
},
{
"name": "windows-release",
"displayName": "Release",
"inherits": "windows-debug",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release"
}
}
],
"buildPresets": [
{
"name": "linux-debug",
"configurePreset": "linux-debug",
"displayName": "Debug"
},
{
"name": "linux-release",
"configurePreset": "linux-release",
"displayName": "Release"
},
{
"name": "windows-debug",
"configurePreset": "windows-debug",
"displayName": "Debug"
},
{
"name": "windows-release",
"configurePreset": "windows-release",
"displayName": "Release"
}
]
}
10 changes: 5 additions & 5 deletions cjpm.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
endian = { git = "https://github.com/causerp/endian.git", tag = "v1.0.0"}

[ffi.c]
csfml-audio = { path = "./csfml" }
csfml-graphics = { path = "./csfml" }
csfml-network = { path = "./csfml" }
csfml-system = { path = "./csfml" }
csfml-window = { path = "./csfml" }
csfml-audio = { path = "./csfml/install/lib" }
csfml-graphics = { path = "./csfml/install/lib" }
csfml-network = { path = "./csfml/install/lib" }
csfml-system = { path = "./csfml/install/lib" }
csfml-window = { path = "./csfml/install/lib" }
8 changes: 0 additions & 8 deletions csfml/README.md

This file was deleted.

Binary file removed csfml/csfml-audio-2.dll
Binary file not shown.
Binary file removed csfml/csfml-graphics-2.dll
Binary file not shown.
Binary file removed csfml/csfml-network-2.dll
Binary file not shown.
Binary file removed csfml/csfml-system-2.dll
Binary file not shown.
Binary file removed csfml/csfml-window-2.dll
Binary file not shown.
Binary file removed csfml/libcsfml-audio.a
Binary file not shown.
Binary file removed csfml/libcsfml-graphics.a
Binary file not shown.
Binary file removed csfml/libcsfml-network.a
Binary file not shown.
Binary file removed csfml/libcsfml-system.a
Binary file not shown.
Binary file removed csfml/libcsfml-window.a
Binary file not shown.
15 changes: 0 additions & 15 deletions csfml/license.md

This file was deleted.

Binary file removed csfml/openal32.dll
Binary file not shown.
2 changes: 2 additions & 0 deletions download_csfml.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
git clone --branch 2.6.1 https://github.com/SFML/CSFML.git csfml
cp -f CMakePresets.json ./csfml/CMakePresets.json
65 changes: 65 additions & 0 deletions src/system/Buffer.cj
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package cjsfml.system

foreign {
func sfBuffer_create(): CPointer<Unit>

func sfBuffer_destroy(handle: CPointer<Unit>): Unit

@FastNative
func sfBuffer_getSize(handle: CPointer<Unit>): UIntNative

@FastNative
func sfBuffer_getData(handle: CPointer<Unit>): CPointer<UInt8>
}

protected class Buffer <: ResourceHandle {
private var m_handle: CPointer<Unit> = CPointer()

public init() {
m_handle = unsafe { sfBuffer_create() }
if (m_handle.isNull()) {
throw SFMLNullHandleException()
}
}

~init() {
if (m_handle.isNotNull()) {
unsafe { sfBuffer_destroy(m_handle) }
m_handle = CPointer()
}
}

// ResourceHandle

public func isClosed(): Bool {
m_handle.isNull()
}

public func close(): Unit {
if (isClosed()) {
return
}
unsafe { sfBuffer_destroy(m_handle) }
m_handle = CPointer()
}

public prop handle: CPointer<Unit> {
get() {
m_handle
}
}

// buffer

public prop size: Int64 {
get() {
unsafe { Int64(sfBuffer_getSize(m_handle)) }
}
}

public prop data: CPointer<UInt8> {
get() {
unsafe { sfBuffer_getData(m_handle) }
}
}
}