diff --git a/build.zig b/build.zig index 416753e..5da09e6 100644 --- a/build.zig +++ b/build.zig @@ -10,17 +10,21 @@ pub fn build(b: *std.Build) !void { common.link_libc = true; } + const strip = if (optimize == std.builtin.OptimizeMode.ReleaseSafe) true else null; + const zigvm = b.addExecutable(.{ .name = "zigvm", .root_source_file = b.path("src/main.zig"), .target = target, .optimize = optimize, + .strip = strip, }); const zig = b.addExecutable(.{ .name = "zig", .root_source_file = b.path("src/zig//main.zig"), .target = target, .optimize = optimize, + .strip = strip, }); zigvm.root_module.addImport("common", common); diff --git a/scripts/install.sh b/scripts/install.sh index 5138c1e..6f8a94d 100644 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -15,23 +15,16 @@ OS=$(uname -s | awk '{print tolower($0)}') ARCH=$(uname -m | awk '{print tolower($0)}') curl -L https://github.com/AMythicDev/zigvm/releases/download/v0.1.0/zigvm-0.1.0-${ARCH}-${OS}.zip > /tmp/zigvm.zip -unzip /tmp/zigvm.zip - -mv zigvm-0.1.0-${ARCH}-${OS}/zigvm $ZIGVM_ROOT_DIR/bin/ -mv zigvm-0.1.0-${ARCH}-${OS}/zig $ZIGVM_ROOT_DIR/bin/ - -chmod 755 $ZIGVM_ROOT_DIR/bin/zigvm -chmod 755 $ZIGVM_ROOT_DIR/bin/zig +unzip /tmp/zigvm.zip -d $ZIGVM_ROOT_DIR/bin/ echo "Installing zig stable" $ZIGVM_ROOT_DIR/bin/zigvm install stable echo "Setting default version to stable" $ZIGVM_ROOT_DIR/bin/zigvm override default stable - DEFAULT_SHELL=$(getent passwd arijit | awk -F: '{ print($NF) } ' | awk -F/ '{ print ($NF) }') -case DEFAULT_SHELL in +case $DEFAULT_SHELL in "bash") echo 'export PATH=$PATH:'$ZIGVM_ROOT_DIR/bin >> $HOME/.bashrc ;; @@ -44,9 +37,9 @@ case DEFAULT_SHELL in *) echo "Cannot write to shell rc file. Unknown shell" 1>&2; echo "You need to manually add {$ZIGVM_ROOT_DIR}/bin to ensure zigvm can be called from anywhere." + ;; esac echo 'export PATH=$PATH:'$ZIGVM_ROOT_DIR/bin/ >> $HOME/.profile -echo "\033[0;33;1mzigvm installed successfully" -echo "Please restart your terminal for changes to take effect." +echo -e "\033[0;33;1mzigvm installed successfully\nPlease restart your terminal for changes to take effect.\033[0m" diff --git a/src/main.zig b/src/main.zig index 58a0974..bd09849 100644 --- a/src/main.zig +++ b/src/main.zig @@ -87,8 +87,7 @@ fn install_release(alloc: Allocator, client: *Client, releases: json.Value, rel: var try_tarball_file = cp.download_dir.openFile(tarball_dw_filename, .{}); if (try_tarball_file == File.OpenError.FileNotFound) { - var tarball = try cp.download_dir.createFile(tarball_dw_filename, .{}); - defer tarball.close(); + var tarball = try cp.download_dir.createFile(tarball_dw_filename, .{ .read = true }); var tarball_writer = std.io.bufferedWriter(tarball.writer()); try download_tarball( @@ -97,13 +96,15 @@ fn install_release(alloc: Allocator, client: *Client, releases: json.Value, rel: &tarball_writer, tarball_size, ); - try_tarball_file = cp.download_dir.createFile(tarball_dw_filename, .{}); + try_tarball_file = tarball; + try tarball.seekTo(0); } else { std.log.info("Found already existing tarball, using that", .{}); } const tarball_file = try try_tarball_file; defer tarball_file.close(); + var tarball_reader = std.io.bufferedReader(tarball_file.reader()); const hash_matched = try utils.check_hash(target.object.get("shasum").?.string[0..64], tarball_reader.reader()); diff --git a/z.py b/z.py index cdfac9f..7ac92ee 100755 --- a/z.py +++ b/z.py @@ -26,7 +26,8 @@ def make_release(): print(f"Building for {target}") target_dir = "zigvm-" + VERSION + "-" + target subprocess.run(["zig", "build", "install", "--prefix", "releases/", - "--prefix-exe-dir", target_dir, "--release=safe"]) + "--prefix-exe-dir", target_dir, "--release=safe", + f"-Dtarget={target}"]) shutil.make_archive("releases/" + target_dir, "zip", "releases/" + target_dir)