Skip to content

build-app: run the user entry's main submodule (packaged apps were no-ops) - #3

Open
turinglambdaai wants to merge 1 commit into
mainfrom
fix/build-entry-main-submodule
Open

turinglambdaai wants to merge 1 commit into
mainfrom
fix/build-entry-main-submodule

Conversation

@turinglambdaai

Copy link
Copy Markdown
Owner

Fixes #1

根因

build-app 生成的入口包装模块把用户 main 以 普通库 的方式 require 进来。racket main.rkt 之所以会跑 (module+ main),是因为该文件本身就是程序的顶层模块;而包装模块自己是顶层模块,静态 require 进来的 main.rkt 只会被当库实例化——main 子模块永远不会执行。于是打包产物表现为:任何参数都立即 exit 0、无输出、程序体完全不启动(连 --version 都沉默)。

修复

入口包装改为镜像解释器语义:

  1. 保留静态 require "main.rkt"——raco exe 只嵌入静态可达的依赖闭包,dynamic-require 对它不可见;丢了它,运行时连 racket/hash 这类集合都找不到。
  2. 静态 require 之后,显式实例化 (submod "main.rkt" main)(用 module-declared? 探测,声明了才跑);未声明 main 子模块的应用(顶层脚本风格)由第 1 步自然运行,不会双重执行。

验证(Racket 9.3 CS / macOS arm64)

  • module+ main 风格真实应用(gPTP Studio,四千行):打包后 --version 输出、未知 flag 走 usage 退出 1、GUI 窗口打开、HTTP 服务 200、SSE 事件流正常
  • 顶层脚本风格小应用:正常执行、无双重运行
  • raco test glaze-test/:216 通过(含 macOS WebView e2e)

注:gPTP Studio 此前用的手工组装 workaround(仓库内 scripts/package-macos.sh)现可弃用,回归 glaze build-app。

…thing

The generated entry wrapper required the user's main as a plain library.
Under `racket main.rkt` the (module+ main) submodule runs because the file
is the program's top module; loaded via require from a wrapper, that
submodule is never instantiated — so build-app's launcher exited 0
immediately without executing any user code (no output for --version, no
usage error for unknown flags; the program body never started).

The wrapper now mirrors the interpreter: it keeps the static require (so
raco exe embeds the full dependency closure — dynamic-requires are
invisible to it) and then explicitly instantiates (submod "main.rkt" main)
when declared, falling back to the module body for top-level-style apps.

Verified on Racket 9.3 CS / macOS arm64 with a real app using module+ main
(window opens, server serves, SSE streams), a top-level-style script, and
--version/--bogus flag semantics. glaze-test: 216 passed.

Fixes #1
@turinglambdaai

Copy link
Copy Markdown
Owner Author

CI 说明:test (windows-latest) 的失败是 main 上已有的问题(main 最新一次 push 35001253186 同样挂在 glaze-test/appapi-test.rkt 的 WebView2 用例,位于 appapi-test.rkt:106 "page loaded"),与本 PR 改动(build.rkt 的入口生成)无关——其余 8 项检查全绿,含三平台 package 与 webview-e2e。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

build-app: assembled .app launcher exits 0 without running the program (Racket 9.3 CS)

1 participant