Skip to content

Commit cefd7ce

Browse files
committed
bender-slang: Add .clangd file for IDE support
1 parent db0ab16 commit cefd7ce

4 files changed

Lines changed: 57 additions & 2 deletions

File tree

.clangd

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
If:
2+
PathMatch: (^|.*/)crates/bender-slang/cpp/.*\.(h|hpp|hh|c|cc|cpp|cxx)$
3+
CompileFlags:
4+
Add:
5+
- -std=c++20
6+
- -fno-cxx-modules
7+
- -I.
8+
- -I../../../crates
9+
- -I../vendor/slang/include
10+
- -I../vendor/slang/external
11+
- -I../../../target/slang-generated-include
12+
- -I../../../target/cxxbridge
13+
- -DSLANG_USE_MIMALLOC=1
14+
- -DSLANG_USE_THREADS=1
15+
- -DSLANG_BOOST_SINGLE_HEADER=1

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ target
44
# Temporary test files
55
tests/**/tmp
66
tests/**/.bender
7+
8+
# clangd
9+
.cache/clangd

crates/bender-slang/build.rs

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,37 @@
11
// Copyright (c) 2025 ETH Zurich
22
// Tim Fischer <fischeti@iis.ee.ethz.ch>
33

4+
#[cfg(unix)]
5+
// We create a symlink from the generated include directory to a stable location in the target directory
6+
// so that tools like clangd can find the headers without needing to know the exact OUT_DIR path.
7+
// This is purely for improving the development experience and is not necessary for the build itself.
8+
fn refresh_include_symlink(generated_include_dir: &std::path::Path) {
9+
use std::ffi::OsStr;
10+
use std::fs;
11+
use std::os::unix::fs::symlink;
12+
use std::path::PathBuf;
13+
14+
let Ok(out_dir) = std::env::var("OUT_DIR") else {
15+
return;
16+
};
17+
let out_dir = PathBuf::from(out_dir);
18+
19+
let Some(target_root) = out_dir
20+
.ancestors()
21+
.find(|path| path.file_name() == Some(OsStr::new("target")))
22+
else {
23+
return;
24+
};
25+
26+
let stable_link = target_root.join("slang-generated-include");
27+
let _ = fs::remove_file(&stable_link);
28+
let _ = fs::remove_dir_all(&stable_link);
29+
let _ = symlink(generated_include_dir, &stable_link);
30+
}
31+
32+
#[cfg(not(unix))]
33+
fn refresh_include_symlink(_generated_include_dir: &std::path::Path) {}
34+
435
fn main() {
536
let target_os = std::env::var("CARGO_CFG_TARGET_OS").unwrap();
637
let target_env = std::env::var("CARGO_CFG_TARGET_ENV").unwrap();
@@ -64,6 +95,11 @@ fn main() {
6495
let dst = slang_lib.build();
6596
let lib_dir = dst.join("lib");
6697

98+
// Create a symlink for the generated include directory
99+
if target_os == "linux" || target_os == "macos" {
100+
refresh_include_symlink(&dst.join("include"));
101+
}
102+
67103
// Configure Linker to find Slang static library
68104
println!("cargo:rustc-link-search=native={}", lib_dir.display());
69105
println!("cargo:rustc-link-lib=static=svlang");
@@ -100,7 +136,7 @@ fn main() {
100136
let compiler = std::env::var("CXX").unwrap_or_else(|_| "g++".to_string());
101137
// We search for the static libstdc++ file using g++
102138
let output = std::process::Command::new(&compiler)
103-
.args(&["-print-file-name=libstdc++.a"])
139+
.args(["-print-file-name=libstdc++.a"])
104140
.output()
105141
.expect("Failed to run g++");
106142

crates/bender-slang/cpp/slang_bridge.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
#include "rust/cxx.h"
88
#include "slang/diagnostics/DiagnosticEngine.h"
99
#include "slang/diagnostics/TextDiagnosticClient.h"
10-
#include "slang/driver/Driver.h"
10+
#include "slang/parsing/Preprocessor.h"
1111
#include "slang/syntax/SyntaxTree.h"
12+
#include "slang/text/SourceManager.h"
1213

1314
#include <cstddef>
1415
#include <cstdint>

0 commit comments

Comments
 (0)