getting rid of old cruft from imported p2 lib
This commit is contained in:
parent
585fa3d7df
commit
eae1737b66
File diff suppressed because it is too large
Load Diff
|
|
@ -1,117 +0,0 @@
|
|||
//! Frozen pre-fetchSub implementation for queue-benchmark.zig only.
|
||||
//! Do not use as a production queue or update alongside the live implementation.
|
||||
const std = @import("std");
|
||||
|
||||
pub const PackedState = packed struct(u32) {
|
||||
remaining_items: u24 = 0, // Unclaimed entries.
|
||||
active_readers: u8 = 0, // Consumers copying descriptors.
|
||||
};
|
||||
|
||||
/// Single-producer, multiple-consumer batch mailbox.
|
||||
///
|
||||
/// Keep the mailbox at a stable address once shared.
|
||||
/// Values are copied
|
||||
///
|
||||
/// usage:
|
||||
///
|
||||
/// producer:
|
||||
/// queue.push(.{.x = 4});
|
||||
///
|
||||
/// consumers:
|
||||
/// while(alive) {
|
||||
/// if(queue.tryTake())|value|
|
||||
/// {
|
||||
/// self.dowork(value);
|
||||
/// }
|
||||
/// else
|
||||
/// {
|
||||
/// chillout();
|
||||
/// }
|
||||
/// }
|
||||
///
|
||||
pub fn CommitQueue(comptime T: type) type {
|
||||
return struct {
|
||||
allocator: std.mem.Allocator,
|
||||
state: std.atomic.Value(PackedState) = .init(.{}),
|
||||
|
||||
active: std.ArrayList(T) = .empty,
|
||||
back: std.ArrayList(T) = .empty,
|
||||
|
||||
pub fn init(allocator: std.mem.Allocator) @This() {
|
||||
return .{ .allocator = allocator };
|
||||
}
|
||||
|
||||
pub fn deinit(self: *@This()) void {
|
||||
while (!self.canSubmit()) std.atomic.spinLoopHint();
|
||||
|
||||
self.active.deinit(self.allocator);
|
||||
self.back.deinit(self.allocator);
|
||||
}
|
||||
|
||||
/// Producer only. Grows the private backbuffer as needed.
|
||||
pub fn push(self: *@This(), item: T) !void {
|
||||
if (self.back.items.len == std.math.maxInt(u24)) return error.BatchFull;
|
||||
try self.back.append(self.allocator, item);
|
||||
}
|
||||
|
||||
/// Consumers. Null means the batch is empty or all 255 reader pins are in use.
|
||||
pub fn tryTake(self: *@This()) ?T {
|
||||
var s = self.state.load(.monotonic);
|
||||
|
||||
while (true) {
|
||||
if (s.remaining_items == 0 or s.active_readers == std.math.maxInt(u8))
|
||||
return null;
|
||||
|
||||
// Claim one entry and pin its batch atomically.
|
||||
var desired = s;
|
||||
desired.remaining_items -= 1;
|
||||
desired.active_readers += 1;
|
||||
|
||||
if (self.state.cmpxchgWeak(s, desired, .acquire, .monotonic)) |observed| {
|
||||
s = observed;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Read metadata only after successfully pinning.
|
||||
const index = self.active.items.len - @as(usize, s.remaining_items);
|
||||
const item = self.active.items[index];
|
||||
|
||||
self.releaseReader();
|
||||
return item;
|
||||
}
|
||||
}
|
||||
|
||||
/// Historical release loop, intentionally frozen for A/B measurement.
|
||||
fn releaseReader(self: *@This()) void {
|
||||
var s = self.state.load(.monotonic);
|
||||
var bailOut: u32 = 100000000;
|
||||
while (bailOut > 0) : (bailOut -= 1) {
|
||||
var desired = s;
|
||||
desired.active_readers -= 1;
|
||||
if (self.state.cmpxchgWeak(s, desired, .release, .monotonic)) |observed| {
|
||||
s = observed;
|
||||
continue;
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn canSubmit(self: *const @This()) bool {
|
||||
const state = self.state.load(.acquire);
|
||||
return state.remaining_items == 0 and state.active_readers == 0;
|
||||
}
|
||||
|
||||
/// Must only be called Producer only.
|
||||
/// publishes the backbuffer to all consumers,
|
||||
pub fn submit(self: *@This()) void {
|
||||
while (!self.canSubmit()) {
|
||||
std.atomic.spinLoopHint();
|
||||
}
|
||||
|
||||
std.mem.swap(@TypeOf(self.active), &self.active, &self.back);
|
||||
|
||||
self.back.clearRetainingCapacity();
|
||||
self.state.store(.{ .remaining_items = @intCast(self.active.items.len) }, .release);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
@ -1,203 +0,0 @@
|
|||
//! One producer, N consumers. Run through `zig build bench-queues` in lib/p2.
|
||||
const std = @import("std");
|
||||
const CommitQueue = @import("structures/spmc-submission-queue.zig").CommitQueue;
|
||||
const ConcurrentQueue = @import("structures/concurrent-queue.zig").ConcurrentQueueU;
|
||||
const CasCommitQueue = @import("queue-benchmark-cas-baseline.zig").CommitQueue;
|
||||
const Kind = enum { commit, concurrent, commit_cas };
|
||||
|
||||
fn Bench(comptime kind: Kind, comptime wordCount: usize, comptime work: usize) type {
|
||||
return struct {
|
||||
const Item = struct { words: [wordCount]u64 };
|
||||
const Queue = switch (kind) {
|
||||
.commit => CommitQueue(Item, .{ .ChunkSize = 256 }),
|
||||
.commit_cas => CasCommitQueue(Item),
|
||||
.concurrent => ConcurrentQueue(Item),
|
||||
};
|
||||
const Worker = struct {
|
||||
queue: *Queue,
|
||||
gate: *std.Io.Event,
|
||||
ready: *std.atomic.Value(usize),
|
||||
producerDone: *std.atomic.Value(bool),
|
||||
io: std.Io,
|
||||
count: u64 align(64) = 0,
|
||||
sum: u64 = 0,
|
||||
xor: u64 = 0,
|
||||
digest: u64 = 0,
|
||||
bad: bool = false,
|
||||
|
||||
fn run(self: *@This()) void {
|
||||
_ = self.ready.fetchAdd(1, .release);
|
||||
self.gate.waitUncancelable(self.io);
|
||||
var output: [256]Item = undefined;
|
||||
var draining = false;
|
||||
while (true) {
|
||||
const items: []const Item = if (kind == .commit)
|
||||
self.queue.maybeTake(&output)
|
||||
else blk: {
|
||||
const item = if (kind == .commit_cas) self.queue.tryTake() else self.queue.pop();
|
||||
if (item) |value| {
|
||||
output[0] = value;
|
||||
break :blk output[0..1];
|
||||
}
|
||||
break :blk &.{};
|
||||
};
|
||||
for (items) |item| {
|
||||
const id = item.words[0];
|
||||
self.count += 1;
|
||||
self.sum +%= id;
|
||||
self.xor ^= id;
|
||||
for (item.words[1..], 1..) |value, lane| {
|
||||
if (value != id ^ @as(u64, @intCast(lane))) self.bad = true;
|
||||
}
|
||||
var result = id;
|
||||
for (0..work) |_| result = (result ^ (result >> 13)) *% 0x9e3779b97f4a7c15;
|
||||
self.digest +%= result;
|
||||
}
|
||||
if (items.len == 0) {
|
||||
if (draining) return;
|
||||
// After acquiring completion, recheck the queue before
|
||||
// exiting: the first empty observation may predate publication.
|
||||
draining = self.producerDone.load(.acquire);
|
||||
std.atomic.spinLoopHint();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
fn makeItem(id: u64) Item {
|
||||
var item: Item = undefined;
|
||||
for (&item.words, 0..) |*value, lane| value.* = id ^ @as(u64, @intCast(lane));
|
||||
return item;
|
||||
}
|
||||
|
||||
fn flush(queue: *Queue) void {
|
||||
if (kind != .concurrent) queue.submit();
|
||||
}
|
||||
|
||||
fn measure(gpa: std.mem.Allocator, io: std.Io, consumers: usize, batch: usize, milliseconds: i64) !f64 {
|
||||
const capacity = @max(batch, consumers);
|
||||
var queue = if (kind != .concurrent) Queue.init(gpa) else try Queue.initCapacity(gpa, capacity * 2);
|
||||
defer if (kind != .concurrent) queue.deinit() else queue.deinit(gpa);
|
||||
if (kind != .concurrent) {
|
||||
try queue.active.ensureTotalCapacity(gpa, capacity);
|
||||
try queue.back.ensureTotalCapacity(gpa, capacity);
|
||||
}
|
||||
var gate: std.Io.Event = .unset;
|
||||
var ready: std.atomic.Value(usize) = .init(0);
|
||||
var producerDone: std.atomic.Value(bool) = .init(false);
|
||||
var workers: [8]Worker = undefined;
|
||||
var threads: [8]std.Thread = undefined;
|
||||
var spawned: usize = 0;
|
||||
// Even a partial spawn must release and shut down existing workers.
|
||||
errdefer {
|
||||
gate.set(io);
|
||||
flush(&queue);
|
||||
producerDone.store(true, .release);
|
||||
for (threads[0..spawned]) |thread| thread.join();
|
||||
}
|
||||
for (0..consumers) |i| {
|
||||
workers[i] = .{ .queue = &queue, .gate = &gate, .ready = &ready, .producerDone = &producerDone, .io = io };
|
||||
threads[i] = try std.Thread.spawn(.{}, Worker.run, .{&workers[i]});
|
||||
spawned += 1;
|
||||
}
|
||||
while (ready.load(.acquire) != consumers) std.atomic.spinLoopHint();
|
||||
const begin = std.Io.Timestamp.now(io, .awake);
|
||||
gate.set(io);
|
||||
var produced: u64 = 0;
|
||||
var expectedSum: u64 = 0;
|
||||
var expectedXor: u64 = 0;
|
||||
var batches: usize = 0;
|
||||
while (true) {
|
||||
for (0..batch) |_| {
|
||||
try queue.push(makeItem(produced));
|
||||
expectedSum +%= produced;
|
||||
expectedXor ^= produced;
|
||||
produced += 1;
|
||||
}
|
||||
flush(&queue);
|
||||
batches += 1;
|
||||
// Amortize clock overhead for small batches; check every large batch
|
||||
// so a 65K batch does not force millions of extra items per sample.
|
||||
const clockInterval: usize = if (batch >= 10000) 1 else 64;
|
||||
if (batches % clockInterval == 0 and begin.durationTo(std.Io.Timestamp.now(io, .awake)).toMilliseconds() >= milliseconds) break;
|
||||
}
|
||||
producerDone.store(true, .release);
|
||||
for (threads[0..consumers]) |thread| thread.join();
|
||||
spawned = 0;
|
||||
const elapsed = begin.durationTo(std.Io.Timestamp.now(io, .awake)).toNanoseconds();
|
||||
var count: u64 = 0;
|
||||
var sum: u64 = 0;
|
||||
var xor: u64 = 0;
|
||||
for (workers[0..consumers]) |*worker| {
|
||||
if (worker.bad) return error.CorruptPayload;
|
||||
count += worker.count;
|
||||
sum +%= worker.sum;
|
||||
xor ^= worker.xor;
|
||||
std.mem.doNotOptimizeAway(worker.digest);
|
||||
}
|
||||
if (count != produced or sum != expectedSum or xor != expectedXor) return error.IncorrectDelivery;
|
||||
return @as(f64, @floatFromInt(count)) * 1000.0 / @as(f64, @floatFromInt(elapsed));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
fn scenario(comptime words: usize, comptime work: usize, init: std.process.Init, consumers: usize, batch: usize, sampleMs: i64, compareCas: bool) !void {
|
||||
if (compareCas) return scenarioAgainst(words, work, .commit_cas, init, consumers, batch, sampleMs);
|
||||
return scenarioAgainst(words, work, .concurrent, init, consumers, batch, sampleMs);
|
||||
}
|
||||
|
||||
fn scenarioAgainst(comptime words: usize, comptime work: usize, comptime other: Kind, init: std.process.Init, consumers: usize, batch: usize, sampleMs: i64) !void {
|
||||
const S = Bench(.commit, words, work);
|
||||
const C = Bench(other, words, work);
|
||||
_ = try S.measure(init.gpa, init.io, consumers, batch, 100);
|
||||
_ = try C.measure(init.gpa, init.io, consumers, batch, 100);
|
||||
for (0..3) |sample| {
|
||||
var s: f64 = undefined;
|
||||
var c: f64 = undefined;
|
||||
if (sample % 2 == 0) {
|
||||
s = try S.measure(init.gpa, init.io, consumers, batch, sampleMs);
|
||||
c = try C.measure(init.gpa, init.io, consumers, batch, sampleMs);
|
||||
} else {
|
||||
c = try C.measure(init.gpa, init.io, consumers, batch, sampleMs);
|
||||
s = try S.measure(init.gpa, init.io, consumers, batch, sampleMs);
|
||||
}
|
||||
std.debug.print("{d},{d},{d},{d},{d},commit,{d:.6}\n", .{ consumers, batch, words * 8, work, sample, s });
|
||||
std.debug.print("{d},{d},{d},{d},{d},{s},{d:.6}\n", .{ consumers, batch, words * 8, work, sample, @tagName(other), c });
|
||||
}
|
||||
}
|
||||
|
||||
pub fn main(init: std.process.Init) !void {
|
||||
var sampleMs: i64 = 400;
|
||||
var minConsumers: usize = 1;
|
||||
var largeBatches = false;
|
||||
var compareCas = false;
|
||||
const args = try init.minimal.args.toSlice(init.arena.allocator());
|
||||
for (args[1..]) |arg| {
|
||||
if (std.mem.startsWith(u8, arg, "--sample-ms=")) {
|
||||
sampleMs = try std.fmt.parseInt(i64, arg["--sample-ms=".len..], 10);
|
||||
if (sampleMs < 1) return error.InvalidSampleDuration;
|
||||
} else if (std.mem.startsWith(u8, arg, "--min-consumers=")) {
|
||||
minConsumers = try std.fmt.parseInt(usize, arg["--min-consumers=".len..], 10);
|
||||
if (minConsumers < 1 or minConsumers > 8) return error.InvalidConsumerCount;
|
||||
} else if (std.mem.eql(u8, arg, "--large-batches")) {
|
||||
largeBatches = true;
|
||||
} else if (std.mem.eql(u8, arg, "--compare-cas")) {
|
||||
compareCas = true;
|
||||
} else return error.UnknownArgument;
|
||||
}
|
||||
std.debug.print("consumers,batch,payload_bytes,work_iterations,sample,queue,million_items_per_second\n", .{});
|
||||
for ([_]usize{ 1, 2, 4, 8 }) |consumers| {
|
||||
if (consumers < minConsumers) continue;
|
||||
if (largeBatches) {
|
||||
for ([_]usize{ 10000, 65536 }) |batch| {
|
||||
try scenario(2, 0, init, consumers, batch, sampleMs, compareCas);
|
||||
try scenario(32, 0, init, consumers, batch, sampleMs, compareCas);
|
||||
try scenario(2, 256, init, consumers, batch, sampleMs, compareCas);
|
||||
}
|
||||
} else {
|
||||
for ([_]usize{ 1, 64, 1024 }) |batch| try scenario(2, 0, init, consumers, batch, sampleMs, compareCas);
|
||||
try scenario(32, 0, init, consumers, 256, sampleMs, compareCas);
|
||||
try scenario(2, 256, init, consumers, 256, sampleMs, compareCas);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,43 +0,0 @@
|
|||
const Engine = struct {};
|
||||
|
||||
pub fn println(comptime fmt: []const u8, args: anytype) void {
|
||||
std.debug.print(fmt ++ "\n", .{args});
|
||||
}
|
||||
|
||||
pub fn printlns(comptime fmt: []const u8) void {
|
||||
std.debug.print(fmt ++ "\n", .{});
|
||||
}
|
||||
|
||||
const MyEngineSystem = struct {
|
||||
pub fn init(self: *@This(), engineContext: *Engine) !void {
|
||||
_ = self;
|
||||
_ = engineContext;
|
||||
println("initialized", .{});
|
||||
}
|
||||
|
||||
pub fn tick(self: *@This(), dt: f32) void {
|
||||
_ = self;
|
||||
printlns("tick!");
|
||||
_ = dt;
|
||||
}
|
||||
|
||||
pub fn deinit(self: *@This()) void {
|
||||
_ = self;
|
||||
|
||||
printlns("deinitialized");
|
||||
}
|
||||
};
|
||||
|
||||
const Vec2 = struct {
|
||||
x: f32 = 0,
|
||||
y: f32 = 0,
|
||||
};
|
||||
|
||||
const Vec2d = struct {
|
||||
x: f32 = 0,
|
||||
y: f32 = 0,
|
||||
};
|
||||
|
||||
test "testing" {}
|
||||
|
||||
const std = @import("std");
|
||||
|
|
@ -1,59 +0,0 @@
|
|||
# P2 VS Code Environment
|
||||
|
||||
This directory holds the repo-local definition for a pinned/custom VS Code setup.
|
||||
It is meant to live under `lib/p2`, while installing generated launcher files at
|
||||
the workspace root.
|
||||
|
||||
## Layout
|
||||
|
||||
- `extensions/`: put vendored `.vsix` files here.
|
||||
- `settings/settings.json`: settings copied into the isolated VS Code user data.
|
||||
- `install.sh`: installs the environment into the workspace root.
|
||||
|
||||
## Install
|
||||
|
||||
From `lib/p2`:
|
||||
|
||||
```sh
|
||||
./tools/vscode-env/install.sh
|
||||
```
|
||||
|
||||
By default this creates:
|
||||
|
||||
- `<workspace-root>/.vscode-p2/`
|
||||
- `<workspace-root>/.bin/p2-code`
|
||||
- `<workspace-root>/.bin/p2-code.bat`
|
||||
- `<workspace-root>/p2.code-workspace`
|
||||
|
||||
Run the environment with:
|
||||
|
||||
```sh
|
||||
<workspace-root>/.bin/p2-code
|
||||
```
|
||||
|
||||
The wrapper uses an isolated `--user-data-dir` and `--extensions-dir`, so custom
|
||||
extensions do not affect your normal VS Code profile.
|
||||
|
||||
On Windows, run:
|
||||
|
||||
```bat
|
||||
<workspace-root>\.bin\p2-code.bat
|
||||
```
|
||||
|
||||
## Vendored Extensions
|
||||
|
||||
Drop custom or forked extensions into `extensions/` as `.vsix` files, then rerun
|
||||
`install.sh`. The installer will install every `.vsix` it finds into the isolated
|
||||
extension directory.
|
||||
|
||||
For example:
|
||||
|
||||
```sh
|
||||
cp ~/dev/vscode-zig/ziglang.vscode-zig-0.6.18-custom.vsix tools/vscode-env/extensions/
|
||||
./tools/vscode-env/install.sh
|
||||
```
|
||||
|
||||
Custom language extensions can live next to the tool they support, such as
|
||||
`tools/riblang/vscode/`, and publish a packaged `.vsix` into this directory.
|
||||
That keeps the source near the language implementation while keeping the editor
|
||||
environment installer simple and pinned.
|
||||
|
|
@ -1 +0,0 @@
|
|||
|
||||
|
|
@ -1,137 +0,0 @@
|
|||
@echo off
|
||||
setlocal EnableExtensions EnableDelayedExpansion
|
||||
|
||||
set "SCRIPT_DIR=%~dp0"
|
||||
if "%SCRIPT_DIR:~-1%"=="\" set "SCRIPT_DIR=%SCRIPT_DIR:~0,-1%"
|
||||
for %%I in ("%SCRIPT_DIR%\..\..") do set "P2_DIR=%%~fI"
|
||||
|
||||
set "WORKSPACE_ROOT="
|
||||
set "CODE_BIN=code"
|
||||
|
||||
:parse_args
|
||||
if "%~1"=="" goto after_args
|
||||
if /I "%~1"=="--workspace-root" (
|
||||
if "%~2"=="" (
|
||||
echo missing value for --workspace-root 1>&2
|
||||
exit /b 2
|
||||
)
|
||||
set "WORKSPACE_ROOT=%~2"
|
||||
shift
|
||||
shift
|
||||
goto parse_args
|
||||
)
|
||||
if /I "%~1"=="--code-bin" (
|
||||
if "%~2"=="" (
|
||||
echo missing value for --code-bin 1>&2
|
||||
exit /b 2
|
||||
)
|
||||
set "CODE_BIN=%~2"
|
||||
shift
|
||||
shift
|
||||
goto parse_args
|
||||
)
|
||||
if /I "%~1"=="-h" goto usage
|
||||
if /I "%~1"=="--help" goto usage
|
||||
|
||||
echo unknown argument: %~1 1>&2
|
||||
goto usage_error
|
||||
|
||||
:after_args
|
||||
if "%WORKSPACE_ROOT%"=="" (
|
||||
for /f "usebackq delims=" %%I in (`git -C "%P2_DIR%" rev-parse --show-toplevel 2^>nul`) do set "WORKSPACE_ROOT=%%I"
|
||||
)
|
||||
if "%WORKSPACE_ROOT%"=="" set "WORKSPACE_ROOT=%P2_DIR%"
|
||||
for %%I in ("%WORKSPACE_ROOT%") do set "WORKSPACE_ROOT=%%~fI"
|
||||
|
||||
set "ENV_DIR=%WORKSPACE_ROOT%\.vscode-p2"
|
||||
set "BIN_DIR=%WORKSPACE_ROOT%\.bin"
|
||||
set "USER_DATA_DIR=%ENV_DIR%\user-data"
|
||||
set "EXTENSIONS_DIR=%ENV_DIR%\extensions"
|
||||
set "WORKSPACE_FILE=%WORKSPACE_ROOT%\p2.code-workspace"
|
||||
|
||||
mkdir "%BIN_DIR%" 2>nul
|
||||
mkdir "%USER_DATA_DIR%\User" 2>nul
|
||||
mkdir "%EXTENSIONS_DIR%" 2>nul
|
||||
copy /Y "%SCRIPT_DIR%\settings\settings.json" "%USER_DATA_DIR%\User\settings.json" >nul
|
||||
|
||||
(
|
||||
echo @echo off
|
||||
echo setlocal
|
||||
echo.
|
||||
echo if "%%CODE_BIN%%"=="" ^(
|
||||
echo set "CODE_BIN=%CODE_BIN%"
|
||||
echo ^)
|
||||
echo.
|
||||
echo set "WORKSPACE_ROOT=%WORKSPACE_ROOT%"
|
||||
echo set "ENV_DIR=%%WORKSPACE_ROOT%%\.vscode-p2"
|
||||
echo.
|
||||
echo "%%CODE_BIN%%" ^^
|
||||
echo --user-data-dir "%%ENV_DIR%%\user-data" ^^
|
||||
echo --extensions-dir "%%ENV_DIR%%\extensions" ^^
|
||||
echo "%%WORKSPACE_ROOT%%\p2.code-workspace" ^^
|
||||
echo %%*
|
||||
) > "%BIN_DIR%\p2-code.bat"
|
||||
|
||||
set "P2_REL=%P2_DIR%"
|
||||
set "P2_REL=!P2_REL:%WORKSPACE_ROOT%=!"
|
||||
if "!P2_REL:~0,1!"=="\" set "P2_REL=!P2_REL:~1!"
|
||||
set "P2_REL=!P2_REL:\=/!"
|
||||
|
||||
(
|
||||
echo {
|
||||
echo "folders": [
|
||||
echo {
|
||||
echo "name": "snow",
|
||||
echo "path": "."
|
||||
echo },
|
||||
echo {
|
||||
echo "name": "p2",
|
||||
echo "path": "!P2_REL!"
|
||||
echo }
|
||||
echo ],
|
||||
echo "settings": {
|
||||
echo "editor.foldingStrategy": "auto"
|
||||
echo }
|
||||
echo }
|
||||
) > "%WORKSPACE_FILE%"
|
||||
|
||||
where "%CODE_BIN%" >nul 2>nul
|
||||
if errorlevel 1 (
|
||||
echo VS Code binary not found: %CODE_BIN% 1>&2
|
||||
echo Skipping .vsix installation. Re-run with --code-bin PATH when available. 1>&2
|
||||
) else (
|
||||
set "FOUND_VSIX=0"
|
||||
for %%F in ("%SCRIPT_DIR%\extensions\*.vsix") do (
|
||||
if exist "%%~fF" (
|
||||
set "FOUND_VSIX=1"
|
||||
"%CODE_BIN%" --extensions-dir "%EXTENSIONS_DIR%" --install-extension "%%~fF"
|
||||
)
|
||||
)
|
||||
if "!FOUND_VSIX!"=="0" echo No vendored .vsix files found in %SCRIPT_DIR%\extensions
|
||||
)
|
||||
|
||||
echo Installed P2 VS Code environment:
|
||||
echo windows: %BIN_DIR%\p2-code.bat
|
||||
echo workspace: %WORKSPACE_FILE%
|
||||
echo user data: %USER_DATA_DIR%
|
||||
echo extensions:%EXTENSIONS_DIR%
|
||||
echo.
|
||||
echo Run:
|
||||
echo %BIN_DIR%\p2-code.bat
|
||||
exit /b 0
|
||||
|
||||
:usage
|
||||
echo Usage: install.bat [--workspace-root PATH] [--code-bin CODE]
|
||||
echo.
|
||||
echo Installs the P2 VS Code environment at the workspace root.
|
||||
echo.
|
||||
echo Options:
|
||||
echo --workspace-root PATH Override the detected Git root.
|
||||
echo --code-bin CODE VS Code binary to use for installing .vsix files.
|
||||
echo -h, --help Show this help.
|
||||
exit /b 0
|
||||
|
||||
:usage_error
|
||||
call :usage
|
||||
exit /b 2
|
||||
|
||||
|
|
@ -1,145 +0,0 @@
|
|||
#!/usr/bin/env sh
|
||||
set -eu
|
||||
|
||||
usage() {
|
||||
cat <<'EOF'
|
||||
Usage: install.sh [--workspace-root PATH] [--code-bin CODE]
|
||||
|
||||
Installs the P2 VS Code environment at the workspace root.
|
||||
|
||||
Options:
|
||||
--workspace-root PATH Override the detected Git root.
|
||||
--code-bin CODE VS Code binary to use for installing .vsix files.
|
||||
-h, --help Show this help.
|
||||
EOF
|
||||
}
|
||||
|
||||
script_dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
|
||||
p2_dir=$(CDPATH= cd -- "$script_dir/../.." && pwd)
|
||||
workspace_root=
|
||||
code_bin=${CODE_BIN:-code}
|
||||
|
||||
while [ "$#" -gt 0 ]; do
|
||||
case "$1" in
|
||||
--workspace-root)
|
||||
[ "$#" -ge 2 ] || {
|
||||
echo "missing value for --workspace-root" >&2
|
||||
exit 2
|
||||
}
|
||||
workspace_root=$2
|
||||
shift 2
|
||||
;;
|
||||
--code-bin)
|
||||
[ "$#" -ge 2 ] || {
|
||||
echo "missing value for --code-bin" >&2
|
||||
exit 2
|
||||
}
|
||||
code_bin=$2
|
||||
shift 2
|
||||
;;
|
||||
-h|--help)
|
||||
usage
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
echo "unknown argument: $1" >&2
|
||||
usage >&2
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ -z "$workspace_root" ]; then
|
||||
workspace_root=$(git -C "$p2_dir" rev-parse --show-toplevel 2>/dev/null || printf '%s\n' "$p2_dir")
|
||||
fi
|
||||
|
||||
workspace_root=$(CDPATH= cd -- "$workspace_root" && pwd)
|
||||
env_dir="$workspace_root/.vscode-p2"
|
||||
bin_dir="$workspace_root/.bin"
|
||||
user_data_dir="$env_dir/user-data"
|
||||
extensions_dir="$env_dir/extensions"
|
||||
workspace_file="$workspace_root/p2.code-workspace"
|
||||
|
||||
mkdir -p "$bin_dir" "$user_data_dir/User" "$extensions_dir"
|
||||
cp "$script_dir/settings/settings.json" "$user_data_dir/User/settings.json"
|
||||
|
||||
cat > "$bin_dir/p2-code" <<EOF
|
||||
#!/usr/bin/env sh
|
||||
set -eu
|
||||
|
||||
code_bin=\${CODE_BIN:-$code_bin}
|
||||
workspace_root=$workspace_root
|
||||
env_dir=\$workspace_root/.vscode-p2
|
||||
|
||||
exec "\$code_bin" \\
|
||||
--user-data-dir "\$env_dir/user-data" \\
|
||||
--extensions-dir "\$env_dir/extensions" \\
|
||||
"\$workspace_root/p2.code-workspace" \\
|
||||
"\$@"
|
||||
EOF
|
||||
chmod +x "$bin_dir/p2-code"
|
||||
|
||||
cat > "$bin_dir/p2-code.bat" <<EOF
|
||||
@echo off
|
||||
setlocal
|
||||
|
||||
if "%CODE_BIN%"=="" (
|
||||
set "CODE_BIN=$code_bin"
|
||||
) else (
|
||||
set "CODE_BIN=%CODE_BIN%"
|
||||
)
|
||||
|
||||
set "WORKSPACE_ROOT=$workspace_root"
|
||||
set "ENV_DIR=%WORKSPACE_ROOT%\\.vscode-p2"
|
||||
|
||||
"%CODE_BIN%" ^
|
||||
--user-data-dir "%ENV_DIR%\\user-data" ^
|
||||
--extensions-dir "%ENV_DIR%\\extensions" ^
|
||||
"%WORKSPACE_ROOT%\\p2.code-workspace" ^
|
||||
%*
|
||||
EOF
|
||||
|
||||
cat > "$workspace_file" <<EOF
|
||||
{
|
||||
"folders": [
|
||||
{
|
||||
"name": "snow",
|
||||
"path": "."
|
||||
},
|
||||
{
|
||||
"name": "p2",
|
||||
"path": "$(realpath --relative-to "$workspace_root" "$p2_dir")"
|
||||
}
|
||||
],
|
||||
"settings": {
|
||||
"editor.foldingStrategy": "auto"
|
||||
}
|
||||
}
|
||||
EOF
|
||||
|
||||
if command -v "$code_bin" >/dev/null 2>&1; then
|
||||
found_vsix=false
|
||||
for vsix in "$script_dir"/extensions/*.vsix; do
|
||||
[ -e "$vsix" ] || continue
|
||||
found_vsix=true
|
||||
"$code_bin" --extensions-dir "$extensions_dir" --install-extension "$vsix"
|
||||
done
|
||||
if [ "$found_vsix" = false ]; then
|
||||
echo "No vendored .vsix files found in $script_dir/extensions"
|
||||
fi
|
||||
else
|
||||
echo "VS Code binary not found: $code_bin" >&2
|
||||
echo "Skipping .vsix installation. Re-run with --code-bin PATH when available." >&2
|
||||
fi
|
||||
|
||||
cat <<EOF
|
||||
Installed P2 VS Code environment:
|
||||
wrapper: $bin_dir/p2-code
|
||||
windows: $bin_dir/p2-code.bat
|
||||
workspace: $workspace_file
|
||||
user data: $user_data_dir
|
||||
extensions:$extensions_dir
|
||||
|
||||
Run:
|
||||
$bin_dir/p2-code
|
||||
EOF
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
{
|
||||
"editor.foldingStrategy": "auto",
|
||||
"extensions.autoCheckUpdates": false,
|
||||
"extensions.autoUpdate": false,
|
||||
"telemetry.telemetryLevel": "off",
|
||||
"zig.path": "zig"
|
||||
}
|
||||
Loading…
Reference in New Issue