write sources to temp dir for Windows

This commit is contained in:
Nick Fisher
2025-04-16 18:05:03 +08:00
parent 2b00d374e0
commit 8a35060653

View File

@@ -9,8 +9,7 @@ import 'package:path/path.dart' as path;
void main(List<String> args) async { void main(List<String> args) async {
await build(args, (BuildInput input, BuildOutputBuilder output) async { await build(args, (BuildInput input, BuildOutputBuilder output) async {
final packageRoot = input.packageRoot; final packageRoot = input.packageRoot;
var pkgRootFilePath = packageRoot var pkgRootFilePath = packageRoot.toFilePath(windows: Platform.isWindows);
.toFilePath(windows: Platform.isWindows);
final config = input.config; final config = input.config;
@@ -44,8 +43,8 @@ void main(List<String> args) async {
var platform = targetOS.toString().toLowerCase(); var platform = targetOS.toString().toLowerCase();
if (!dryRun) { if (!dryRun) {
logger.info( logger
"Building Thermion for ${targetOS} in mode ${buildMode.name}"); .info("Building Thermion for ${targetOS} in mode ${buildMode.name}");
} }
// We don't support Linux (yet), so the native/Filament libraries won't be // We don't support Linux (yet), so the native/Filament libraries won't be
@@ -56,7 +55,9 @@ void main(List<String> args) async {
throw Exception("TODO"); throw Exception("TODO");
} }
var libDir = (await getLibDir(packageRoot, targetOS, targetArchitecture, logger, buildMode)).path; var libDir = (await getLibDir(
packageRoot, targetOS, targetArchitecture, logger, buildMode))
.path;
var sources = Directory(path.join(pkgRootFilePath, "native", "src")) var sources = Directory(path.join(pkgRootFilePath, "native", "src"))
.listSync(recursive: true) .listSync(recursive: true)
@@ -112,12 +113,11 @@ void main(List<String> args) async {
if (targetOS == OS.macOS) ...["matdbg", "fgviewer"] if (targetOS == OS.macOS) ...["matdbg", "fgviewer"]
]; ];
if (platform == "windows") { if (platform == "windows") {
// we just need the libDir and don't need to explicitly link the actual libs // we just need the libDir and don't need to explicitly link the actual libs
// (these are linked via ThermionWin32.h) // (these are linked via ThermionWin32.h)
libDir = Directory(libDir) libDir =
.uri Directory(libDir).uri.toFilePath(windows: targetOS == OS.windows);
.toFilePath(windows: targetOS == OS.windows);
} else { } else {
libs.add("stdc++"); libs.add("stdc++");
} }
@@ -182,7 +182,10 @@ void main(List<String> args) async {
frameworks = frameworks.expand((f) => ["-framework", f]).toList(); frameworks = frameworks.expand((f) => ["-framework", f]).toList();
File("C:\\Users\\nickh\\thermion_sources.rsp").writeAsStringSync(sources.join("\n")); var srcs = File(Directory.systemTemp.path +
Platform.pathSeparator +
"thermion_sources.rsp");
srcs.writeAsStringSync(sources.join("\n"));
final cbuilder = CBuilder.library( final cbuilder = CBuilder.library(
name: packageName, name: packageName,
@@ -206,7 +209,7 @@ void main(List<String> args) async {
"/I${path.join(pkgRootFilePath, "native", "include")}", "/I${path.join(pkgRootFilePath, "native", "include")}",
"/I${path.join(pkgRootFilePath, "native", "include", "filament")}", "/I${path.join(pkgRootFilePath, "native", "include", "filament")}",
"/I${path.join(pkgRootFilePath, "native", "include", "windows", "vulkan")}", "/I${path.join(pkgRootFilePath, "native", "include", "windows", "vulkan")}",
"@C:\\Users\\nickh\\thermion_sources.rsp", "@${srcs.uri.toFilePath(windows: true)}",
// ...sources, // ...sources,
'/link', '/link',
"/LIBPATH:$libDir", "/LIBPATH:$libDir",
@@ -216,8 +219,6 @@ void main(List<String> args) async {
dartBuildFiles: ['hook/build.dart'], dartBuildFiles: ['hook/build.dart'],
); );
await cbuilder.run( await cbuilder.run(
input: input, input: input,
output: output, output: output,
@@ -266,9 +267,7 @@ void main(List<String> args) async {
} }
if (targetOS == OS.windows) { if (targetOS == OS.windows) {
var importLib = File(path.join( var importLib = File(path.join(
outputDirectory.path.substring(1).replaceAll("/", "\\"), outputDirectory.path.substring(1).replaceAll("/", "\\"),
"thermion_dart.lib")); "thermion_dart.lib"));
final libthermion = CodeAsset( final libthermion = CodeAsset(
@@ -318,7 +317,8 @@ String _getLibraryUrl(String platform, String mode) {
// //
// Download precompiled Filament libraries for the target platform from Cloudflare. // Download precompiled Filament libraries for the target platform from Cloudflare.
// //
Future<Directory> getLibDir(Uri packageRoot, OS targetOS, Architecture targetArchitecture, Logger logger, BuildMode buildMode) async { Future<Directory> getLibDir(Uri packageRoot, OS targetOS,
Architecture targetArchitecture, Logger logger, BuildMode buildMode) async {
var platform = targetOS.toString().toLowerCase(); var platform = targetOS.toString().toLowerCase();
var mode = buildMode == BuildMode.debug ? "debug" : "release"; var mode = buildMode == BuildMode.debug ? "debug" : "release";
@@ -343,8 +343,7 @@ Future<Directory> getLibDir(Uri packageRoot, OS targetOS, Architecture targetArc
libDir = Directory(path.join(libDir.path, archExtension)); libDir = Directory(path.join(libDir.path, archExtension));
} else if (platform == "windows") { } else if (platform == "windows") {
if (targetArchitecture != Architecture.x64) { if (targetArchitecture != Architecture.x64) {
throw Exception( throw Exception("Unsupported architecture : ${targetArchitecture}");
"Unsupported architecture : ${targetArchitecture}");
} }
} }