diff --git a/.gitignore b/.gitignore index fc9dc57cd4..80fbb01a00 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,7 @@ /src/ifcmax/out/ /src/ifcwrap/out/ /src/qtviewer/out/ +/src/ifctester/webapp/public/pyodide/ /win/BuildDepsCache*.txt diff --git a/src/common.mk b/src/common.mk index 24537d06de..765655339b 100644 --- a/src/common.mk +++ b/src/common.mk @@ -28,6 +28,7 @@ dist: mkdir -p dist cp -r $(PACKAGE_NAME) build/ cp pyproject.toml build/ + if [ -f README.md ]; then cp README.md build/; fi ifeq ($(IS_STABLE), TRUE) $(SED) 's/version = "0.0.0"/version = "$(VERSION)"/' build/pyproject.toml ifdef IS_MODULE diff --git a/src/ifctester/Makefile b/src/ifctester/Makefile index 63ce7bc311..71ecbd48d7 100644 --- a/src/ifctester/Makefile +++ b/src/ifctester/Makefile @@ -25,9 +25,19 @@ WEBAPP_BUILD_DIR := $(WEBAPP_DIR)/dist PYODIDE_DIR := $(WEBAPP_DIR)/public/pyodide PYODIDE_VERSION := 0.28.0 PYODIDE_URL := https://github.com/pyodide/pyodide/releases/download/$(PYODIDE_VERSION)/pyodide-$(PYODIDE_VERSION).tar.bz2 +WORKER_BIN_DIR := $(WEBAPP_DIR)/public/worker/bin +IFCOPENSHELL_WASM_WHEEL := ifcopenshell-0.8.5+a51b2c5-cp313-cp313-pyodide_2025_0_wasm32.whl +IFCOPENSHELL_WASM_WHEEL_URL := https://s3.amazonaws.com/ifcopenshell-builds/ifcopenshell-0.8.5%2Ba51b2c5-cp313-cp313-pyodide_2025_0_wasm32.whl +IFCOPENSHELL_WASM_WHEEL_PATH := $(WORKER_BIN_DIR)/$(IFCOPENSHELL_WASM_WHEEL) +WEBAPP_GENERATED_DIR := $(WEBAPP_DIR)/public/worker/generated +WEBAPP_IFCTESTER_MANIFEST := $(WEBAPP_GENERATED_DIR)/ifctester.json +WEBAPP_IFCTESTER_BUILD_DIR := build-webapp-wheel +PACKAGE_WEBAPP_DIR := $(PACKAGE_NAME)/webapp +PACKAGE_WEBAPP_WWW_DIR := $(PACKAGE_WEBAPP_DIR)/www .PHONY: webapp-dev -webapp-dev: +webapp-dev: pyodide-download ifcopenshell-wasm-download webapp-stage-ifctester-wheel + cd $(WEBAPP_DIR) && npm install cd $(WEBAPP_DIR) && npm run dev .PHONY: pyodide-download @@ -62,8 +72,43 @@ pyodide-download: echo "Pyodide $(PYODIDE_VERSION) prepared in $(PYODIDE_DIR)"; \ fi +.PHONY: ifcopenshell-wasm-download +ifcopenshell-wasm-download: + @if [ -f "$(IFCOPENSHELL_WASM_WHEEL_PATH)" ]; then \ + echo "IfcOpenShell wasm wheel already exists at $(IFCOPENSHELL_WASM_WHEEL_PATH), skipping download"; \ + else \ + echo "Downloading IfcOpenShell wasm wheel..."; \ + mkdir -p $(WORKER_BIN_DIR); \ + rm -f $(WORKER_BIN_DIR)/ifcopenshell-*.whl; \ + curl -fL -o "$(IFCOPENSHELL_WASM_WHEEL_PATH)" "$(IFCOPENSHELL_WASM_WHEEL_URL)"; \ + echo "IfcOpenShell wasm wheel prepared at $(IFCOPENSHELL_WASM_WHEEL_PATH)"; \ + fi + +.PHONY: webapp-stage-ifctester-wheel +webapp-stage-ifctester-wheel: + rm -rf $(WEBAPP_GENERATED_DIR) + rm -rf $(WEBAPP_IFCTESTER_BUILD_DIR) + mkdir -p $(WEBAPP_IFCTESTER_BUILD_DIR) + cp -r $(PACKAGE_NAME) $(WEBAPP_IFCTESTER_BUILD_DIR)/ + rm -rf $(WEBAPP_IFCTESTER_BUILD_DIR)/$(PACKAGE_NAME)/webapp + cp pyproject.toml $(WEBAPP_IFCTESTER_BUILD_DIR)/ + cp README.md $(WEBAPP_IFCTESTER_BUILD_DIR)/ +ifeq ($(IS_STABLE), TRUE) + $(SED) 's/version = "0.0.0"/version = "$(VERSION)"/' $(WEBAPP_IFCTESTER_BUILD_DIR)/pyproject.toml + $(SED) 's/version = "0.0.0"/version = "$(VERSION)"/' $(WEBAPP_IFCTESTER_BUILD_DIR)/$(PACKAGE_NAME)/__init__.py +else + $(SED) 's/version = "0.0.0"/version = "$(VERSION)a$(VERSION_DATE)"/' $(WEBAPP_IFCTESTER_BUILD_DIR)/pyproject.toml + $(SED) 's/version = "0.0.0"/version = "$(VERSION)-alpha$(VERSION_DATE)"/' $(WEBAPP_IFCTESTER_BUILD_DIR)/$(PACKAGE_NAME)/__init__.py +endif + cd $(WEBAPP_IFCTESTER_BUILD_DIR) && $(PYTHON) -m venv env --system-site-packages && . env/$(VENV_ACTIVATE) && python -m pip install build && python -m build --wheel --no-isolation + mkdir -p $(WEBAPP_GENERATED_DIR) + wheel=$$(basename $(WEBAPP_IFCTESTER_BUILD_DIR)/dist/$(PACKAGE_NAME)-*.whl); \ + cp "$(WEBAPP_IFCTESTER_BUILD_DIR)/dist/$$wheel" "$(WEBAPP_GENERATED_DIR)/$$wheel"; \ + printf '{\n "wheel_url": "/worker/generated/%s"\n}\n' "$$wheel" > "$(WEBAPP_IFCTESTER_MANIFEST)" + rm -rf $(WEBAPP_IFCTESTER_BUILD_DIR) + .PHONY: webapp-build -webapp-build: pyodide-download +webapp-build: pyodide-download ifcopenshell-wasm-download webapp-stage-ifctester-wheel cd $(WEBAPP_DIR) && npm install cd $(WEBAPP_DIR) && npm run build @@ -76,22 +121,30 @@ clean: rm -rf $(WEBAPP_BUILD_DIR) rm -rf $(WEBAPP_DIR)/node_modules rm -rf $(PYODIDE_DIR) + rm -f $(WORKER_BIN_DIR)/ifcopenshell-*.whl + rm -rf $(WEBAPP_GENERATED_DIR) + rm -rf $(WEBAPP_IFCTESTER_BUILD_DIR) rm -rf $(PACKAGE_NAME)/webapp rm -rf dist -.PHONY: dist -dist: webapp-prepare +.PHONY: python-dist +python-dist: + rm -rf dist # For some reason OS is not initalized when we call common.mk dist, which matters on Windows. # So we pass it explicitly. - $(MAKE) -f ../common.mk dist PACKAGE_NAME=$(PACKAGE_NAME) OS=$(OS) + $(MAKE) -f ../common.mk dist PACKAGE_NAME=$(PACKAGE_NAME) OS=$(OS) IS_STABLE=$(IS_STABLE) + +.PHONY: dist +dist: webapp-prepare + $(MAKE) python-dist OS=$(OS) IS_STABLE=$(IS_STABLE) .PHONY: webapp-prepare webapp-prepare: webapp-build - rm -rf $(PACKAGE_NAME)/webapp/www/* - mkdir -p $(PACKAGE_NAME)/webapp/www - cp -r $(WEBAPP_BUILD_DIR)/* $(PACKAGE_NAME)/webapp/www/ - cp $(WEBAPP_DIR)/__init__.py $(PACKAGE_NAME)/webapp/__init__.py - cp $(WEBAPP_DIR)/serve.py $(PACKAGE_NAME)/webapp/serve.py + rm -rf $(PACKAGE_WEBAPP_WWW_DIR) + mkdir -p $(PACKAGE_WEBAPP_WWW_DIR) + cp -r $(WEBAPP_BUILD_DIR)/* $(PACKAGE_WEBAPP_WWW_DIR)/ + cp $(WEBAPP_DIR)/__init__.py $(PACKAGE_WEBAPP_DIR)/__init__.py + cp $(WEBAPP_DIR)/serve.py $(PACKAGE_WEBAPP_DIR)/serve.py .PHONY: test test: diff --git a/src/ifctester/webapp/.gitignore b/src/ifctester/webapp/.gitignore index 4205867691..f7daf321ef 100644 --- a/src/ifctester/webapp/.gitignore +++ b/src/ifctester/webapp/.gitignore @@ -11,6 +11,8 @@ node_modules dist dist-ssr *.local +public/worker/bin/ifcopenshell-*.whl +public/worker/generated # Editor directories and files .vscode/* @@ -24,4 +26,4 @@ dist-ssr *.sw? .claude -experiment/* \ No newline at end of file +experiment/* diff --git a/src/ifctester/webapp/biome.json b/src/ifctester/webapp/biome.json new file mode 100644 index 0000000000..ce01c80c3f --- /dev/null +++ b/src/ifctester/webapp/biome.json @@ -0,0 +1,31 @@ +{ + "$schema": "https://biomejs.dev/schemas/1.9.4/schema.json", + "files": { + "ignore": [ + "dist", + "node_modules", + "public/pyodide", + "**/*.svelte" + ] + }, + "linter": { + "enabled": true, + "rules": { + "recommended": true + } + }, + "overrides": [ + { + "include": [ + "src/modules/wasm/worker/**" + ], + "linter": { + "rules": { + "suspicious": { + "noExplicitAny": "off" + } + } + } + } + ] +} diff --git a/src/ifctester/webapp/index.html b/src/ifctester/webapp/index.html index 27c32440dc..48ac4cc1c8 100644 --- a/src/ifctester/webapp/index.html +++ b/src/ifctester/webapp/index.html @@ -9,6 +9,6 @@
- +