Skip to content

Commit 89b12d1

Browse files
committed
Build as a 'bin' crate, linking with rust-lld
Using the same target file as system76/firmware-setup#14 Builds, though I don't know how to properly test it.
1 parent 01f539c commit 89b12d1

File tree

6 files changed

+44
-67
lines changed

6 files changed

+44
-67
lines changed

Cargo.toml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@ name = "system76_gop_policy"
33
version = "1.0.0"
44
edition = "2018"
55

6-
[lib]
7-
name = "system76_gop_policy"
8-
path = "src/lib.rs"
9-
crate-type = ["staticlib"]
10-
116
[profile.release]
127
lto = true
138

Makefile

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
TARGET?=x86_64-efi-pe
1+
TARGET?=x86_64-unknown-uefi-drv
22

33
export LD=ld
44
export RUST_TARGET_PATH=$(CURDIR)/targets
@@ -39,39 +39,10 @@ $(BUILD)/efi.img: $(BUILD)/boot.efi
3939
mcopy -i $@.tmp $< ::driver.efi
4040
mv $@.tmp $@
4141

42-
$(BUILD)/boot.efi: $(BUILD)/boot.o
43-
$(LD) \
44-
-m i386pep \
45-
--oformat pei-x86-64 \
46-
--dll \
47-
--image-base 0 \
48-
--section-alignment 32 \
49-
--file-alignment 32 \
50-
--major-os-version 0 \
51-
--minor-os-version 0 \
52-
--major-image-version 0 \
53-
--minor-image-version 0 \
54-
--major-subsystem-version 0 \
55-
--minor-subsystem-version 0 \
56-
--subsystem 11 \
57-
--heap 0,0 \
58-
--stack 0,0 \
59-
--pic-executable \
60-
--entry _start \
61-
--no-insert-timestamp \
62-
$< -o $@
63-
64-
$(BUILD)/boot.o: $(BUILD)/boot.a
65-
rm -rf $(BUILD)/boot
66-
mkdir $(BUILD)/boot
67-
cd $(BUILD)/boot && ar x ../boot.a
68-
ld -r $(BUILD)/boot/*.o -o $@
69-
70-
$(BUILD)/boot.a: Cargo.lock Cargo.toml src/*
42+
$(BUILD)/boot.efi: Cargo.lock Cargo.toml src/*
7143
mkdir -p $(BUILD)
7244
cargo rustc \
7345
-Z build-std=core,alloc \
74-
--lib \
7546
--target $(TARGET) \
7647
--release \
7748
-- \

gop-policy.inf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
VERSION_STRING = 1.0
77

88
[Binaries.X64]
9-
PE32|build/x86_64-efi-pe/boot.efi|*
9+
PE32|build/x86_64-unknown-uefi-drv/boot.efi|*

src/lib.rs renamed to src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#![no_std]
2+
#![no_main]
23
// #![feature(const_fn)]
34
// #![feature(core_intrinsics)]
45
#![feature(prelude_import)]

targets/x86_64-efi-pe.json

Lines changed: 0 additions & 30 deletions
This file was deleted.

targets/x86_64-unknown-uefi-drv.json

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"abi-return-struct-as-int": true,
3+
"allows-weak-linkage": false,
4+
"arch": "x86_64",
5+
"code-model": "large",
6+
"cpu": "x86-64",
7+
"data-layout": "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128",
8+
"disable-redzone": true,
9+
"emit-debug-gdb-scripts": false,
10+
"env": "",
11+
"exe-suffix": ".efi",
12+
"executables": true,
13+
"features": "-mmx,-sse,+soft-float",
14+
"is-builtin": true,
15+
"linker": "rust-lld",
16+
"linker-flavor": "lld-link",
17+
"lld-flavor": "link",
18+
"llvm-target": "x86_64-unknown-windows",
19+
"max-atomic-width": 64,
20+
"os": "uefi",
21+
"panic-strategy": "abort",
22+
"pre-link-args": {
23+
"lld-link": [
24+
"/entry:_start",
25+
"/heap:0,0",
26+
"/stack:0,0",
27+
"/dll",
28+
"/base:0",
29+
"/align:32",
30+
"/filealign:32",
31+
"/subsystem:efi_boot_service_driver"
32+
]
33+
},
34+
"singlethread": true,
35+
"stack-probes": true,
36+
"target-c-int-width": "32",
37+
"target-endian": "little",
38+
"target-pointer-width": "64",
39+
"vendor": "unknown"
40+
}

0 commit comments

Comments
 (0)