Skip to content

Commit f6ae49e

Browse files
committed
fix: windows compile
1 parent c5b4c9d commit f6ae49e

File tree

5 files changed

+29
-15
lines changed

5 files changed

+29
-15
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ target
44
.VSCodeCounter
55
*.ll
66
*.out
7+
*.ilk
8+
*.exe
9+
*.pdb
710

811
test.cpp
912
*.bc

.vscode/launch.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"build"
2929
]
3030
},
31-
"args": ["run","out.plb"]
31+
"args": ["run","out.bc"]
3232
},
3333
{
3434
"type": "lldb",
@@ -50,12 +50,11 @@
5050
"name": "(Windows) Launch",
5151
"type": "cppvsdbg",
5252
"request": "launch",
53-
"program": "${workspaceFolder}/out",
53+
"program": "${workspaceFolder}/out.exe",
5454
"args": [],
5555
"stopAtEntry": false,
5656
"cwd": "${workspaceFolder}",
5757
"environment": [],
58-
"preLaunchTask": "windows link"
5958
}
6059

6160
]

book/src/tutorial/basicproject.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ entry指定了该项目的入口文件,即编译器将从该文件开始编译
2828
> 重要:`printi64ln`函数是目前pl runtime中的一个测试用内置函数,此函数可能会在未来移除
2929
3030
## 编译
31-
如果你已经安装了`plc`,那么你可以在项目根目录下执行`plc main.pi`命令来编译该项目。此指令会生成一个名叫`out.plb`的文件,还有一些中间文件
31+
如果你已经安装了`plc`,那么你可以在项目根目录下执行`plc main.pi`命令来编译该项目。此指令会生成一个名叫`out.bc`的文件,还有一些中间文件
3232

3333
> 如果你配置了静态编译环境,还会生成一个叫做`out`的文件,该文件是一个可执行文件,可以直接运行
3434
> 而如果你只有jit环境,该文件不会生成,并且编译命令会输出一个clang报错和两行warning,这是正常现象
3535
3636
## jit运行
3737

38-
编译后输入`plc run out.plb`可以jit运行该项目,其输出结果如下:
38+
编译后输入`plc run out.bc`可以jit运行该项目,其输出结果如下:
3939

4040
```
4141
666

src/ast/compiler.rs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -282,9 +282,9 @@ pub fn compile(db: &dyn Db, docs: MemDocsInput, out: String, op: Options) {
282282
}
283283
tm.write_to_file(&llvmmod, FileType::Assembly, Path::new(&f))
284284
.unwrap();
285-
let fo = out.to_string();
285+
let mut fo = out.to_string();
286286
let mut out = out.to_string();
287-
out.push_str(".plb");
287+
out.push_str(".bc");
288288
llvmmod.write_bitcode_to_path(Path::new(&out));
289289
println!("jit executable file writted to: {}", &out);
290290
let mut cmd = Command::new("clang-14");
@@ -298,18 +298,30 @@ pub fn compile(db: &dyn Db, docs: MemDocsInput, out: String, op: Options) {
298298
return;
299299
}
300300
let root = root.unwrap();
301-
let vmpath = format!("{}/libvm.a", root);
301+
let vmpath;
302+
if cfg!(target_os = "windows") {
303+
cmd = Command::new("clang");
304+
f = out;
305+
fo.push_str(".exe");
306+
vmpath = format!("{}/vm.lib", root);
307+
cmd.arg("-lws2_32")
308+
.arg("-lbcrypt")
309+
.arg("-luserenv")
310+
.arg("-ladvapi32");
311+
} else {
312+
vmpath = format!("{}/libvm.a", root);
313+
cmd.arg("-pthread").arg("-ldl");
314+
}
302315

303316
cmd.arg(format!("-O{}", op.optimization as u32))
304-
.arg("-pthread")
305-
.arg("-ldl")
306317
.arg(&f)
307318
.arg(&vmpath)
308319
.arg("-o")
309320
.arg(&fo)
310321
.arg("-g");
311322
let res = cmd.status();
312323
if res.is_err() || !res.as_ref().unwrap().success() {
324+
println!("{}", format!("link failed: {}", res.unwrap()).bright_red());
313325
println!("warning: link with pivot lang vm failed, could be caused by libvm not found.");
314326
} else {
315327
println!("link succ, output file: {}", fo);
@@ -445,7 +457,7 @@ mod test {
445457
ActionType::Compile,
446458
None,
447459
);
448-
let outplb = "testout.plb";
460+
let outplb = "testout.bc";
449461
let out = "testout";
450462
compile(
451463
&db,

src/ast/ctx.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,11 +1023,11 @@ pub fn create_ctx_info<'ctx>(
10231023
let metav = context.metadata_node(&[BasicMetadataValueEnum::IntValue(
10241024
context.i32_type().const_int(3, false),
10251025
)]);
1026-
// let metacv = context.metadata_node(&[BasicMetadataValueEnum::IntValue(
1027-
// context.i32_type().const_int(1, false),
1028-
// )]);
1026+
let metacv = context.metadata_node(&[BasicMetadataValueEnum::IntValue(
1027+
context.i32_type().const_int(1, false),
1028+
)]);
10291029
module.add_metadata_flag("Debug Info Version", FlagBehavior::Warning, metav);
1030-
// module.add_metadata_flag("CodeView", FlagBehavior::Warning, metacv); // TODO: is this needed for windows debug?
1030+
module.add_metadata_flag("CodeView", FlagBehavior::Warning, metacv); // TODO: is this needed for windows debug?
10311031
let tm = get_target_machine(inkwell::OptimizationLevel::None);
10321032
(
10331033
module,

0 commit comments

Comments
 (0)