Skip to content

Commit 87eeceb

Browse files
committed
build(rust): split vendored C API source
Stop amalgamating merve_c.cpp into rust/deps/merve.cpp; vendor it as rust/deps/merve_c.cpp and compile both translation units. This keeps merve_error_loc helpers in the C API layer and matches the upstream file layout.
1 parent b0271a1 commit 87eeceb

4 files changed

Lines changed: 155 additions & 364 deletions

File tree

rust/build.rs

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@ fn amalgamate_file(
133133
out.push_str(&format!("/* end file {filename} */\n"));
134134
}
135135

136-
/// When building inside the merve repository, produce the three amalgamated
137-
/// files in `deps/`: merve.h, merve.cpp, merve_c.h.
136+
/// When building inside the merve repository, produce the vendored
137+
/// sources in `deps/`: merve.h, merve.cpp, merve_c.cpp, merve_c.h.
138138
fn amalgamate_from_repo(project_root: &Path, deps: &Path) {
139139
let include_path = project_root.join("include");
140140
let source_path = project_root.join("src");
@@ -159,21 +159,23 @@ fn amalgamate_from_repo(project_root: &Path, deps: &Path) {
159159
);
160160
fs::write(deps.join("merve.h"), &header).expect("failed to write deps/merve.h");
161161

162-
// 2. Amalgamate merve.cpp (parser.cpp + merve_c.cpp with includes resolved).
162+
// 2. Amalgamate merve.cpp (parser.cpp with includes resolved).
163163
let mut source = String::from("#include \"merve.h\"\n\n");
164-
for cpp in &["parser.cpp", "merve_c.cpp"] {
165-
amalgamate_file(
166-
&include_path,
167-
&source_path,
168-
&source_path,
169-
cpp,
170-
&mut source,
171-
&mut included,
172-
);
173-
}
164+
amalgamate_file(
165+
&include_path,
166+
&source_path,
167+
&source_path,
168+
"parser.cpp",
169+
&mut source,
170+
&mut included,
171+
);
174172
fs::write(deps.join("merve.cpp"), &source).expect("failed to write deps/merve.cpp");
175173

176-
// 3. Copy merve_c.h verbatim (standalone C header).
174+
// 3. Copy merve_c.cpp verbatim (C API implementation).
175+
fs::copy(source_path.join("merve_c.cpp"), deps.join("merve_c.cpp"))
176+
.expect("failed to copy merve_c.cpp");
177+
178+
// 4. Copy merve_c.h verbatim (standalone C header).
177179
fs::copy(include_path.join("merve_c.h"), deps.join("merve_c.h"))
178180
.expect("failed to copy merve_c.h");
179181
}
@@ -207,15 +209,17 @@ fn main() {
207209
}
208210
}
209211

210-
// Both in-repo and published crate use the same layout: merve.cpp + merve.h + merve_c.h
212+
// Both in-repo and published crate use the same layout:
213+
// merve.cpp + merve_c.cpp + merve.h + merve_c.h
211214
assert!(
212-
deps.join("merve.cpp").exists(),
215+
deps.join("merve.cpp").exists() && deps.join("merve_c.cpp").exists(),
213216
"No C++ sources found in deps/. \
214-
When building outside the repository, deps/ must contain the amalgamated sources."
217+
When building outside the repository, deps/ must contain the vendored sources."
215218
);
216219

217220
let mut build = cc::Build::new();
218221
build.file(deps.join("merve.cpp"));
222+
build.file(deps.join("merve_c.cpp"));
219223
build.include(&deps);
220224
build.cpp(true).std("c++20").warnings(false);
221225

0 commit comments

Comments
 (0)