Skip to content

Commit

Permalink
edit_homo
Browse files Browse the repository at this point in the history
  • Loading branch information
Misakatri committed Nov 2, 2023
1 parent a98e1b6 commit 23742bf
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 57 deletions.
119 changes: 70 additions & 49 deletions build.zig
Original file line number Diff line number Diff line change
@@ -1,50 +1,61 @@
const std = @import("std");
const log = std.debug.print;

pub fn build(b: *std.build.Builder) void {
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const mode = b.standardReleaseOptions();
const optimize = b.standardOptimizeOption(.{});

const quickjs = b.addStaticLibrary("quickjs", "src/dummy.zig");
quickjs.addIncludePath("clib/quickjs");
const quickjs = b.addStaticLibrary(.{
.name = "quickjs",
.root_source_file = .{ .path = "src/dummy.zig" },
.target = target,
.optimize = optimize,
});
quickjs.addIncludePath(.{ .path = "clib/quickjs" });
quickjs.disable_sanitize_c = true;
quickjs.addCSourceFiles(&.{
"clib/quickjs/cutils.c",
"clib/quickjs/libbf.c",
"clib/quickjs/libunicode.c",
"clib/quickjs/quickjs-libc.c",
"clib/quickjs/quickjs.c",
"clib/quickjs/libregexp.c",
}, &.{
"-g",
"-Wall",
"-D_GNU_SOURCE",
"-DCONFIG_VERSION=\"2021-03-27\"",
"-DCONFIG_BIGNUM",

quickjs.addCSourceFiles(.{
.files = &.{
"clib/quickjs/cutils.c",
"clib/quickjs/libbf.c",
"clib/quickjs/libunicode.c",
"clib/quickjs/quickjs-libc.c",
"clib/quickjs/quickjs.c",
"clib/quickjs/libregexp.c",
},
.flags = &.{
"-g",
"-Wall",
"-D_GNU_SOURCE",
"-DCONFIG_VERSION=\"2021-03-27\"",
"-DCONFIG_BIGNUM",
},
});

quickjs.linkLibC();
quickjs.install();
quickjs.setTarget(target);
quickjs.setBuildMode(mode);

const exe = b.addExecutable("fre", "src/main.zig");
exe.setTarget(target);
exe.setBuildMode(mode);
exe.addIncludePath("clib/quickjs");
b.installArtifact(quickjs);

const exe = b.addExecutable(.{
.name = "fre",
.root_source_file = .{ .path = "src/main.zig" },
.target = target,
.optimize = optimize,
});
exe.addIncludePath(.{ .path = "clib/quickjs" });
exe.linkLibC();
exe.linkLibrary(quickjs);
exe.install();
b.installArtifact(exe);

if (target.getOsTag() == .windows) {
quickjs.addIncludePath("clib/mingw-w64-winpthreads/include");
exe.addObjectFile("clib/mingw-w64-winpthreads/lib/libpthread.a");
quickjs.addIncludePath(.{ .path = "clib/mingw-w64-winpthreads/include" });
exe.addObjectFile(.{ .path = "clib/mingw-w64-winpthreads/lib/libpthread.a" });
}

// init lvgl
exe.linkLibC();

exe.addIncludePath("./clib/lvgl");
exe.addIncludePath("./clib/lvgl_drv");
exe.addIncludePath(.{ .path = "./clib/lvgl" });
exe.addIncludePath(.{ .path = "./clib/lvgl_drv" });

const cflags = [_][]const u8{
// TODO:
Expand Down Expand Up @@ -152,31 +163,31 @@ pub fn build(b: *std.build.Builder) void {
"clib/lvgl/src/font/lv_font.c",
"clib/lvgl/src/font/lv_font_fmt_txt.c",
"clib/lvgl/src/font/lv_font_montserrat_14.c",

// lvgl_drv
"clib/lvgl_drv/lv_sdl_disp.c",
"clib/lvgl_drv/lv_port_indev.c",
"clib/lvgl_drv/lv_xbox_disp.c",

};
exe.addCSourceFiles(&lvgl_source_files, &cflags);
exe.addCSourceFiles(.{
.files = &lvgl_source_files,
.flags = &cflags,
});

// init sdl


if ( target.getOsTag() == .macos and
target.getCpuArch().isAARCH64() ) {

if (target.getOsTag() == .macos and
target.getCpuArch().isAARCH64())
{
const homebrew_path = "/opt/homebrew";
exe.addIncludePath(homebrew_path ++ "/include/SDL2");
exe.addLibraryPath(homebrew_path ++ "/lib");
exe.addIncludePath(.{ .path = homebrew_path ++ "/include/SDL2" });
exe.addLibraryPath(.{ .path = homebrew_path ++ "/lib" });

exe.linkSystemLibrary("SDL2");
}
else {
const sdl_path = "D:\\SDL2-2.0.14\\";
exe.addIncludePath(sdl_path ++ "include");
exe.addLibraryPath(sdl_path ++ "lib\\x64");
} else {
const sdl_path = "D:\\SDL2_2.28.4\\x86_64-w64-mingw32\\";
exe.addIncludePath(.{ .path = sdl_path ++ "include" });
exe.addLibraryPath(.{ .path = sdl_path ++ "lib\\x64" });
b.installBinFile(sdl_path ++ "lib\\x64\\SDL2.dll", "SDL2.dll");
b.installBinFile(sdl_path ++ "lib\\x64\\SDL2_image.dll", "SDL2_image.dll");
b.installBinFile(sdl_path ++ "lib\\x64\\SDL2_ttf.dll", "SDL2_ttf.dll");
Expand All @@ -185,21 +196,31 @@ pub fn build(b: *std.build.Builder) void {
exe.linkSystemLibrary("sdl2_ttf");
}


// This line of code specifies the subsystem of the executable as Windows.
// exe.subsystem = .Windows;

exe.linkLibC();

const run_cmd = exe.run();
const run_cmd = b.addRunArtifact(exe);

run_cmd.step.dependOn(b.getInstallStep());

if (b.args) |args| {
run_cmd.addArgs(args);
}

const run_step = b.step("run", "Run the app");
run_step.dependOn(&run_cmd.step);

const exe_tests = b.addTest("src/main.zig");
exe_tests.setTarget(target);
exe_tests.setBuildMode(mode);
const unit_tests = b.addTest(.{
.root_source_file = .{ .path = "src/main.zig" },
.target = target,
.optimize = optimize,
});

const run_unit_tests = b.addRunArtifact(unit_tests);

const test_step = b.step("test", "Run unit tests");
test_step.dependOn(&exe_tests.step);
test_step.dependOn(&run_unit_tests.step);
}
6 changes: 4 additions & 2 deletions clib/lvgl_drv/lv_port_indev.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
#include "lv_port_indev.h"
#include "lvgl.h"
#ifdef NXDK
#include "SDL.h"
#include "SDL2/SDL.h"
#else
#include "SDL.h"
#include "SDL2/SDL.h"
#endif

// C/C++

static lv_indev_drv_t indev_drv_gamepad;
static lv_indev_drv_t indev_drv_mouse;
static lv_indev_t *indev_mouse;
Expand Down
4 changes: 2 additions & 2 deletions clib/lvgl_drv/lv_port_indev.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ extern "C" {
#include "lvgl.h"
#include "lvgl.h"
#ifdef NXDK
#include "SDL.h"
#include "SDL2/SDL.h"
#else
#include "SDL.h"
#include "SDL2/SDL.h"
#endif

/*********************
Expand Down
2 changes: 1 addition & 1 deletion clib/lvgl_drv/lv_sdl_disp.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//SPDX-License-Identifier: MIT

#include <assert.h>
#include "SDL.h"
#include "SDL2/SDL.h"
#include "lv_port_disp.h"
#include "lvgl.h"

Expand Down
4 changes: 2 additions & 2 deletions src/component/text.zig
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ pub fn drawFont(text: []const u8, x: i32, y: i32) void {

const font_file = @embedFile("../asset/Sans.ttf");
const font_rw = sdl.SDL_RWFromConstMem(
@ptrCast(*const anyopaque, &font_file[0]),
@intCast(c_int, font_file.len),
@as(*const anyopaque,@ptrCast(&font_file[0])),
@as(c_int, @intCast(font_file.len)),
);
defer std.debug.assert(sdl.SDL_RWclose(font_rw) == 0);

Expand Down
2 changes: 1 addition & 1 deletion src/lv.zig
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub fn runLvgl() void {

var lastTick: i64 = std.time.milliTimestamp();
while (true) {
lv.lv_tick_inc(@intCast(u32, std.time.milliTimestamp() - lastTick));
lv.lv_tick_inc(@as(u32, @intCast(std.time.milliTimestamp() - lastTick)));
lastTick = std.time.milliTimestamp();
_=lv.lv_task_handler();
}
Expand Down

0 comments on commit 23742bf

Please sign in to comment.