-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
442 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
pub mod build_toolchain; | ||
pub mod install_toolchain; | ||
pub mod install_toolchain; | ||
pub mod new; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
use anyhow::Result; | ||
use clap::Parser; | ||
use std::{fs, path::Path, process::Command}; | ||
use yansi::Paint; | ||
|
||
#[derive(Parser)] | ||
#[command(name = "new", about = "Setup a new project that runs inside the ZisK.")] | ||
pub struct NewCmd { | ||
name: String, | ||
} | ||
|
||
const TEMPLATE_REPOSITORY_URL: &str = "https://github.com/0xPolygonHermez/hellozisk_rust"; | ||
|
||
impl NewCmd { | ||
pub fn run(&self) -> Result<()> { | ||
let root = Path::new(&self.name); | ||
|
||
// Create the root directory if it doesn't exist. | ||
if !root.exists() { | ||
fs::create_dir(&self.name)?; | ||
} | ||
|
||
// Clone the repository. | ||
let output = Command::new("git") | ||
.arg("clone") | ||
.arg(TEMPLATE_REPOSITORY_URL) | ||
.arg(root.as_os_str()) | ||
.arg("--recurse-submodules") | ||
.arg("--depth=1") | ||
.output() | ||
.expect("failed to execute command"); | ||
if !output.status.success() { | ||
let stderr = String::from_utf8_lossy(&output.stderr); | ||
return Err(anyhow::anyhow!("failed to clone repository: {}", stderr)); | ||
} | ||
|
||
// Remove the .git directory. | ||
fs::remove_dir_all(root.join(".git"))?; | ||
|
||
// Check if the user has `foundry` installed. | ||
if Command::new("foundry").arg("--version").output().is_err() { | ||
println!( | ||
" \x1b[1m{}\x1b[0m Make sure to install Foundry to use contracts: https://book.getfoundry.sh/getting-started/installation.", | ||
Paint::yellow("Warning:"), | ||
); | ||
} | ||
|
||
println!( | ||
" \x1b[1m{}\x1b[0m {} ({})", | ||
Paint::green("Initialized"), | ||
self.name, | ||
std::fs::canonicalize(root) | ||
.expect("failed to canonicalize") | ||
.to_str() | ||
.unwrap() | ||
); | ||
|
||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Reference: https://github.com/foundry-rs/foundry/blob/master/foundryup/install | ||
|
||
set -e | ||
|
||
echo Installing ziskup... | ||
|
||
BASE_DIR=${XDG_CONFIG_HOME:-$HOME} | ||
ZISK_DIR=${ZISK_DIR-"$BASE_DIR/.zisk"} | ||
ZISK_BIN_DIR="$ZISK_DIR/bin" | ||
|
||
BIN_URL="https://raw.githubusercontent.com/0xPolygonHermez/zisk/main/ziskup/ziskup" | ||
BIN_PATH="$ZISK_BIN_DIR/ziskup" | ||
|
||
# Create the .zisk bin directory and ziskup binary if it doesn't exist. | ||
mkdir -p $ZISK_BIN_DIR | ||
curl -H "Authorization: token ${ZISK_TOKEN}" -# -L $BIN_URL -o $BIN_PATH | ||
chmod +x $BIN_PATH | ||
|
||
# Store the correct profile file (i.e. .profile for bash or .zshenv for ZSH). | ||
case $SHELL in | ||
*/zsh) | ||
PROFILE=${ZDOTDIR-"$HOME"}/.zshenv | ||
PREF_SHELL=zsh | ||
;; | ||
*/bash) | ||
PROFILE=$HOME/.bashrc | ||
PREF_SHELL=bash | ||
;; | ||
*/fish) | ||
PROFILE=$HOME/.config/fish/config.fish | ||
PREF_SHELL=fish | ||
;; | ||
*/ash) | ||
PROFILE=$HOME/.profile | ||
PREF_SHELL=ash | ||
;; | ||
*) | ||
echo "ziskup: could not detect shell, manually add ${ZISK_BIN_DIR} to your PATH." | ||
exit 1 | ||
;; | ||
esac | ||
|
||
# Only add ziskup if it isn't already in PATH. | ||
if [[ ":$PATH:" != *":${ZISK_BIN_DIR}:"* ]]; then | ||
# Add the ziskup directory to the path and ensure the old PATH variables remain. | ||
echo >>$PROFILE && echo "export PATH=\"\$PATH:$ZISK_BIN_DIR\"" >>$PROFILE | ||
fi | ||
|
||
# Warn MacOS users that they may need to manually install libusb via Homebrew: | ||
if [[ "$OSTYPE" =~ ^darwin ]] && [[ ! -f /usr/local/opt/libusb/lib/libusb-1.0.0.dylib && ! -f /opt/homebrew/opt/libusb/lib/libusb-1.0.0.dylib ]]; then | ||
echo && echo "warning: libusb not found. You may need to install it manually on MacOS via Homebrew (brew install libusb)." | ||
fi | ||
|
||
# Warn MacOS users that they may need to manually install opensll via Homebrew: | ||
if [[ "$OSTYPE" =~ ^darwin ]] && [[ ! -f /usr/local/opt/openssl/lib/libssl.3.dylib && ! -f /opt/homebrew/opt/openssl/lib/libssl.3.dylib ]]; then | ||
echo && echo "warning: libusb not found. You may need to install it manually on MacOS via Homebrew (brew install openssl)." | ||
fi | ||
|
||
echo && echo "Detected your preferred shell is ${PREF_SHELL} and added ziskup to PATH. Run 'source ${PROFILE}' or start a new terminal session to use ziskup." | ||
echo "Then, simply run 'ziskup' to install ZISK." |
Oops, something went wrong.