33用于构建 SecRandom 的独立可执行文件
44"""
55
6+ import argparse
7+ import os
68import subprocess
79import sys
810import re
4042}
4143
4244
45+ def parse_args () -> argparse .Namespace :
46+ """解析命令行参数"""
47+ parser = argparse .ArgumentParser (description = "Nuitka 打包脚本" )
48+ parser .add_argument (
49+ "--quick" ,
50+ action = "store_true" ,
51+ help = "快速构建模式:生成 standalone 目录(不启用 onefile)" ,
52+ )
53+ parser .add_argument (
54+ "--jobs" ,
55+ type = int ,
56+ default = max (1 , (os .cpu_count () or 1 ) - 1 ),
57+ help = "并行编译任务数,默认使用 CPU 核心数 - 1" ,
58+ )
59+ return parser .parse_args ()
60+
61+
4362def _print_packaging_summary () -> None :
4463 """Log a quick overview of the data and modules that will be bundled."""
4564
@@ -111,7 +130,7 @@ def _sanitize_version(ver_str: str) -> str:
111130 return "0.0.0.0"
112131
113132
114- def get_nuitka_command () -> list [str ]:
133+ def get_nuitka_command (* , quick : bool , jobs : int ) -> list [str ]:
115134 """获取Nuitka命令列表"""
116135 raw_version = VERSION if VERSION else "0.0.0"
117136 clean_version = _sanitize_version (raw_version )
@@ -125,7 +144,7 @@ def get_nuitka_command() -> list[str]:
125144 "-m" ,
126145 "nuitka" ,
127146 "--standalone" ,
128- "--onefile " ,
147+ f "--jobs= { max ( 1 , jobs ) } " ,
129148 "--enable-plugin=pyside6" ,
130149 "--assume-yes-for-downloads" ,
131150 "--output-dir=dist" ,
@@ -136,6 +155,8 @@ def get_nuitka_command() -> list[str]:
136155 "--copyright=Copyright (c) 2025" ,
137156 "--no-deployment-flag=self-execution" ,
138157 ]
158+ if not quick :
159+ cmd .append ("--onefile" )
139160
140161 # 编译器选择逻辑
141162 if sys .platform == "win32" :
@@ -231,15 +252,20 @@ def build_deb() -> None:
231252
232253def main ():
233254 """执行 Nuitka 打包"""
255+ args = parse_args ()
256+
234257 print ("=" * 60 )
235258 print ("开始使用 Nuitka + uv 打包 SecRandom" )
236259 print ("=" * 60 )
260+ print (
261+ f"构建模式: { 'quick-standalone' if args .quick else 'onefile' } | jobs={ max (1 , args .jobs )} "
262+ )
237263
238264 if sys .platform == "win32" and not check_compiler_env ():
239265 sys .exit (1 )
240266
241267 _print_packaging_summary ()
242- cmd = get_nuitka_command ()
268+ cmd = get_nuitka_command (quick = args . quick , jobs = args . jobs )
243269
244270 # 打印命令
245271 print ("\n 执行命令:" )
0 commit comments