Skip to content

Commit

Permalink
Merge remote-tracking branch 'gitorigin/main' into fix-canvas-type
Browse files Browse the repository at this point in the history
  • Loading branch information
Erik Corry committed Nov 1, 2023
2 parents 245e8e6 + d7b8730 commit d5be32b
Show file tree
Hide file tree
Showing 84 changed files with 1,123 additions and 415 deletions.
97 changes: 97 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
name: CI

on:
push:
release:
types: [published]

jobs:
build:
strategy:
matrix:
# Zlib in Toit is not available on these platforms yet.
os: [ ubuntu-latest, windows-latest, macos-latest ]

runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v3
with:
submodules: recursive

- name: Setup constants
shell: bash
run: |
TOIT_VERSION=v2.0.0-alpha.107
echo "TOIT_VERSION=$TOIT_VERSION" >> $GITHUB_ENV
export DOWNLOAD_DIR="${{ github.workspace }}/downloads"
echo "DOWNLOAD_DIR=$DOWNLOAD_DIR" >> $GITHUB_ENV
if [[ "$RUNNER_OS" = "Linux" ]]; then
TOIT_FILE=toit-linux.tar.gz
echo "TOIT_EXEC=$DOWNLOAD_DIR/toit/bin/toit.run" >> $GITHUB_ENV
echo "TPKG_EXEC=$DOWNLOAD_DIR/toit/bin/toit.pkg" >> $GITHUB_ENV
elif [[ "$RUNNER_OS" = "macOS" ]]; then
TOIT_FILE=toit-macos.tar.gz
echo "TOIT_EXEC=$DOWNLOAD_DIR/toit/bin/toit.run" >> $GITHUB_ENV
echo "TPKG_EXEC=$DOWNLOAD_DIR/toit/bin/toit.pkg" >> $GITHUB_ENV
elif [[ "$RUNNER_OS" = "Windows" ]]; then
TOIT_FILE=toit-windows.tar.gz
echo "TOIT_EXEC=$DOWNLOAD_DIR/toit/bin/toit.run.exe" >> $GITHUB_ENV
echo "TPKG_EXEC=$DOWNLOAD_DIR/toit/bin/toit.pkg.exe" >> $GITHUB_ENV
else
echo "UNSUPPORTED RUNNER: $RUNNER_OS"
exit 1
fi
if [[ $TOIT_VERSION = latest ]]; then
echo "TOIT_URL=https://github.com/toitlang/toit/releases/latest/download/$TOIT_FILE" >> $GITHUB_ENV
else
echo "TOIT_URL=https://github.com/toitlang/toit/releases/download/$TOIT_VERSION/$TOIT_FILE" >> $GITHUB_ENV
fi
# Fetch the dependencies. Different for each platform.
- name: Install dependencies - Linux
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install ninja-build
ninja --version
cmake --version
- name: Install dependencies - macOS
if: runner.os == 'macOS'
run: |
brew install ninja
ninja --version
cmake --version
- name: Install dependencies - Windows
if: runner.os == 'Windows'
run: |
choco install ninja
ninja --version
cmake --version
- uses: suisei-cn/[email protected]
name: Download Toit
with:
url: ${{ env.TOIT_URL }}
target: ${{ env.DOWNLOAD_DIR }}

- name: Extract Toit
shell: bash
run: |
cd "$DOWNLOAD_DIR"
tar x -f *.tar.gz
- name: Run cmake
shell: bash
run: |
make rebuild-cmake
cmake "-DTOIT_EXEC=$TOIT_EXEC" "-DTPKG_EXEC=$TPKG_EXEC" build
- name: Install packages
run: |
make install-pkgs
- name: Test
run: |
make test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
*.swp
*.swo
.packages
10 changes: 10 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Copyright (C) 2023 Toitware ApS.
# Use of this source code is governed by a Zero-Clause BSD license that can
# be found in the tests/TESTS_LICENSE file.

cmake_minimum_required(VERSION 3.22)

project(cli)

enable_testing()
add_subdirectory(tests)
25 changes: 25 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright (C) 2023 Toitware ApS.
# Use of this source code is governed by a Zero-Clause BSD license that can
# be found in the tests/LICENSE file.

all: test

.PHONY: build/host/CMakeCache.txt
build/CMakeCache.txt:
$(MAKE) rebuild-cmake

install-pkgs: rebuild-cmake
(cd build && ninja install-pkgs)

test: install-pkgs rebuild-cmake
(cd build && ninja check)

# We rebuild the cmake file all the time.
# We use "glob" in the cmakefile, and wouldn't otherwise notice if a new
# file (for example a test) was added or removed.
# It takes <1s on Linux to run cmake, so it doesn't hurt to run it frequently.
rebuild-cmake:
mkdir -p build
(cd build && cmake .. -G Ninja)

.PHONY: all test rebuild-cmake install-pkgs
3 changes: 0 additions & 3 deletions src/four_gray.toit
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ BLACK ::= 3
// 1 0 Dark gray
// 1 1 Black
// Starts off with all pixels white.
class InfiniteBackground extends TwoBitInfiniteBackground_:
constructor color:
super color
class FilledRectangle extends TwoBitFilledRectangle_:
constructor color x/int y/int w/int h/int transform/Transform:
Expand Down
4 changes: 0 additions & 4 deletions src/gray_scale.toit
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ class Canvas extends OneByteCanvas_:
create_similar:
return Canvas width_ height_ x_offset_ y_offset_

class InfiniteBackground extends OneByteInfiniteBackground_:
constructor color/int:
super color

class FilledRectangle extends OneByteFilledRectangle_:
constructor color/int x/int y/int w/int h/int transform/Transform:
super color x y w h transform
Expand Down
20 changes: 2 additions & 18 deletions src/one_byte.toit
Original file line number Diff line number Diff line change
Expand Up @@ -21,31 +21,15 @@ abstract class OneByteCanvas_ extends AbstractCanvas:
pixels_ = ByteArray size
super width height x_offset y_offset

set_all_pixels color:
set_all_pixels color/int -> none:
bytemap_zap pixels_ color

set_pixel color x y:
pixels_[x + width_ * y] = color

get_pixel x y:
get_pixel_ x y:
return pixels_[x + width_ * y]

composit frame_opacity frame_canvas/OneByteCanvas_? painting_opacity painting_canvas/OneByteCanvas_:
composit_bytes pixels_ frame_opacity (frame_canvas ? frame_canvas.pixels_ : null) painting_opacity painting_canvas.pixels_ false

class OneByteInfiniteBackground_ extends InfiniteBackground_:
color_ := 0

constructor .color_:

color -> int:
return color_

write canvas/OneByteCanvas_:
bytemap_zap canvas.pixels_ color_

write_ canvas/OneByteCanvas_:
throw "Not used"

class OneByteFilledRectangle_ extends FilledRectangle_:
color_ := ?
Expand Down
Loading

0 comments on commit d5be32b

Please sign in to comment.