Skip to content

Commit 24ac6d3

Browse files
committed
vala: Compile and run using Meson
1 parent 68e1d33 commit 24ac6d3

File tree

4 files changed

+56
-43
lines changed

4 files changed

+56
-43
lines changed

src/PanelCode.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import GObject from "gi://GObject";
44
import { makeDropdownFlat, settings as global_settings } from "./util.js";
55
import { setupRustProject } from "./langs/rust/rust.js";
66
import { setupTypeScriptProject } from "./langs/typescript/typescript.js";
7+
import { setupValaProject } from "./langs/vala/vala.js";
78

89
export default function PanelCode({
910
builder,
@@ -55,6 +56,10 @@ export default function PanelCode({
5556
stack_code.visible_child_name = panel.language;
5657
previewer.useInternal().catch(console.error);
5758

59+
if (panel.language.toLowerCase() === "vala") {
60+
setupValaProject(file).catch(console.error);
61+
}
62+
5863
if (panel.language.toLowerCase() === "rust") {
5964
setupRustProject(file).catch(console.error);
6065
}

src/langs/vala/Compiler.js

Lines changed: 27 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,44 @@
11
import Gio from "gi://Gio";
22
import dbus_previewer from "../../Previewer/DBusPreviewer.js";
3-
import { decode } from "../../util.js";
43

54
export default function ValaCompiler({ session }) {
65
const { file } = session;
76

8-
const module_file = file.get_child("libworkbenchcode.so");
9-
const file_vala = file.get_child("main.vala");
7+
const meson_builddir = "builddir";
8+
const module_file = file
9+
.get_child(meson_builddir)
10+
.get_child("libworkbenchcode.so");
1011

1112
async function compile() {
12-
let args;
13+
// TODO: Do not run setup if the build directory is already
14+
// configured
15+
const meson_launcher = new Gio.SubprocessLauncher();
16+
meson_launcher.set_cwd(file.get_path());
17+
const meson_setup = meson_launcher.spawnv([
18+
"meson",
19+
"setup",
20+
meson_builddir,
21+
]);
1322

14-
try {
15-
const [contents] = await file_vala.load_contents_async(null);
16-
const code = decode(contents);
17-
args = getValaCompilerArguments(code);
18-
} catch (error) {
19-
console.debug(error);
20-
return;
23+
await meson_setup.wait_async(null);
24+
const setup_result = meson_setup.get_successful();
25+
if (!setup_result) {
26+
return false;
2127
}
2228

23-
const valac_launcher = new Gio.SubprocessLauncher();
24-
valac_launcher.set_cwd(file.get_path());
25-
const valac = valac_launcher.spawnv([
26-
"valac",
27-
file_vala.get_path(),
28-
"--hide-internal",
29-
"-X",
30-
"-shared",
31-
"-X",
32-
"-fpic",
33-
"--library",
34-
"workbench",
35-
"-o",
36-
module_file.get_path(),
37-
"--vapi",
38-
"/dev/null",
39-
...args,
29+
const meson_compile = meson_launcher.spawnv([
30+
"meson",
31+
"compile",
32+
"-C",
33+
meson_builddir,
4034
]);
4135

42-
await valac.wait_async(null);
36+
await meson_compile.wait_async(null);
37+
const compile_result = meson_compile.get_successful();
4338

44-
const result = valac.get_successful();
45-
valac_launcher.close();
46-
return result;
39+
meson_launcher.close();
40+
41+
return compile_result;
4742
}
4843

4944
async function run() {
@@ -60,11 +55,3 @@ export default function ValaCompiler({ session }) {
6055

6156
return { compile, run };
6257
}
63-
64-
// Takes a string starting with the line
65-
// #!/usr/bin/env -S vala workbench.vala --pkg gtk4 --pkg libadwaita-1
66-
// and return ["--pkg", "gtk4", "--pkg", "libadwaita-1"]
67-
// FIXME: consider using https://docs.gtk.org/glib/struct.OptionContext.html instead
68-
function getValaCompilerArguments(text) {
69-
return text.split("\n")[0]?.split("-S vala ")[1]?.split(" ") || [];
70-
}

src/langs/vala/template/meson.build

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ dependencies = [
3030
dependency('webkitgtk-6.0'),
3131
dependency('gstreamer-1.0'),
3232
dependency('gtksourceview-5'),
33+
dependency('json-glib-1.0'),
3334
]
3435

35-
executable('demo', source_files,
36-
objects: 'libworkbenchcode.so',
36+
library('workbenchcode', source_files,
3737
dependencies: dependencies,
3838
install: true,
3939
)

src/langs/vala/vala.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import Gio from "gi://Gio";
22

33
import { isValaEnabled } from "../../Extensions/Extensions.js";
44
import { createLSPClient } from "../../common.js";
5-
import { getLanguage } from "../../util.js";
5+
import { getLanguage, copy } from "../../util.js";
66

77
export function setup({ document }) {
88
if (!isValaEnabled()) return;
@@ -44,3 +44,24 @@ export function setup({ document }) {
4444

4545
return lspc;
4646
}
47+
48+
const vala_template_dir = Gio.File.new_for_path(
49+
pkg.pkgdatadir,
50+
).resolve_relative_path("langs/vala/template");
51+
52+
export async function setupValaProject(destination) {
53+
return Promise.all([
54+
copy(
55+
"meson.build",
56+
vala_template_dir,
57+
destination,
58+
Gio.FileCopyFlags.OVERWRITE,
59+
),
60+
copy(
61+
"workbench.vala",
62+
vala_template_dir,
63+
destination,
64+
Gio.FileCopyFlags.OVERWRITE,
65+
),
66+
]);
67+
}

0 commit comments

Comments
 (0)