Skip to content

Commit f0c40a9

Browse files
committed
update schema and add example
1 parent 9b61804 commit f0c40a9

File tree

8 files changed

+3146
-0
lines changed

8 files changed

+3146
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# pixi environments
2+
.pixi
3+
4+
# The build directory
5+
.build
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
cmake_minimum_required(VERSION 3.7)
2+
project(sdl_example)
3+
4+
find_package(SDL2 REQUIRED)
5+
6+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
7+
8+
add_executable(${PROJECT_NAME} src/main.cc)
9+
10+
if (MSVC)
11+
set_target_properties(${PROJECT_NAME} PROPERTIES WIN32_EXECUTABLE TRUE)
12+
endif()
13+
14+
target_link_libraries(
15+
${PROJECT_NAME} PRIVATE
16+
SDL2::SDL2
17+
SDL2::SDL2main
18+
)
19+
20+
include(GNUInstallDirs)
21+
install(
22+
TARGETS ${PROJECT_NAME}
23+
EXPORT ${PROJECT_NAME}Targets
24+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
25+
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
26+
RUNTIME DESTINATION ${BINDIR}
27+
)

examples/develop/cpp-sdl/README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Simple C++ SDL Example
2+
3+
This is a simple pixi demo that showcases how to use C++ and SDL.
4+
5+
## How to use?
6+
7+
Make sure you have `pixi` available in your terminal.
8+
Navigate to this directory and run:
9+
10+
```shell
11+
# Configure the CMake project
12+
pixi run configure
13+
14+
# Build the executable
15+
pixi run build
16+
17+
# Start the build executable
18+
pixi run start
19+
```

examples/develop/cpp-sdl/pixi.lock

Lines changed: 2822 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/develop/cpp-sdl/pixi.toml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
[workspace]
2+
channels = ["https://prefix.dev/conda-forge"]
3+
platforms = ["win-64", "linux-64", "osx-64", "osx-arm64"]
4+
preview = ["pixi-build"]
5+
6+
# --------------------------
7+
# Specify that the package in this directory is part of the default environment so we can start developing it.
8+
# --------------------------
9+
[develop]
10+
sdl_example = { path = "." }
11+
12+
# --------------------------
13+
# Tasks to build and run the package
14+
# --------------------------
15+
[tasks.configure]
16+
# Configures CMake
17+
cmd = [
18+
"cmake",
19+
# Use the cross-platform Ninja generator
20+
"-GNinja",
21+
# The source is in the root directory
22+
"-S.",
23+
# We wanna build in the .build directory
24+
"-B.build",
25+
]
26+
inputs = []
27+
outputs = [".build/build.ninja"]
28+
29+
# Build the executable but make sure CMake is configured first.
30+
[tasks.build]
31+
cmd = ["cmake", "--build", ".build"]
32+
depends-on = ["configure"]
33+
inputs = ["CMakeLists.txt", "src/*"]
34+
outputs = [".build/bin/sdl_example*"]
35+
36+
[tasks.start]
37+
cmd = [".build/bin/sdl_example"]
38+
depends-on = ["build"]
39+
40+
# --------------------------
41+
# Package definition
42+
# --------------------------
43+
[package]
44+
authors = ["Bas Zalmstra <[email protected]>"]
45+
description = "Showcases how to create a simple C++ executable with Pixi"
46+
name = "sdl_example"
47+
version = "0.1.0"
48+
49+
[package.build.backend]
50+
channels = [
51+
"https://prefix.dev/pixi-build-backends",
52+
"https://prefix.dev/conda-forge",
53+
]
54+
name = "pixi-build-cmake"
55+
version = "*"
56+
57+
[package.host-dependencies]
58+
# This ensures that SDL2 is available at build time.
59+
sdl2 = ">=2.26.5,<3.0"
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
#include <iostream>
2+
#include <SDL.h>
3+
4+
int main( int argc, char* args[] ) {
5+
if (argc > 1 && std::string(args[1]) == "-h") {
6+
std::cout << "Usage: sdl-example [options]\n"
7+
<< "A simple SDL example that creates a window and draws a square that follows the mouse cursor.\n"
8+
<< "Options:\n"
9+
<< " -h Show this help message\n";
10+
return 0;
11+
}
12+
13+
// Initialize SDL
14+
if( SDL_Init( SDL_INIT_VIDEO ) < 0 )
15+
{
16+
std::cout << "SDL could not initialize! SDL_Error: " << SDL_GetError() << std::endl;
17+
return 1;
18+
}
19+
20+
// Create window
21+
SDL_Window *window = SDL_CreateWindow("Basic Pixi SDL project",
22+
SDL_WINDOWPOS_UNDEFINED,
23+
SDL_WINDOWPOS_UNDEFINED,
24+
800, 600,
25+
SDL_WINDOW_SHOWN);
26+
if(window == nullptr) {
27+
std::cout << "Failed to create SDL window (error" << SDL_GetError() << ")" << std::endl;
28+
SDL_Quit();
29+
return 1;
30+
}
31+
32+
SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
33+
if(renderer == nullptr) {
34+
std::cout << "Failed to create SDL renderer (error" << SDL_GetError() << ")" << std::endl;
35+
SDL_DestroyWindow(window);
36+
SDL_Quit();
37+
return 1;
38+
}
39+
40+
// Declare rect of square
41+
SDL_Rect squareRect;
42+
43+
// Square dimensions: Half of the min(SCREEN_WIDTH, SCREEN_HEIGHT)
44+
squareRect.w = 300;
45+
squareRect.h = 300;
46+
47+
// Event loop exit flag
48+
bool quit = false;
49+
50+
// Event loop
51+
while(!quit)
52+
{
53+
SDL_Event e;
54+
55+
// Wait indefinitely for the next available event
56+
SDL_WaitEvent(&e);
57+
58+
// User requests quit
59+
if(e.type == SDL_QUIT)
60+
{
61+
quit = true;
62+
}
63+
64+
// Get mouse position
65+
int mouseX, mouseY;
66+
SDL_GetMouseState(&mouseX, &mouseY);
67+
68+
// Update square position to follow the mouse cursor
69+
squareRect.x = mouseX - squareRect.w / 2;
70+
squareRect.y = mouseY - squareRect.h / 2;
71+
72+
73+
// Initialize renderer color white for the background
74+
SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xFF, 0xFF);
75+
76+
// Clear screen
77+
SDL_RenderClear(renderer);
78+
79+
// Set renderer color red to draw the square
80+
SDL_SetRenderDrawColor(renderer, 0xFF, 0x00, 0x00, 0xFF);
81+
82+
// Draw a rectangle
83+
SDL_RenderFillRect(renderer, &squareRect);
84+
85+
// Update screen
86+
SDL_RenderPresent(renderer);
87+
}
88+
89+
SDL_DestroyRenderer(renderer);
90+
SDL_DestroyWindow(window);
91+
SDL_Quit();
92+
93+
return 0;
94+
}

