Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

linux dynamic linking #79

Merged
merged 3 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ fn main() {
// Get the roc ray target
let target = RocRaySupportedTarget::default();

// Find required static libraries in the build cache or root directory
println!("cargo:rustc-link-search={}", out_dir.display());
// Find required libraries in the build cache
println!("cargo:rustc-link-search=native={}", out_dir.display());

// Get the roc app object file (ensure it exists)
let app = get_roc_app_object(&target);
Expand Down Expand Up @@ -123,8 +123,9 @@ fn main() {
let out_path = out_dir.join("libapp.so");
std::fs::copy(app_so, out_path).unwrap();

// TODO is this required? it seems to cause a segfault
// Add linking flags to make sure our symbols are visible to roc
println!("cargo:rustc-link-arg=-Wl,-export_dynamic");
// println!("cargo:rustc-link-arg=-Wl,-export_dynamic");

// Link with the app object file
println!("cargo:rustc-link-lib=dylib=app");
Expand Down Expand Up @@ -195,13 +196,14 @@ fn get_roc_app_object(target: &RocRaySupportedTarget) -> AppType {
}
}
RocRaySupportedTarget::Linux => {
// Check if the app.o built by roc exists
// Check which app built by roc exists
let app_o = manifest_dir().join("app.o");
let app_so = manifest_dir().join("libapp.so");
let lib_app_so = manifest_dir().join("libapp.so");

if app_o.exists() {
AppType::Static(app_o.to_path_buf())
} else if app_so.exists() {
AppType::Dynamic(app_so.to_path_buf())
} else if lib_app_so.exists() {
AppType::Dynamic(lib_app_so.to_path_buf())
} else {
panic!(
"app.o or libapp.so file not found -- this should have been generated by roc"
Expand Down
12 changes: 4 additions & 8 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,18 @@ dev app="examples/basic-shapes.roc" features="default":
[linux]
dev app="examples/basic-shapes.roc" features="default":
# remove previous builds
rm -f app.o
rm -f rocray
rm -f *.o
rm -f *.so

# roc check use 2 as an exit code for warnings
roc check {{app}} || [ $? -eq 2 ] && exit 0 || exit 1

# build once to ensure we have a dylib to link against
roc build --no-link --emit-llvm-ir --output app.o {{app}} || [ $? -eq 2 ] && exit 0 || exit 1
roc build --lib --emit-llvm-ir --output libapp.so {{app}} || [ $? -eq 2 ] && exit 0 || exit 1

# build the host app
cargo build

# copy the app to the cwd directory
cp target/debug/rocray .
cargo run --features {{features}}

./rocray

# build and run an executable
[windows]
Expand Down
Loading