[internal] Tweak build system to better support unit tests in Zig

This commit is contained in:
Jarred Sumner
2021-10-24 06:18:42 -07:00
parent 1f7af3754d
commit 449c8b5f36
11 changed files with 146 additions and 19 deletions

33
.vscode/launch.json vendored
View File

@@ -37,6 +37,15 @@
"cwd": "/tmp/",
"console": "internalConsole"
},
{
"type": "lldb",
"request": "launch",
"name": "bun routes",
"program": "${workspaceFolder}/packages/debug-bun-cli-darwin-x64/bin/bun-debug",
"args": [],
"cwd": "${workspaceFolder}/integration/apps/routing",
"console": "internalConsole"
},
{
"type": "lldb",
"request": "launch",
@@ -174,10 +183,28 @@
{
"type": "lldb",
"request": "launch",
"name": "Fixture serve",
"name": "Dazzle serve",
"program": "${workspaceFolder}/packages/debug-bun-cli-darwin-x64/bin/bun-debug",
"args": [],
"cwd": "${workspaceFolder}/src/test/fixtures",
"args": ["--origin=http://localhost:5000", "--disable-hmr"],
"cwd": "/Users/jarred/Build/lattice/apps/dazzle",
"console": "internalConsole"
},
{
"type": "lldb",
"request": "launch",
"name": "Bun",
"program": "${workspaceFolder}/packages/debug-bun-cli-darwin-x64/bin/bun-debug",
"args": ["bun", "--use=next"],
"cwd": "/Users/jarred/Build/lattice/apps/dazzle",
"console": "internalConsole"
},
{
"type": "lldb",
"request": "launch",
"name": "unicode check",
"args": ["--disable-hmr"],
"program": "${workspaceFolder}/packages/debug-bun-cli-darwin-x64/bin/bun-debug",
"cwd": "/Users/jarred/Build/app994",
"console": "internalConsole"
},

21
.vscode/settings.json vendored
View File

@@ -3,15 +3,16 @@
"search.quickOpen.includeSymbols": false,
"search.seedWithNearestWord": true,
"search.smartCase": true,
"search.exclude": {
"src/javascript/jsc/WebKit/**/*": true
},
"search.exclude": {},
"search.followSymlinks": false,
"search.useIgnoreFiles": true,
"zig.buildOnSave": false,
"[zig]": {
"editor.defaultFormatter": "tiehuis.zig"
},
"lldb.verboseLogging": true,
"zig.beforeDebugCmd": "make build-unit ${file} ${filter} ${bin}",
"zig.testCmd": "make test ${file} ${filter} ${bin}",
"files.exclude": {
"**/.git": true,
"**/.svn": true,
@@ -19,8 +20,20 @@
"**/CVS": true,
"**/.DS_Store": true,
"**/Thumbs.db": true,
"**/*.xcworkspacedata": true,
"**/*.xcscheme": true,
"**/*.pem": true,
"**/*.xcodeproj": true,
"integration/snapshots": true,
"integration/snapshots-no-hmr": true
"integration/snapshots-no-hmr": true,
"src/javascript/jsc/WebKit": true,
"src/deps/libarchive": true,
"src/deps/mimalloc": true,
"src/deps/s2n-tls": true,
"src/deps/openssl": true,
"src/deps/zlib": true,
"integration/snippets/package-json-exports/_node_modules_copy": true
},
"C_Cpp.files.exclude": {
"**/.vscode": true,

View File

@@ -703,7 +703,7 @@ build-unit:
-femit-bin=zig-out/bin/$(testname) \
-fcompiler-rt \
-lc -lc++ \
--cache-dir /tmp/zig-cache-bun-$(testname)-$(basename $(firstword $(testfilter))) \
--cache-dir /tmp/zig-cache-bun-$(testname)-$(basename $(lastword $(testfilter))) \
-fallow-shlib-undefined \
-L$(LIBCRYPTO_PREFIX_DIR)/lib \
-lcrypto -lssl \

View File

@@ -128,13 +128,19 @@ pub fn build(b: *std.build.Builder) !void {
exe.setOutputDir(output_dir);
var cwd_dir = std.fs.cwd();
const runtime_hash = std.hash.Wyhash.hash(0, @embedFile("./src/runtime.out.js"));
var runtime_out_file = try std.fs.cwd().openFile("src/runtime.out.js", .{ .read = true });
const runtime_hash = std.hash.Wyhash.hash(
0,
try runtime_out_file.readToEndAlloc(b.allocator, try runtime_out_file.getEndPos()),
);
const runtime_version_file = std.fs.cwd().openFile("src/runtime.version", .{ .write = true }) catch unreachable;
runtime_version_file.writer().print("{x}", .{runtime_hash}) catch unreachable;
defer runtime_version_file.close();
const fallback_hash = std.hash.Wyhash.hash(0, @embedFile("./src/fallback.out.js"));
var fallback_out_file = try std.fs.cwd().openFile("src/fallback.out.js", .{ .read = true });
const fallback_hash = std.hash.Wyhash.hash(
0,
try fallback_out_file.readToEndAlloc(b.allocator, try fallback_out_file.getEndPos()),
);
const fallback_version_file = std.fs.cwd().openFile("src/fallback.version", .{ .write = true }) catch unreachable;
fallback_version_file.writer().print("{x}", .{fallback_hash}) catch unreachable;
defer fallback_version_file.close();

View File

@@ -0,0 +1,23 @@
[
"/cjs-transform-shouldnt-have-static-imports-in-cjs-function.js",
"/bundled-entry-point.js",
"/export.js",
"/type-only-imports.ts",
"/global-is-remapped-to-globalThis.js",
"/multiple-imports.js",
"/ts-fallback-rewrite-works.js",
"/tsx-fallback-rewrite-works.js",
"/lodash-regexp.js",
"/unicode-identifiers.js",
"/string-escapes.js",
"/package-json-exports/index.js",
"/array-args-with-default-values.js",
"/forbid-in-is-correct.js",
"/code-simplification-neql-define.js",
"/spread_with_key.tsx",
"/styledcomponents-output.js",
"/void-shouldnt-delete-call-expressions.js",
"/custom-emotion-jsx/file.jsx",
"/react-context-value-func.tsx",
"/latin1-chars-in-regexp.js"
]

View File

@@ -117,6 +117,52 @@ function generateRangeTable(codePoints) {
return lines.join("\n");
}
function generateBigSwitchStatement(codePoints) {
let lines = [];
let index = 0;
let latinOffset = 0;
while (latinOffset < codePoints.length && codePoints[latinOffset] <= 0xff) {
latinOffset++;
}
lines.push(`return switch(codepoint) {`);
// 16-bit code points
while (index < codePoints.length && codePoints[index] < 0x1000) {
let start = codePoints[index];
index++;
while (
index < codePoints.length &&
codePoints[index] < 0x1000 &&
codePoints[index] === codePoints[index - 1] + 1
) {
index++;
}
let end = codePoints[index - 1];
lines.push(`0x${start.toString(16)}...0x${end.toString(16)},`);
}
// 32-bit code points
while (index < codePoints.length) {
let start = codePoints[index];
index++;
while (
index < codePoints.length &&
codePoints[index] === codePoints[index - 1] + 1
) {
index++;
}
let end = codePoints[index - 1];
lines.push(` 0x${start.toString(16)}...0x${end.toString(16)},`);
}
lines.push(` => true,
else => false
};`);
return lines.join("\n");
}
fs.writeFileSync(
path.join(__dirname, "..", "src", "js_lexer", "unicode.zig"),
`// This file was automatically generated by ${path.basename(
@@ -134,5 +180,15 @@ pub const id_continue = ${generateRangeTable(idContinueES5OrESNext)}
pub const printable_id_start = ${generateRangeTable(idStartESNext)}
pub const printable_id_continue = ${generateRangeTable(idContinueESNext)}
pub fn isIdentifierStart(comptime Codepoint: type, codepoint: Codepoint) bool{
${generateBigSwitchStatement(idStartES5OrESNext)}
}
pub fn isIdentifierContinue(comptime Codepoint: type, codepoint: Codepoint) bool{
${generateBigSwitchStatement(idContinueES5OrESNext)}
}
`
);

View File

@@ -32,7 +32,7 @@
".env": "NEXT_PUBLIC_",
"defaults": {
"process.env.__NEXT_TRAILING_SLASH": "false",
"process.env.NODE_ENV": "\"development\"",
"process.env.NODE_ENV": "'development'",
"process.env.__NEXT_ROUTER_BASEPATH": "''",
"process.env.__NEXT_SCROLL_RESTORATION": "false",
"process.env.__NEXT_I18N_SUPPORT": "false",

View File

@@ -391,7 +391,7 @@ export async function render({
var query = Object.assign({}, route.query);
// These are reversed in our Router versus Next.js...mostly due to personal preference.
const pathname = "/" + route.name;
const pathname = route.name;
var asPath = route.pathname;
const pages = {};

View File

@@ -52,7 +52,6 @@ addEventListener("fetch", async (event: FetchEvent) => {
appRoute = null;
}
const appStylesheets = (Bun.getImportedStyles() as string[]).slice();
event.respondWith(
render({
route,

View File

@@ -10,12 +10,15 @@ import { parse, print } from "graphql";
// 6. Replace the TemplateLiteral with the default identifier from the injected import
let artifactDirectory: string = `__generated__`;
if (process.env.RELAY_ARTIFACT_DIRECTORY) {
artifactDirectory = process.env.RELAY_ARTIFACT_DIRECTORY;
const { RELAY_ARTIFACT_DIRECTORY, BUN_MACRO_RELAY_ARTIFACT_DIRECTORY } =
Bun.env;
if (RELAY_ARTIFACT_DIRECTORY) {
artifactDirectory = RELAY_ARTIFACT_DIRECTORY;
}
if (process.env.BUN_MACRO_RELAY_ARTIFACT_DIRECTORY) {
artifactDirectory = process.env.BUN_MACRO_RELAY_ARTIFACT_DIRECTORY;
if (BUN_MACRO_RELAY_ARTIFACT_DIRECTORY) {
artifactDirectory = BUN_MACRO_RELAY_ARTIFACT_DIRECTORY;
}
// TODO: platform-independent path cleaning