Skip to content

Commit

Permalink
New subcommand: bun upgrade. It upgrades bun to the latest version.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarred-Sumner committed Oct 28, 2021
1 parent c7fc080 commit a44cb97
Show file tree
Hide file tree
Showing 25 changed files with 770 additions and 363 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ release/
sign.*.json
packages/debug-*
packages/bun-cli/postinstall.js
packages/bun-*/bin/*
packages/bun-*/bun
packages/bun-*/bun-profile
packages/bun-*/debug-bun
packages/bun-*/*.o
packages/bun-cli/postinstall.js

packages/bun-cli/bin/*
bun-test-scratch
Expand Down
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@
[submodule "src/deps/s2n-tls"]
path = src/deps/s2n-tls
url = https://github.com/Jarred-Sumner/s2n-tls
ignore = dirty
ignore = dirty
232 changes: 49 additions & 183 deletions Makefile

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ All in one fast & easy-to-use tool. Instead of 1,000 node_modules for develo
## Install:

```
# Global install is recommended so bun appears in your $PATH
npm install -g bun-cli
curl -fsSL bun.sh/install | bash
```

## Benchmarks
Expand Down Expand Up @@ -458,9 +457,9 @@ When running bun on an M1 (or Apple Silicon), if you see a message like this:
> [1] 28447 killed bun create next ./test
It most likely means you're running bun's x64 version on Apple Silicon. This happens if `node` (or, rather, `npm`) is running via Rosetta. Rosetta is unable to emulate AVX2 instructions, which Bun indirectly uses.
It most likely means you're running bun's x64 version on Apple Silicon. This happens if bun is running via Rosetta. Rosetta is unable to emulate AVX2 instructions, which Bun indirectly uses.
The fix is to ensure you installed a version of Node built for Apple Silicon and then reinstall `bun-cli`. You can also try to directly install `npm install -g bun-cli-darwin-aarch64`.
The fix is to ensure you installed a version of Bun built for Apple Silicon.
# Reference
Expand Down
2 changes: 1 addition & 1 deletion build-id
Original file line number Diff line number Diff line change
@@ -1 +1 @@
38
39
109 changes: 53 additions & 56 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub fn build(b: *std.build.Builder) !void {
const cwd: []const u8 = b.pathFromRoot(".");
var exe: *std.build.LibExeObjStep = undefined;
var output_dir_buf = std.mem.zeroes([4096]u8);
var bin_label = if (mode == std.builtin.Mode.Debug) "packages/debug-bun-cli-" else "packages/bun-cli-";
var bin_label = if (mode == std.builtin.Mode.Debug) "packages/debug-bun-" else "packages/bun-";

var triplet_buf: [64]u8 = undefined;
var os_tagname = @tagName(target.getOs().tag);
Expand All @@ -60,7 +60,7 @@ pub fn build(b: *std.build.Builder) !void {

var triplet = triplet_buf[0 .. osname.len + cpuArchName.len + 1];

const output_dir_base = try std.fmt.bufPrint(&output_dir_buf, "{s}{s}/bin", .{ bin_label, triplet });
const output_dir_base = try std.fmt.bufPrint(&output_dir_buf, "{s}{s}", .{ bin_label, triplet });
const output_dir = b.pathFromRoot(output_dir_base);
const bun_executable_name = if (mode == std.builtin.Mode.Debug) "bun-debug" else "bun";

Expand Down Expand Up @@ -207,67 +207,64 @@ pub fn build(b: *std.build.Builder) !void {
headers_obj.setMainPkgPath(javascript.main_pkg_path.?);
headers_step.dependOn(&headers_obj.step);


b.default_step.dependOn(&exe.step);
{
var steps = [_]*std.build.LibExeObjStep{ exe, javascript, typings_exe };


var steps = [_]*std.build.LibExeObjStep{ exe, javascript, typings_exe };

// const single_threaded = b.option(bool, "single-threaded", "Build single-threaded") orelse false;

for (steps) |step, i| {
step.linkLibC();
step.linkLibCpp();
addPicoHTTP(
step,
true,
);

step.addObjectFile("src/deps/libJavaScriptCore.a");
step.addObjectFile("src/deps/libWTF.a");
step.addObjectFile("src/deps/libcrypto.a");
step.addObjectFile("src/deps/libbmalloc.a");
step.addObjectFile("src/deps/libarchive.a");
step.addObjectFile("src/deps/libs2n.a");

step.addObjectFile("src/deps/zlib/libz.a");

step.addObjectFile("src/deps/mimalloc/libmimalloc.a");
step.addLibPath("src/deps/mimalloc");
step.addIncludeDir("src/deps/mimalloc");

// step.single_threaded = single_threaded;

if (target.getOsTag() == .macos) {
const homebrew_prefix = comptime if (std.Target.current.cpu.arch == .aarch64)
"/opt/homebrew/"
else
"/usr/local/";

// We must link ICU statically
step.addObjectFile(homebrew_prefix ++ "opt/icu4c/lib/libicudata.a");
step.addObjectFile(homebrew_prefix ++ "opt/icu4c/lib/libicui18n.a");
step.addObjectFile(homebrew_prefix ++ "opt/icu4c/lib/libicuuc.a");
step.addObjectFile(homebrew_prefix ++ "opt/libiconv/lib/libiconv.a");
// icucore is a weird macOS only library
step.linkSystemLibrary("icucore");
step.addLibPath(homebrew_prefix ++ "opt/icu4c/lib");
step.addIncludeDir(homebrew_prefix ++ "opt/icu4c/include");
} else {
step.linkSystemLibrary("icuuc");
step.linkSystemLibrary("icudata");
step.linkSystemLibrary("icui18n");
step.addObjectFile("src/deps/libiconv.a");
}
// const single_threaded = b.option(bool, "single-threaded", "Build single-threaded") orelse false;

for (bindings_files.items) |binding| {
step.addObjectFile(
binding,
for (steps) |step, i| {
step.linkLibC();
step.linkLibCpp();
addPicoHTTP(
step,
true,
);

step.addObjectFile("src/deps/libJavaScriptCore.a");
step.addObjectFile("src/deps/libWTF.a");
step.addObjectFile("src/deps/libcrypto.a");
step.addObjectFile("src/deps/libbmalloc.a");
step.addObjectFile("src/deps/libarchive.a");
step.addObjectFile("src/deps/libs2n.a");

step.addObjectFile("src/deps/zlib/libz.a");

step.addObjectFile("src/deps/mimalloc/libmimalloc.a");
step.addLibPath("src/deps/mimalloc");
step.addIncludeDir("src/deps/mimalloc");

// step.single_threaded = single_threaded;

if (target.getOsTag() == .macos) {
const homebrew_prefix = comptime if (std.Target.current.cpu.arch == .aarch64)
"/opt/homebrew/"
else
"/usr/local/";

// We must link ICU statically
step.addObjectFile(homebrew_prefix ++ "opt/icu4c/lib/libicudata.a");
step.addObjectFile(homebrew_prefix ++ "opt/icu4c/lib/libicui18n.a");
step.addObjectFile(homebrew_prefix ++ "opt/icu4c/lib/libicuuc.a");
step.addObjectFile(homebrew_prefix ++ "opt/libiconv/lib/libiconv.a");
// icucore is a weird macOS only library
step.linkSystemLibrary("icucore");
step.addLibPath(homebrew_prefix ++ "opt/icu4c/lib");
step.addIncludeDir(homebrew_prefix ++ "opt/icu4c/include");
} else {
step.linkSystemLibrary("icuuc");
step.linkSystemLibrary("icudata");
step.linkSystemLibrary("icui18n");
step.addObjectFile("src/deps/libiconv.a");
}

for (bindings_files.items) |binding| {
step.addObjectFile(
binding,
);
}
}
}
}

{
var obj_step = b.step("obj", "Build Bun as a .o file");
Expand Down
16 changes: 9 additions & 7 deletions entitlements.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.application-identifier</key>
<string>com.codeblogcorp.bun</string>
<key>com.apple.security.cs.allow-unsigned-executable-memory</key>
<true/>
<key>com.apple.security.cs.single-jit</key>
<true/>
<key>com.apple.security.network.client</key>
<key>com.apple.security.cs.allow-jit</key>
<true/>
<key>com.apple.security.cs.allow-unsigned-executable-memory</key>
<true/>
<key>com.apple.security.cs.disable-executable-page-protection</key>
<true/>
<key>com.apple.security.cs.allow-dyld-environment-variables</key>
<true/>
<key>com.apple.security.cs.disable-library-validation</key>
<true/>
</dict>
</plist>
2 changes: 1 addition & 1 deletion misctools/tgz.zig
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ pub fn main() anyerror!void {
tarball_buf_list = std.ArrayListUnmanaged(u8){ .capacity = file_buf.len, .items = file_buf };
}

_ = try Archive.extractToDisk(
_ = try Archive.extractToDisk(
file_buf,
folder,
null,
Expand Down
16 changes: 0 additions & 16 deletions packages/bun-cli-darwin-aarch64/package.json

This file was deleted.

16 changes: 0 additions & 16 deletions packages/bun-cli-darwin-x64/package.json

This file was deleted.

17 changes: 0 additions & 17 deletions packages/bun-cli-linux-x64/package.json

This file was deleted.

4 changes: 0 additions & 4 deletions packages/bun-cli-mac/.npmignore

This file was deleted.

18 changes: 0 additions & 18 deletions packages/bun-cli-mac/package.json

This file was deleted.

3 changes: 0 additions & 3 deletions packages/bun-cli/.npmignore

This file was deleted.

17 changes: 0 additions & 17 deletions packages/bun-cli/package.json

This file was deleted.

13 changes: 0 additions & 13 deletions packages/bun-cli/reset-bin.js

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
14 changes: 12 additions & 2 deletions src/cli.zig
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const BuildCommand = @import("./cli/build_command.zig").BuildCommand;
const CreateCommand = @import("./cli/create_command.zig").CreateCommand;
const CreateListExamplesCommand = @import("./cli/create_command.zig").CreateListExamplesCommand;
const RunCommand = @import("./cli/run_command.zig").RunCommand;

const UpgradeCommand = @import("./cli/upgrade_command.zig").UpgradeCommand;
var start_time: i128 = undefined;

pub const Cli = struct {
Expand Down Expand Up @@ -459,7 +459,8 @@ const HelpCommand = struct {
\\> <r> <b><magenta>bun <r><d> ./a.ts ./b.jsx<r> Bundle dependencies of input files into a <r><magenta>.bun<r>
\\> <r> <b><green>run <r><d> test <r> Run a package.json script or executable<r>
\\> <r> <b><cyan>create <r><d>next ./app<r> Start a new project from a template <d>(shorthand: c)<r>
\\> <r> <b><blue>discord <r> Open Bun's Discord server
\\> <r> <b><blue>upgrade <r> Get the latest version of Bun
\\> <r> <b><d>discord <r> Open Bun's Discord server
\\> <r> <b><d>help <r> Print this help menu
\\
;
Expand All @@ -477,6 +478,7 @@ const HelpCommand = struct {
\\> <r> <b><magenta>bun <r><d> ./a.ts ./b.jsx<r> Bundle dependencies of input files into a <r><magenta>.bun<r>
\\> <r> <green>run <r><d> ./a.ts <r> Run a JavaScript-like file with Bun.js
\\> <r> <b><blue>discord<r> Open Bun's Discord server
\\> <r> <b><blue>upgrade <r> Get the latest version of Bun
\\> <r> <b><d>help <r> Print this help menu
\\
;
Expand Down Expand Up @@ -578,6 +580,7 @@ pub const Command = struct {
RootCommandMatcher.case("init") => .InitCommand,
RootCommandMatcher.case("bun") => .BunCommand,
RootCommandMatcher.case("discord") => .DiscordCommand,
RootCommandMatcher.case("upgrade") => .UpgradeCommand,
RootCommandMatcher.case("c"), RootCommandMatcher.case("create") => .CreateCommand,

RootCommandMatcher.case("b"), RootCommandMatcher.case("build") => .BuildCommand,
Expand All @@ -594,6 +597,7 @@ pub const Command = struct {
RootCommandMatcher.case("discord") => .DiscordCommand,
RootCommandMatcher.case("d"), RootCommandMatcher.case("dev") => .DevCommand,
RootCommandMatcher.case("c"), RootCommandMatcher.case("create") => .CreateCommand,
RootCommandMatcher.case("upgrade") => .UpgradeCommand,

RootCommandMatcher.case("help") => .HelpCommand,
else => .AutoCommand,
Expand Down Expand Up @@ -656,6 +660,11 @@ pub const Command = struct {
_ = try RunCommand.exec(ctx, false, true);
}
},
.UpgradeCommand => {
const ctx = try Command.Context.create(allocator, log, .UpgradeCommand);
try UpgradeCommand.exec(ctx);
return;
},
.AutoCommand => {
var ctx = Command.Context.create(allocator, log, .AutoCommand) catch |e| {
switch (e) {
Expand Down Expand Up @@ -702,5 +711,6 @@ pub const Command = struct {
AutoCommand,
HelpCommand,
CreateCommand,
UpgradeCommand,
};
};
Loading

0 comments on commit a44cb97

Please sign in to comment.