mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-03 00:24:34 +00:00
use an exported constant in the host
This commit is contained in:
parent
8a6a126c19
commit
cc0ee8c2fd
1 changed files with 12 additions and 5 deletions
|
@ -933,16 +933,18 @@ mod test {
|
||||||
|
|
||||||
extern fn magic() callconv(.C) u64;
|
extern fn magic() callconv(.C) u64;
|
||||||
|
|
||||||
|
extern const three: u64;
|
||||||
|
|
||||||
pub fn main() !void {
|
pub fn main() !void {
|
||||||
const stdout = std.io.getStdOut().writer();
|
const stdout = std.io.getStdOut().writer();
|
||||||
try stdout.print("Hello, {}!\n", .{magic()});
|
try stdout.print("Hello, {} {}!\n", .{magic(), three});
|
||||||
}
|
}
|
||||||
"#
|
"#
|
||||||
);
|
);
|
||||||
|
|
||||||
let app_zig = indoc!(
|
let app_zig = indoc!(
|
||||||
r#"
|
r#"
|
||||||
export const THREE: u64 = 3;
|
export const three: u64 = 3;
|
||||||
|
|
||||||
export fn magic() u64 {
|
export fn magic() u64 {
|
||||||
return 42;
|
return 42;
|
||||||
|
@ -955,7 +957,7 @@ mod test {
|
||||||
std::fs::write(dir.join("host.zig"), host_zig.as_bytes()).unwrap();
|
std::fs::write(dir.join("host.zig"), host_zig.as_bytes()).unwrap();
|
||||||
std::fs::write(dir.join("app.zig"), app_zig.as_bytes()).unwrap();
|
std::fs::write(dir.join("app.zig"), app_zig.as_bytes()).unwrap();
|
||||||
|
|
||||||
let dylib_bytes = crate::generate_dylib::synthetic_dll(&["magic".into()]);
|
let dylib_bytes = crate::generate_dylib::synthetic_dll(&["magic".into(), "three".into()]);
|
||||||
std::fs::write(dir.join("libapp.obj"), dylib_bytes).unwrap();
|
std::fs::write(dir.join("libapp.obj"), dylib_bytes).unwrap();
|
||||||
|
|
||||||
let output = std::process::Command::new(&zig)
|
let output = std::process::Command::new(&zig)
|
||||||
|
@ -1048,8 +1050,13 @@ mod test {
|
||||||
section_alignment as usize,
|
section_alignment as usize,
|
||||||
) as u64;
|
) as u64;
|
||||||
|
|
||||||
|
let hacks = image_base | 0xc000;
|
||||||
let dynamic_relocations = DynamicRelocationsPe::new(&app);
|
let dynamic_relocations = DynamicRelocationsPe::new(&app);
|
||||||
redirect_dummy_dll_functions(&mut app, &dynamic_relocations, &[app_code_section_va]);
|
redirect_dummy_dll_functions(
|
||||||
|
&mut app,
|
||||||
|
&dynamic_relocations,
|
||||||
|
&[app_code_section_va, hacks],
|
||||||
|
);
|
||||||
|
|
||||||
remove_dummy_dll_import_table(
|
remove_dummy_dll_import_table(
|
||||||
&mut app,
|
&mut app,
|
||||||
|
@ -1133,6 +1140,6 @@ mod test {
|
||||||
|
|
||||||
let output = String::from_utf8_lossy(&output.stdout);
|
let output = String::from_utf8_lossy(&output.stdout);
|
||||||
|
|
||||||
assert_eq!("Hello, 42!\n", output);
|
assert_eq!("Hello, 42 3!\n", output);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue