Fix archive issues in cli

This commit is contained in:
nub31
2025-08-18 21:25:03 +02:00
parent 37dd110bb6
commit 7ed1b80c32
8 changed files with 51 additions and 34 deletions

View File

@@ -1,8 +1,19 @@
// c // c
extern func puts(text: cstring) extern func puts(text: cstring)
struct Human {
name: cstring
age: u32
}
func main(args: []cstring): i64 func main(args: []cstring): i64
{ {
puts("Hello, World") let x: Human = struct {
name = "Oliver"
age = 23
}
puts(x.name)
return 0 return 0
} }

View File

@@ -14,8 +14,10 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Remove="assets\libruntime_x64.a" /> <None Remove="assets\runtime.o" />
<EmbeddedResource Include="assets\libruntime_x64.a" /> <EmbeddedResource Include="assets\runtime.o" />
<None Remove="assets\x64.o" />
<EmbeddedResource Include="assets\x64.o" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@@ -124,32 +124,38 @@ for (var i = 0; i < typedSyntaxTrees.Count; i++)
objectFiles.Add(objFilePath); objectFiles.Add(objFilePath);
} }
const string runtimeName = "libruntime_x64.a";
var resources = Assembly.GetExecutingAssembly().GetManifestResourceNames(); var resources = Assembly.GetExecutingAssembly().GetManifestResourceNames();
var runtime = resources.First(r => r.EndsWith(runtimeName));
await using var reader = Assembly.GetExecutingAssembly().GetManifestResourceStream(runtime); string[] runtimeObjects = ["runtime.o", "x64.o"];
if (reader == null) foreach (var runtimeObject in runtimeObjects)
{ {
Console.Error.WriteLine($"Cannot open stream to '{runtimeName}'"); var runtime = resources.First(r => r.EndsWith(runtimeObject));
await using var reader = Assembly
.GetExecutingAssembly()
.GetManifestResourceStream(runtime);
if (reader == null)
{
Console.Error.WriteLine($"Cannot open read stream to '{runtimeObject}'");
return 1; return 1;
} }
var runtimePath = Path.Combine("build", "runtime", runtimeName); var runtimePath = Path.Combine("build", "runtime", runtimeObject);
var runtimeDir = Path.GetDirectoryName(runtimePath); var runtimeDir = Path.GetDirectoryName(runtimePath);
if (!string.IsNullOrEmpty(runtimeDir)) if (!string.IsNullOrEmpty(runtimeDir))
{ {
Directory.CreateDirectory(runtimeDir); Directory.CreateDirectory(runtimeDir);
}
await using var writer = new FileStream(runtimePath, FileMode.Create);
reader.CopyTo(writer);
objectFiles.Add(runtimePath);
} }
await using var writer = new FileStream(runtimePath, FileMode.Create);
reader.CopyTo(writer);
objectFiles.Add(runtimePath);
var outPath = options.OutputPath ?? Path.Combine("build", "out.a"); var outPath = options.OutputPath ?? Path.Combine("build", "out.a");
var outDir = Path.GetDirectoryName(outPath); var outDir = Path.GetDirectoryName(outPath);
if (!string.IsNullOrEmpty(outDir)) if (!string.IsNullOrEmpty(outDir))
@@ -163,4 +169,5 @@ if (!archiveResult)
return 1; return 1;
} }
return 0; return 0;

Binary file not shown.

View File

@@ -939,7 +939,7 @@ public class QBEGenerator
{ {
destination = TmpName(); destination = TmpName();
var size = SizeOf(structInitializer.StructType); var size = SizeOf(structInitializer.StructType);
_writer.Indented($"{destination} =l alloc8 {size}"); _writer.Indented($"{destination} =l call $malloc(l {size})");
} }
foreach (var field in structDef.Fields) foreach (var field in structDef.Fields)

View File

@@ -1,2 +1 @@
bin build
bin-int

View File

@@ -3,14 +3,12 @@ TARGET ?= x64
CFLAGS = -Wall -Werror -Wextra -g CFLAGS = -Wall -Werror -Wextra -g
libruntime: bin-int/runtime.o libruntime: build/runtime.o
$(CC) $(CFLAGS) -c targets/$(TARGET).s -o bin-int/$(TARGET).o $(CC) $(CFLAGS) -c targets/$(TARGET).s -o build/$(TARGET).o
mkdir -p bin
ar rcs bin/libruntime_$(TARGET).a bin-int/runtime.o bin-int/$(TARGET).o
bin-int/runtime.o: runtime/runtime.c build/runtime.o: runtime/runtime.c
mkdir -p bin-int mkdir -p build
$(CC) $(CFLAGS) -c runtime/runtime.c -o bin-int/runtime.o $(CC) $(CFLAGS) -c runtime/runtime.c -o build/runtime.o
clean: clean:
rm -r bin bin-int rm -r build