Skip to content

Commit

Permalink
Compile files for NSP generation with hacbrewpack (#93)
Browse files Browse the repository at this point in the history
Closes #91.
  • Loading branch information
TooTallNate authored Feb 15, 2024
1 parent 3ac5b4d commit a2258b3
Show file tree
Hide file tree
Showing 50 changed files with 575 additions and 93 deletions.
1 change: 1 addition & 0 deletions .changeset/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"fixed": [
[
"@nx.js/nro",
"@nx.js/nsp",
"create-nxjs-app",
"nxjs-runtime"
]
Expand Down
5 changes: 5 additions & 0 deletions .changeset/tidy-timers-begin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@nx.js/nsp': patch
---

Add `@nx.js/nsp` package
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ jobs:
- name: Copy `nxjs.nro` to "@nx.js/nro"
run: cp -v nxjs.nro packages/nro/dist

- name: Copy files to "@nx.js/nsp"
run: cp -rv build/exefs nxjs.nacp icon.jpg packages/nsp

- name: Create Release Pull Request or Publish to npm
id: changesets
uses: changesets/action@v1
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ node_modules
/lib/*/lib
/lib/*/debug
/lib/*/release
/hacbrewpack_*
/exefs
/control

/nxjs.*
!/nxjs.jpg
Expand Down
67 changes: 29 additions & 38 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ include $(DEVKITPRO)/libnx/switch_rules
# SOURCES is a list of directories containing source code
# DATA is a list of directories containing data files
# INCLUDES is a list of directories containing header files
# EXEFS_SRC is the optional input directory containing data copied into exefs, if anything this normally should only contain "main.npdm".
# ROMFS is the directory containing data to be added to RomFS, relative to the Makefile (Optional)
#
# NO_ICON: if set to anything, do not use icon.
Expand All @@ -28,25 +29,21 @@ include $(DEVKITPRO)/libnx/switch_rules
# - <Project name>.jpg
# - icon.jpg
# - <libnx folder>/default_icon.jpg
#
# CONFIG_JSON is the filename of the NPDM config file (.json), relative to the project folder.
# If not set, it attempts to use one of the following (in this order):
# - <Project name>.json
# - config.json
# If a JSON file is provided or autodetected, an ExeFS PFS0 (.nsp) is built instead
# of a homebrew executable (.nro). This is intended to be used for sysmodules.
# NACP building is skipped as well.
#---------------------------------------------------------------------------------

APP_TITLE := nx.js
APP_TITLEID := 016e782e6a730000 # 6e782e6a73 is "nx.js" in hex 😉
APP_AUTHOR := TooTallNate
APP_VERSION := `jq -r .version < ../packages/runtime/package.json`

TARGET := nxjs
BUILD := build
SOURCES := source
DATA := data
INCLUDES := include
EXEFS_SRC := exefs_src
ROMFS := romfs
CONFIG_JSON := npdm.json

#---------------------------------------------------------------------------------
# options for code generation
Expand All @@ -58,10 +55,10 @@ CFLAGS := -g -Wall -O2 -ffunction-sections \

CFLAGS += $(INCLUDE) -D__SWITCH__ `freetype-config --cflags` `aarch64-none-elf-pkg-config cairo --cflags`

CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions

ASFLAGS := -g $(ARCH)
LDFLAGS = -specs=$(DEVKITPRO)/libnx/switch.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
LDFLAGS = -specs=${DEVKITPRO}/libnx/switch.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)

LIBS := -pthread -lmbedtls -lmbedx509 -lmbedcrypto -lharfbuzz `freetype-config --libs` `aarch64-none-elf-pkg-config cairo --libs` -lturbojpeg -lwebp -lqjs -lm3 -lm

Expand Down Expand Up @@ -117,18 +114,7 @@ export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \

export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)

ifeq ($(strip $(CONFIG_JSON)),)
jsons := $(wildcard *.json)
ifneq (,$(findstring $(TARGET).json,$(jsons)))
export APP_JSON := $(TOPDIR)/$(TARGET).json
else
ifneq (,$(findstring config.json,$(jsons)))
export APP_JSON := $(TOPDIR)/config.json
endif
endif
else
export APP_JSON := $(TOPDIR)/$(CONFIG_JSON)
endif
export BUILD_EXEFS_SRC := $(TOPDIR)/$(EXEFS_SRC)

ifeq ($(strip $(ICON)),)
icons := $(wildcard *.jpg)
Expand Down Expand Up @@ -159,6 +145,19 @@ ifneq ($(ROMFS),)
export NROFLAGS += --romfsdir=$(CURDIR)/$(ROMFS)
endif

ifeq ($(strip $(CONFIG_JSON)),)
jsons := $(wildcard *.json)
ifneq (,$(findstring $(TARGET).json,$(jsons)))
export APP_JSON := $(TOPDIR)/$(TARGET).json
else
ifneq (,$(findstring config.json,$(jsons)))
export APP_JSON := $(TOPDIR)/config.json
endif
endif
else
export APP_JSON := $(TOPDIR)/$(CONFIG_JSON)
endif

.PHONY: $(BUILD) clean all

#---------------------------------------------------------------------------------
Expand All @@ -171,11 +170,7 @@ $(BUILD):
#---------------------------------------------------------------------------------
clean:
@echo clean ...
ifeq ($(strip $(APP_JSON)),)
@rm -fr $(BUILD) $(TARGET).nro $(TARGET).nacp $(TARGET).elf
else
@rm -fr $(BUILD) $(TARGET).nsp $(TARGET).nso $(TARGET).npdm $(TARGET).elf
endif
@rm -fr $(BUILD) $(TARGET).pfs0 $(TARGET).nso $(TARGET).nro $(TARGET).nacp $(TARGET).elf $(TARGET).npdm


#---------------------------------------------------------------------------------
Expand All @@ -187,26 +182,22 @@ DEPENDS := $(OFILES:.o=.d)
#---------------------------------------------------------------------------------
# main targets
#---------------------------------------------------------------------------------
all : $(OUTPUT).pfs0 $(OUTPUT).nro

ifeq ($(strip $(APP_JSON)),)
$(OUTPUT).pfs0 : $(OUTPUT).nso
else
$(OUTPUT).pfs0 : $(OUTPUT).nso $(OUTPUT).npdm
endif

all : $(OUTPUT).nro
$(OUTPUT).nso : $(OUTPUT).elf

ifeq ($(strip $(NO_NACP)),)
$(OUTPUT).nro : $(OUTPUT).elf $(OUTPUT).nacp
else
$(OUTPUT).nro : $(OUTPUT).elf
endif

else

all : $(OUTPUT).nsp

$(OUTPUT).nsp : $(OUTPUT).nso $(OUTPUT).npdm

$(OUTPUT).nso : $(OUTPUT).elf

endif

$(OUTPUT).elf : $(OFILES)

$(OFILES_SRC) : $(HFILES_BIN)
Expand Down
1 change: 1 addition & 0 deletions apps/2048/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*.nro
/*.nsp
/node_modules
/romfs/main.js
/romfs/main.js.map
6 changes: 4 additions & 2 deletions apps/2048/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@
"description": "nx.js port of the 2048 game",
"scripts": {
"build": "esbuild --bundle --sourcemap --sources-content=false --target=es2022 src/main.js --outfile=romfs/main.js",
"nro": "nxjs-nro"
"nro": "nxjs-nro",
"nsp": "nxjs-nsp"
},
"license": "MIT",
"dependencies": {
"nxjs-constants": "workspace:*"
},
"devDependencies": {
"esbuild": "^0.17.19",
"@nx.js/nro": "workspace:^",
"@nx.js/nsp": "workspace:^",
"esbuild": "^0.17.19",
"nxjs-runtime": "workspace:^"
}
}
1 change: 1 addition & 0 deletions apps/ansi/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*.nro
/*.nsp
/node_modules
/romfs/main.js
/romfs/main.js.map
6 changes: 4 additions & 2 deletions apps/ansi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
"description": "nx.js app with colors and cursor movement using ANSI escapes",
"scripts": {
"build": "esbuild --bundle --sourcemap --sources-content=false --target=es2022 src/main.ts --outfile=romfs/main.js",
"nro": "nxjs-nro"
"nro": "nxjs-nro",
"nsp": "nxjs-nsp"
},
"license": "MIT",
"devDependencies": {
"esbuild": "^0.17.19",
"@nx.js/nro": "workspace:^",
"@nx.js/nsp": "workspace:^",
"esbuild": "^0.17.19",
"nxjs-runtime": "workspace:^"
},
"dependencies": {
Expand Down
1 change: 1 addition & 0 deletions apps/app-launch/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*.nro
/*.nsp
/node_modules
/romfs/main.js
/romfs/main.js.map
6 changes: 4 additions & 2 deletions apps/app-launch/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
"description": "List and launch installed games",
"scripts": {
"build": "esbuild --bundle --sourcemap --sources-content=false --target=es2022 --format=esm src/main.ts --outfile=romfs/main.js",
"nro": "nxjs-nro"
"nro": "nxjs-nro",
"nsp": "nxjs-nsp"
},
"license": "MIT",
"devDependencies": {
"esbuild": "^0.17.19",
"@nx.js/nro": "workspace:^",
"@nx.js/nsp": "workspace:^",
"esbuild": "^0.17.19",
"nxjs-runtime": "workspace:^"
}
}
1 change: 1 addition & 0 deletions apps/battery/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*.nro
/*.nsp
/node_modules
/romfs/main.js
/romfs/main.js.map
6 changes: 4 additions & 2 deletions apps/battery/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
"description": "nx.js app to display the battery charge level",
"scripts": {
"build": "esbuild --bundle --sourcemap --sources-content=false --target=es2022 --format=esm src/main.ts --outfile=romfs/main.js",
"nro": "nxjs-nro"
"nro": "nxjs-nro",
"nsp": "nxjs-nsp"
},
"license": "MIT",
"devDependencies": {
"esbuild": "^0.17.19",
"@nx.js/nro": "workspace:^",
"@nx.js/nsp": "workspace:^",
"esbuild": "^0.17.19",
"nxjs-runtime": "workspace:^"
}
}
1 change: 1 addition & 0 deletions apps/canvas/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*.nro
/*.nsp
/node_modules
/romfs/main.js
/romfs/main.js.map
6 changes: 4 additions & 2 deletions apps/canvas/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
"description": "nx.js app using the web `Canvas` API",
"scripts": {
"build": "esbuild --bundle --sourcemap --sources-content=false --target=es2022 src/main.ts --outfile=romfs/main.js",
"nro": "nxjs-nro"
"nro": "nxjs-nro",
"nsp": "nxjs-nsp"
},
"license": "MIT",
"devDependencies": {
"esbuild": "^0.17.19",
"@nx.js/nro": "workspace:^",
"@nx.js/nsp": "workspace:^",
"esbuild": "^0.17.19",
"nxjs-runtime": "workspace:^"
}
}
1 change: 1 addition & 0 deletions apps/fonts/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*.nro
/*.nsp
/node_modules
/romfs/main.js
/romfs/main.js.map
6 changes: 4 additions & 2 deletions apps/fonts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
"description": "nx.js app using customs fonts",
"scripts": {
"build": "esbuild --bundle --sourcemap --sources-content=false --target=es2022 src/main.ts --outfile=romfs/main.js",
"nro": "nxjs-nro"
"nro": "nxjs-nro",
"nsp": "nxjs-nsp"
},
"license": "MIT",
"devDependencies": {
"esbuild": "^0.17.19",
"@nx.js/nro": "workspace:^",
"@nx.js/nsp": "workspace:^",
"esbuild": "^0.17.19",
"nxjs-runtime": "workspace:^"
}
}
1 change: 1 addition & 0 deletions apps/hello-world/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*.nro
/*.nsp
/node_modules
/romfs/main.js
/romfs/main.js.map
6 changes: 4 additions & 2 deletions apps/hello-world/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
"description": "Simple 'Hello World' nx.js app",
"scripts": {
"build": "esbuild --bundle --sourcemap --sources-content=false --target=es2022 --format=esm src/main.ts --outfile=romfs/main.js",
"nro": "nxjs-nro"
"nro": "nxjs-nro",
"nsp": "nxjs-nsp"
},
"license": "MIT",
"devDependencies": {
"esbuild": "^0.17.19",
"@nx.js/nro": "workspace:^",
"@nx.js/nsp": "workspace:^",
"esbuild": "^0.17.19",
"nxjs-runtime": "workspace:^"
}
}
1 change: 1 addition & 0 deletions apps/repl-server/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*.nro
/*.nsp
/node_modules
/romfs/main.js
/romfs/main.js.map
6 changes: 4 additions & 2 deletions apps/repl-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@
"description": "nx.js REPL (read-eval-print-loop) app accessed over TCP",
"scripts": {
"build": "esbuild --bundle --sourcemap --sources-content=false --target=es2022 --format=esm src/main.ts --outfile=romfs/main.js",
"nro": "nxjs-nro"
"nro": "nxjs-nro",
"nsp": "nxjs-nsp"
},
"license": "MIT",
"dependencies": {
"@nx.js/repl": "workspace:^",
"sisteransi": "^1.0.5"
},
"devDependencies": {
"esbuild": "^0.17.19",
"@nx.js/nro": "workspace:^",
"@nx.js/nsp": "workspace:^",
"esbuild": "^0.17.19",
"nxjs-runtime": "workspace:^"
}
}
1 change: 1 addition & 0 deletions apps/repl/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*.nro
/*.nsp
/node_modules
/romfs/main.js
/romfs/main.js.map
6 changes: 4 additions & 2 deletions apps/repl/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@
"description": "nx.js REPL (read-eval-print-loop) app",
"scripts": {
"build": "esbuild --bundle --sourcemap --sources-content=false --target=es2022 src/main.ts --outfile=romfs/main.js",
"nro": "nxjs-nro"
"nro": "nxjs-nro",
"nsp": "nxjs-nsp"
},
"license": "MIT",
"dependencies": {
"kleur": "^4.1.5",
"sisteransi": "^1.0.5"
},
"devDependencies": {
"esbuild": "^0.17.19",
"@nx.js/nro": "workspace:^",
"@nx.js/nsp": "workspace:^",
"esbuild": "^0.17.19",
"nxjs-runtime": "workspace:^"
}
}
1 change: 1 addition & 0 deletions apps/snake/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*.nro
/*.nsp
/node_modules
/romfs/main.js
/romfs/main.js.map
Loading

0 comments on commit a2258b3

Please sign in to comment.