common: add subproc.h wrapper, disabled on android/ios (#26102)

* add common/subproc.h|cpp

* add compile flag LLAMA_SUBPROCESS

* disabled by default on android and ios

* test-jinja: use common subproc

* mtmd: disable video if subproc is not set

* disable subproc on wasm

* make is_created atomic

* migrate server-mcp
This commit is contained in:
Xuan-Son Nguyen
2026-07-26 20:54:25 +02:00
committed by GitHub
parent af285020e9
commit d2a818231e
9 changed files with 272 additions and 109 deletions
+11 -14
View File
@@ -4,7 +4,7 @@
#include <cstdlib>
#include <nlohmann/json.hpp>
#include <sheredom/subprocess.h>
#include "subproc.h"
#include "jinja/runtime.h"
#include "jinja/parser.h"
@@ -2135,21 +2135,20 @@ static void test_template_py(testing & t, const std::string & name, const std::s
const char * python_executable = "python3";
#endif
const char * command_line[] = {python_executable, "-c", py_script.c_str(), NULL};
std::vector<std::string> args = {python_executable, "-c", py_script, };
struct subprocess_s subprocess;
common_subproc subprocess;
int options = subprocess_option_combined_stdout_stderr
| subprocess_option_no_window
| subprocess_option_inherit_environment
| subprocess_option_search_user_path;
int result = subprocess_create(command_line, options, &subprocess);
if (result != 0) {
t.log("Failed to create subprocess, error code: " + std::to_string(result));
if (!subprocess.create(args, options)) {
t.log("Failed to create subprocess");
t.assert_true("subprocess creation", false);
return;
}
FILE * p_stdin = subprocess_stdin(&subprocess);
FILE * p_stdin = subprocess.stdin_file();
// Write input
std::string input = merged.dump();
@@ -2157,24 +2156,22 @@ static void test_template_py(testing & t, const std::string & name, const std::s
if (written != input.size()) {
t.log("Failed to write complete input to subprocess stdin");
t.assert_true("subprocess stdin write", false);
subprocess_destroy(&subprocess);
subprocess.close_stdin();
subprocess.join();
return;
}
fflush(p_stdin);
fclose(p_stdin); // Close stdin to signal EOF to the Python process
subprocess.stdin_file = nullptr;
subprocess.close_stdin(); // Close stdin to signal EOF to the Python process
// Read output
std::string output;
char buffer[1024];
FILE * p_stdout = subprocess_stdout(&subprocess);
FILE * p_stdout = subprocess.stdout_file();
while (fgets(buffer, sizeof(buffer), p_stdout)) {
output += buffer;
}
int process_return;
subprocess_join(&subprocess, &process_return);
subprocess_destroy(&subprocess);
int process_return = subprocess.join();
if (process_return != 0) {
t.log("Python script failed with exit code: " + std::to_string(process_return));