schema/model.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,22 @@ class MatchspecTable(StrictBaseModel):
229229
subdirectory: NonEmptyStr | None = Field(None, description="A subdirectory to use in the repo")
230230

231231

232+
class SourceSpecTable(StrictBaseModel):
233+
"""A precise description of a source package location."""
234+
235+
path: NonEmptyStr | None = Field(None, description="The path to the source package")
236+
237+
url: NonEmptyStr | None = Field(None, description="The URL to the source package")
238+
md5: Md5Sum | None = Field(None, description="The md5 hash of the source package")
239+
sha256: Sha256Sum | None = Field(None, description="The sha256 hash of the source package")
240+
241+
git: NonEmptyStr | None = Field(None, description="The git URL to the source repo")
242+
rev: NonEmptyStr | None = Field(None, description="A git SHA revision to use")
243+
tag: NonEmptyStr | None = Field(None, description="A git tag to use")
244+
branch: NonEmptyStr | None = Field(None, description="A git branch to use")
245+
subdirectory: NonEmptyStr | None = Field(None, description="A subdirectory to use in the repo")
246+
247+
232248
MatchSpec = NonEmptyStr | MatchspecTable
233249
CondaPackageName = NonEmptyStr
234250

@@ -499,6 +515,9 @@ class Target(StrictBaseModel):
499515
pypi_dependencies: dict[PyPIPackageName, PyPIRequirement] | None = Field(
500516
None, description="The PyPI dependencies for this target"
501517
)
518+
develop: dict[CondaPackageName, SourceSpecTable] | None = Field(
519+
None, description="Source packages whose dependencies should be installed without building the package itself. Useful for development environments."
520+
)
502521
tasks: dict[TaskName, TaskInlineTable | list[DependsOn] | NonEmptyStr] | None = Field(
503522
None, description="The tasks of the target"
504523
)
@@ -534,6 +553,9 @@ class Feature(StrictBaseModel):
534553
pypi_dependencies: dict[PyPIPackageName, PyPIRequirement] | None = Field(
535554
None, description="The PyPI dependencies of this feature"
536555
)
556+
develop: dict[CondaPackageName, SourceSpecTable] | None = Field(
557+
None, description="Source packages whose dependencies should be installed without building the package itself. Useful for development environments."
558+
)
537559
tasks: dict[TaskName, TaskInlineTable | list[DependsOn] | NonEmptyStr] | None = Field(
538560
None, description="The tasks provided by this feature"
539561
)
@@ -807,6 +829,9 @@ class BaseManifest(StrictBaseModel):
807829
pypi_dependencies: dict[PyPIPackageName, PyPIRequirement] | None = Field(
808830
None, description="The PyPI dependencies"
809831
)
832+
develop: dict[CondaPackageName, SourceSpecTable] | None = Field(
833+
None, description="Source packages whose dependencies should be installed without building the package itself. Useful for development environments."
834+
)
810835
tasks: dict[TaskName, TaskInlineTable | list[DependsOn] | NonEmptyStr] | None = Field(
811836
None, description="The tasks of the project"
812837
)

