Skip to content

Commit

Permalink
Merge branch 'main' into ben/wtf-timer-event-loop
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarred-Sumner committed Dec 22, 2024
2 parents 204edcb + a6ad3b9 commit 95dfb03
Show file tree
Hide file tree
Showing 109 changed files with 6,745 additions and 3,973 deletions.
2 changes: 1 addition & 1 deletion LATEST
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.1.39
1.1.41
16 changes: 13 additions & 3 deletions cmake/targets/BuildBun.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,8 @@ file(GLOB BUN_C_SOURCES ${CONFIGURE_DEPENDS}

if(WIN32)
list(APPEND BUN_C_SOURCES ${CWD}/src/bun.js/bindings/windows/musl-memmem.c)
list(APPEND BUN_CXX_SOURCES ${CWD}/src/bun.js/bindings/windows/rescle.cpp)
list(APPEND BUN_CXX_SOURCES ${CWD}/src/bun.js/bindings/windows/rescle-binding.cpp)
endif()

register_repository(
Expand Down Expand Up @@ -650,19 +652,27 @@ if(WIN32)
set(Bun_VERSION_WITH_TAG ${VERSION})
endif()
set(BUN_ICO_PATH ${CWD}/src/bun.ico)
configure_file(${CWD}/src/bun.ico ${CODEGEN_PATH}/bun.ico COPYONLY)
configure_file(
${CWD}/src/windows-app-info.rc
${CODEGEN_PATH}/windows-app-info.rc
@ONLY
)
list(APPEND BUN_CPP_SOURCES ${CODEGEN_PATH}/windows-app-info.rc)
add_custom_command(
OUTPUT ${CODEGEN_PATH}/windows-app-info.res
COMMAND rc.exe /fo ${CODEGEN_PATH}/windows-app-info.res ${CODEGEN_PATH}/windows-app-info.rc
DEPENDS ${CODEGEN_PATH}/windows-app-info.rc ${CODEGEN_PATH}/bun.ico
COMMENT "Adding Windows resource file ${CODEGEN_PATH}/windows-app-info.res with ico in ${CODEGEN_PATH}/bun.ico"
)
set(WINDOWS_RESOURCES ${CODEGEN_PATH}/windows-app-info.res)
endif()

# --- Executable ---

set(BUN_CPP_OUTPUT ${BUILD_PATH}/${CMAKE_STATIC_LIBRARY_PREFIX}${bun}${CMAKE_STATIC_LIBRARY_SUFFIX})

if(BUN_LINK_ONLY)
add_executable(${bun} ${BUN_CPP_OUTPUT} ${BUN_ZIG_OUTPUT})
add_executable(${bun} ${BUN_CPP_OUTPUT} ${BUN_ZIG_OUTPUT} ${WINDOWS_RESOURCES})
set_target_properties(${bun} PROPERTIES LINKER_LANGUAGE CXX)
target_link_libraries(${bun} PRIVATE ${BUN_CPP_OUTPUT})
elseif(BUN_CPP_ONLY)
Expand All @@ -680,7 +690,7 @@ elseif(BUN_CPP_ONLY)
${BUN_CPP_OUTPUT}
)
else()
add_executable(${bun} ${BUN_CPP_SOURCES})
add_executable(${bun} ${BUN_CPP_SOURCES} ${WINDOWS_RESOURCES})
target_link_libraries(${bun} PRIVATE ${BUN_ZIG_OUTPUT})
endif()

Expand Down
2 changes: 1 addition & 1 deletion cmake/targets/BuildLibDeflate.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ register_repository(
REPOSITORY
ebiggers/libdeflate
COMMIT
9d624d1d8ba82c690d6d6be1d0a961fc5a983ea4
733848901289eca058804ca0737f8796875204c8
)

register_cmake_command(
Expand Down
13 changes: 13 additions & 0 deletions docs/bundler/executables.md
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,19 @@ $ bun build --compile --asset-naming="[name].[ext]" ./index.ts

To trim down the size of the executable a little, pass `--minify` to `bun build --compile`. This uses Bun's minifier to reduce the code size. Overall though, Bun's binary is still way too big and we need to make it smaller.

## Windows-specific flags

When compiling a standalone executable on Windows, there are two platform-specific options that can be used to customize metadata on the generated `.exe` file:

- `--windows-icon=path/to/icon.ico` to customize the executable file icon.
- `--windows-hide-console` to disable the background terminal, which can be used for applications that do not need a TTY.

{% callout %}

These flags currently cannot be used when cross-compiling because they depend on Windows APIs.

{% /callout %}

## Unsupported CLI arguments

Currently, the `--compile` flag can only accept a single entrypoint at a time and does not support the following flags:
Expand Down
3 changes: 3 additions & 0 deletions docs/cli/bun-install.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,15 @@ frozenLockfile = false
dryRun = true

# Install optionalDependencies (default: true)
# Setting this to false is equivalent to the `--omit=optional` CLI argument
optional = true

# Install local devDependencies (default: true)
# Setting this to false is equivalent to the `--omit=dev` CLI argument
dev = true

# Install peerDependencies (default: true)
# Setting this to false is equivalent to the `--omit=peer` CLI argument
peer = true

# Max number of concurrent lifecycle scripts (default: (cpu count or GOMAXPROCS) x2)
Expand Down
14 changes: 14 additions & 0 deletions docs/cli/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,20 @@ $ bun install --frozen-lockfile

For more information on Bun's binary lockfile `bun.lockb`, refer to [Package manager > Lockfile](https://bun.sh/docs/install/lockfile).

## Omitting dependencies

To omit dev, peer, or optional dependencies use the `--omit` flag.

```bash
# Exclude "devDependencies" from the installation. This will apply to the
# root package and workspaces if they exist. Transitive dependencies will
# not have "devDependencies".
$ bun install --omit dev

# Install only dependencies from "dependencies"
$ bun install --omit=dev --omit=peer --omit=optional
```

## Dry run

To perform a dry run (i.e. don't actually install anything):
Expand Down
7 changes: 7 additions & 0 deletions docs/install/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ To install dependencies without allowing changes to lockfile (useful on CI):
$ bun install --frozen-lockfile
```

To exclude dependency types from installing, use `--omit` with `dev`, `optional`, or `peer`:

```bash
# Disable devDependencies and optionalDependencies
$ bun install --omit=dev --omit=optional
```

To perform a dry run (i.e. don't actually install anything):

```bash
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "bun",
"version": "1.1.40",
"version": "1.1.42",
"workspaces": [
"./packages/bun-types"
],
Expand Down
29 changes: 27 additions & 2 deletions src/StandaloneModuleGraph.zig
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,11 @@ pub const StandaloneModuleGraph = struct {
else
std.mem.page_size;

pub fn inject(bytes: []const u8, self_exe: [:0]const u8) bun.FileDescriptor {
pub const InjectOptions = struct {
windows_hide_console: bool = false,
};

pub fn inject(bytes: []const u8, self_exe: [:0]const u8, inject_options: InjectOptions) bun.FileDescriptor {
var buf: bun.PathBuffer = undefined;
var zname: [:0]const u8 = bun.span(bun.fs.FileSystem.instance.tmpname("bun-build", &buf, @as(u64, @bitCast(std.time.milliTimestamp()))) catch |err| {
Output.prettyErrorln("<r><red>error<r><d>:<r> failed to get temporary file name: {s}", .{@errorName(err)});
Expand Down Expand Up @@ -470,7 +474,7 @@ pub const StandaloneModuleGraph = struct {
bun.invalid_fd,
out,
// access_mask
w.SYNCHRONIZE | w.GENERIC_WRITE | w.DELETE,
w.SYNCHRONIZE | w.GENERIC_WRITE | w.GENERIC_READ | w.DELETE,
// create disposition
w.FILE_OPEN,
// create options
Expand Down Expand Up @@ -637,6 +641,15 @@ pub const StandaloneModuleGraph = struct {
_ = bun.C.fchmod(cloned_executable_fd.int(), 0o777);
}

if (Environment.isWindows and inject_options.windows_hide_console) {
bun.windows.editWin32BinarySubsystem(.{ .handle = cloned_executable_fd }, .windows_gui) catch |err| {
Output.err(err, "failed to disable console on executable", .{});
cleanup(zname, cloned_executable_fd);

Global.exit(1);
};
}

return cloned_executable_fd;
}

Expand Down Expand Up @@ -664,6 +677,8 @@ pub const StandaloneModuleGraph = struct {
outfile: []const u8,
env: *bun.DotEnv.Loader,
output_format: bun.options.Format,
windows_hide_console: bool,
windows_icon: ?[]const u8,
) !void {
const bytes = try toBytes(allocator, module_prefix, output_files, output_format);
if (bytes.len == 0) return;
Expand All @@ -680,6 +695,7 @@ pub const StandaloneModuleGraph = struct {
Output.err(err, "failed to download cross-compiled bun executable", .{});
Global.exit(1);
},
.{ .windows_hide_console = windows_hide_console },
);
fd.assertKind(.system);

Expand All @@ -704,6 +720,15 @@ pub const StandaloneModuleGraph = struct {

Global.exit(1);
};
_ = bun.sys.close(fd);

if (windows_icon) |icon_utf8| {
var icon_buf: bun.OSPathBuffer = undefined;
const icon = bun.strings.toWPathNormalized(&icon_buf, icon_utf8);
bun.windows.rescle.setIcon(outfile_slice, icon) catch {
Output.warn("Failed to set executable icon", .{});
};
}
return;
}

Expand Down
12 changes: 6 additions & 6 deletions src/bake/DevServer.zig
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ bundles_since_last_error: usize = 0,
framework: bake.Framework,
bundler_options: bake.SplitBundlerOptions,
// Each logical graph gets its own bundler configuration
server_bundler: Bundler,
client_bundler: Bundler,
ssr_bundler: Bundler,
server_bundler: Transpiler,
client_bundler: Transpiler,
ssr_bundler: Transpiler,
/// The log used by all `server_bundler`, `client_bundler` and `ssr_bundler`.
/// Note that it is rarely correct to write messages into it. Instead, associate
/// messages with the IncrementalGraph file or Route using `SerializedFailure`
Expand Down Expand Up @@ -837,7 +837,7 @@ pub fn onSrcRequest(dev: *DevServer, req: *uws.Request, resp: *App.Response) voi
}

const ctx = &dev.vm.rareData().editor_context;
ctx.autoDetectEditor(JSC.VirtualMachine.get().bundler.env);
ctx.autoDetectEditor(JSC.VirtualMachine.get().transpiler.env);
const line: ?[]const u8 = req.header("editor-line");
const column: ?[]const u8 = req.header("editor-column");

Expand Down Expand Up @@ -3431,7 +3431,7 @@ pub const SerializedFailure = struct {
// TODO: syntax highlighted line text + give more context lines
try writeString32(loc.line_text orelse "", w);

// The file is not specified here. Since the bundler runs every file
// The file is not specified here. Since the transpiler runs every file
// in isolation, it would be impossible to reference any other file
// in this Log. Thus, it is not serialized.
} else {
Expand Down Expand Up @@ -4463,7 +4463,7 @@ const OpaqueFileId = FrameworkRouter.OpaqueFileId;
const Log = bun.logger.Log;
const Output = bun.Output;

const Bundler = bun.bundler.Bundler;
const Transpiler = bun.transpiler.Transpiler;
const BundleV2 = bun.bundle_v2.BundleV2;

const Define = bun.options.Define;
Expand Down
2 changes: 1 addition & 1 deletion src/bake/FrameworkRouter.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1129,7 +1129,7 @@ pub const JSFrameworkRouter = struct {
try jsfr.router.scan(
bun.default_allocator,
Type.Index.init(0),
&global.bunVM().bundler.resolver,
&global.bunVM().transpiler.resolver,
InsertionContext.wrap(JSFrameworkRouter, jsfr),
);
if (jsfr.stored_parse_errors.items.len > 0) {
Expand Down
4 changes: 2 additions & 2 deletions src/bake/bake.zig
Original file line number Diff line number Diff line change
Expand Up @@ -544,9 +544,9 @@ pub const Framework = struct {
log: *bun.logger.Log,
mode: Mode,
comptime renderer: Graph,
out: *bun.bundler.Bundler,
out: *bun.transpiler.Transpiler,
) !void {
out.* = try bun.Bundler.init(
out.* = try bun.Transpiler.init(
allocator, // TODO: this is likely a memory leak
log,
std.mem.zeroes(bun.Schema.Api.TransformOptions),
Expand Down
24 changes: 12 additions & 12 deletions src/bake/production.zig
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub fn buildCommand(ctx: bun.CLI.Command.Context) !void {
vm.regular_event_loop.global = vm.global;
vm.jsc = vm.global.vm();
vm.event_loop.ensureWaker();
const b = &vm.bundler;
const b = &vm.transpiler;
vm.preload = ctx.preloads;
vm.argv = ctx.passthrough;
vm.arena = &arena;
Expand Down Expand Up @@ -99,7 +99,7 @@ pub fn buildCommand(ctx: bun.CLI.Command.Context) !void {
pub fn buildWithVm(ctx: bun.CLI.Command.Context, cwd: []const u8, vm: *VirtualMachine) !void {
// Load and evaluate the configuration module
const global = vm.global;
const b = &vm.bundler;
const b = &vm.transpiler;
const allocator = bun.default_allocator;

Output.prettyErrorln("Loading configuration", .{});
Expand Down Expand Up @@ -171,23 +171,23 @@ pub fn buildWithVm(ctx: bun.CLI.Command.Context, cwd: []const u8, vm: *VirtualMa
try loader.map.put("NODE_ENV", "production");
bun.DotEnv.instance = loader;

var client_bundler: bun.bundler.Bundler = undefined;
var server_bundler: bun.bundler.Bundler = undefined;
var ssr_bundler: bun.bundler.Bundler = undefined;
var client_bundler: bun.transpiler.Transpiler = undefined;
var server_bundler: bun.transpiler.Transpiler = undefined;
var ssr_bundler: bun.transpiler.Transpiler = undefined;
try framework.initBundler(allocator, vm.log, .production_static, .server, &server_bundler);
try framework.initBundler(allocator, vm.log, .production_static, .client, &client_bundler);
if (separate_ssr_graph) {
try framework.initBundler(allocator, vm.log, .production_static, .ssr, &ssr_bundler);
}

if (ctx.bundler_options.bake_debug_disable_minify) {
for ([_]*bun.bundler.Bundler{ &client_bundler, &server_bundler, &ssr_bundler }) |bundler| {
bundler.options.minify_syntax = false;
bundler.options.minify_identifiers = false;
bundler.options.minify_whitespace = false;
bundler.resolver.opts.entry_naming = "_bun/[dir]/[name].[hash].[ext]";
bundler.resolver.opts.chunk_naming = "_bun/[dir]/[name].[hash].chunk.[ext]";
bundler.resolver.opts.asset_naming = "_bun/[dir]/[name].[hash].asset.[ext]";
for ([_]*bun.transpiler.Transpiler{ &client_bundler, &server_bundler, &ssr_bundler }) |transpiler| {
transpiler.options.minify_syntax = false;
transpiler.options.minify_identifiers = false;
transpiler.options.minify_whitespace = false;
transpiler.resolver.opts.entry_naming = "_bun/[dir]/[name].[hash].[ext]";
transpiler.resolver.opts.chunk_naming = "_bun/[dir]/[name].[hash].chunk.[ext]";
transpiler.resolver.opts.asset_naming = "_bun/[dir]/[name].[hash].asset.[ext]";
}
}

Expand Down
Loading

0 comments on commit 95dfb03

Please sign in to comment.