@@ -9,6 +9,7 @@ import 'package:celest_cli/src/context.dart';
99import 'package:celest_cli/src/sdk/dart_sdk.dart' ;
1010import 'package:celest_cli/src/utils/error.dart' ;
1111import 'package:celest_cli/src/utils/json.dart' ;
12+ import 'package:celest_cloud/src/proto.dart' as proto;
1213import 'package:crypto/crypto.dart' ;
1314import 'package:logging/logging.dart' ;
1415
@@ -31,17 +32,20 @@ final class EntrypointDefinition {
3132
3233final class EntrypointResult {
3334 const EntrypointResult ({
35+ required this .type,
3436 required this .outputDillPath,
3537 required this .outputDill,
3638 required this .outputDillDigest,
3739 });
3840
41+ final proto.ProjectAsset_Type type;
3942 final String outputDillPath;
4043 final Uint8List outputDill;
4144 final Digest outputDillDigest;
4245
4346 @override
4447 String toString () => prettyPrintJson ({
48+ 'type' : type.name,
4549 'outputDillPath' : outputDillPath,
4650 'outputDillSha256' : outputDillDigest.toString (),
4751 });
@@ -58,6 +62,51 @@ final class EntrypointCompiler {
5862 final bool verbose;
5963 final List <String > enabledExperiments;
6064
65+ Future <EntrypointResult > _crossCompile ({
66+ required String entrypointPath,
67+ }) async {
68+ logger.fine ('Cross-compiling entrypoint: $entrypointPath ' );
69+ final outputPath = p.join (p.dirname (entrypointPath), 'main.exe' );
70+ final command = < String > [
71+ Sdk .current.dart,
72+ 'compile' ,
73+ 'exe' ,
74+ '--target-os=linux' ,
75+ '--target-arch=x64' ,
76+ '--experimental-cross-compilation' ,
77+ '-o' ,
78+ outputPath,
79+ entrypointPath,
80+ ];
81+ final result = await processManager.run (
82+ command,
83+ workingDirectory: projectPaths.outputsDir,
84+ includeParentEnvironment: true ,
85+ stdoutEncoding: utf8,
86+ stderrEncoding: utf8,
87+ );
88+ final ProcessResult (: exitCode, : stdout as String , : stderr as String ) =
89+ result;
90+ logger.fine ('Cross-compilation finished with status $exitCode ' );
91+ if (exitCode != 0 ) {
92+ throw ProcessException (
93+ Sdk .current.dart,
94+ command.sublist (1 ),
95+ 'Cross-compilation failed:\n $stdout \n $stderr ' ,
96+ exitCode,
97+ );
98+ }
99+
100+ final outputDill = await fileSystem.file (outputPath).readAsBytes ();
101+ final outputDillDigest = await _computeMd5 (outputDill.asUnmodifiableView ());
102+ return EntrypointResult (
103+ type: proto.ProjectAsset_Type .DART_EXECUTABLE ,
104+ outputDillPath: outputPath,
105+ outputDill: outputDill,
106+ outputDillDigest: outputDillDigest,
107+ );
108+ }
109+
61110 Future <EntrypointResult > compile ({
62111 required ast.ResolvedProject resolvedProject,
63112 required String entrypointPath,
@@ -69,16 +118,20 @@ final class EntrypointCompiler {
69118 '$entrypointPath ' ,
70119 );
71120 }
72- final pathWithoutDart = entrypointPath.substring (
73- 0 ,
74- entrypointPath.length - 5 ,
75- );
121+
122+ if (resolvedProject.sdkConfig.targetSdk == SdkType .dart &&
123+ Sdk .current.supportsCrossCompilation) {
124+ return _crossCompile (
125+ entrypointPath: entrypointPath,
126+ );
127+ }
128+
76129 final packageConfig = await transformPackageConfig (
77130 packageConfigPath: projectPaths.packagesConfig,
78131 fromRoot: projectPaths.projectRoot,
79132 toRoot: projectPaths.outputsDir,
80133 );
81- final outputPath = '$ pathWithoutDart . dill' ;
134+ final outputPath = p. join (p. dirname (entrypointPath), 'main.aot. dill') ;
82135 final (target, platformDill, sdkRoot) =
83136 switch (resolvedProject.sdkConfig.targetSdk) {
84137 SdkType .flutter => (
@@ -136,6 +189,7 @@ final class EntrypointCompiler {
136189 final outputDill = await fileSystem.file (outputPath).readAsBytes ();
137190 final outputDillDigest = await _computeMd5 (outputDill.asUnmodifiableView ());
138191 return EntrypointResult (
192+ type: proto.ProjectAsset_Type .DART_KERNEL ,
139193 outputDillPath: outputPath,
140194 outputDill: outputDill,
141195 outputDillDigest: outputDillDigest,
0 commit comments