schema/schema.json

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,17 @@
5555
"minLength": 1
5656
}
5757
},
58+
"develop": {
59+
"title": "Develop",
60+
"description": "Source packages whose dependencies should be installed without building the package itself. Useful for development environments.",
61+
"type": "object",
62+
"additionalProperties": {
63+
"$ref": "#/$defs/SourceSpecTable"
64+
},
65+
"propertyNames": {
66+
"minLength": 1
67+
}
68+
},
5869
"environments": {
5970
"title": "Environments",
6071
"description": "The environments of the project, defined as a full object or a list of feature names.",
@@ -730,6 +741,17 @@
730741
"minLength": 1
731742
}
732743
},
744+
"develop": {
745+
"title": "Develop",
746+
"description": "Source packages whose dependencies should be installed without building the package itself. Useful for development environments.",
747+
"type": "object",
748+
"additionalProperties": {
749+
"$ref": "#/$defs/SourceSpecTable"
750+
},
751+
"propertyNames": {
752+
"minLength": 1
753+
}
754+
},
733755
"host-dependencies": {
734756
"title": "Host-Dependencies",
735757
"description": "The host `conda` dependencies, used in the build process. See https://pixi.sh/latest/build/dependency_types/ for more information.",
@@ -1710,6 +1732,68 @@
17101732
}
17111733
}
17121734
},
1735+
"SourceSpecTable": {
1736+
"title": "SourceSpecTable",
1737+
"description": "A precise description of a source package location.",
1738+
"type": "object",
1739+
"additionalProperties": false,
1740+
"properties": {
1741+
"branch": {
1742+
"title": "Branch",
1743+
"description": "A git branch to use",
1744+
"type": "string",
1745+
"minLength": 1
1746+
},
1747+
"git": {
1748+
"title": "Git",
1749+
"description": "The git URL to the source repo",
1750+
"type": "string",
1751+
"minLength": 1
1752+
},
1753+
"md5": {
1754+
"title": "Md5",
1755+
"description": "The md5 hash of the source package",
1756+
"type": "string",
1757+
"pattern": "^[a-fA-F0-9]{32}$"
1758+
},
1759+
"path": {
1760+
"title": "Path",
1761+
"description": "The path to the source package",
1762+
"type": "string",
1763+
"minLength": 1
1764+
},
1765+
"rev": {
1766+
"title": "Rev",
1767+
"description": "A git SHA revision to use",
1768+
"type": "string",
1769+
"minLength": 1
1770+
},
1771+
"sha256": {
1772+
"title": "Sha256",
1773+
"description": "The sha256 hash of the source package",
1774+
"type": "string",
1775+
"pattern": "^[a-fA-F0-9]{64}$"
1776+
},
1777+
"subdirectory": {
1778+
"title": "Subdirectory",
1779+
"description": "A subdirectory to use in the repo",
1780+
"type": "string",
1781+
"minLength": 1
1782+
},
1783+
"tag": {
1784+
"title": "Tag",
1785+
"description": "A git tag to use",
1786+
"type": "string",
1787+
"minLength": 1
1788+
},
1789+
"url": {
1790+
"title": "Url",
1791+
"description": "The URL to the source package",
1792+
"type": "string",
1793+
"minLength": 1
1794+
}
1795+
}
1796+
},
17131797
"SystemRequirements": {
17141798
"title": "SystemRequirements",
17151799
"description": "Platform-specific requirements",
@@ -1845,6 +1929,17 @@
18451929
"minLength": 1
18461930
}
18471931
},
1932+
"develop": {
1933+
"title": "Develop",
1934+
"description": "Source packages whose dependencies should be installed without building the package itself. Useful for development environments.",
1935+
"type": "object",
1936+
"additionalProperties": {
1937+
"$ref": "#/$defs/SourceSpecTable"
1938+
},
1939+
"propertyNames": {
1940+
"minLength": 1
1941+
}
1942+
},
18481943
"host-dependencies": {
18491944
"title": "Host-Dependencies",
18501945
"description": "The host `conda` dependencies, used in the build process. See https://pixi.sh/latest/build/dependency_types/ for more information.",

0 commit comments

Comments
 (0)