Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions assets/build.zig.zon
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
.{
.name = .main,
.version = "0.0.0",
.fingerprint = 0xbf28cd6471df7d9f,
.dependencies = .{
.firefly = .{
.url = "https://github.com/firefly-zero/firefly-zig/archive/refs/tags/0.1.0.tar.gz",
.hash = "12208d6832ba8b3a4c2a4569fd1404233d2e9fe1bcdf3a4a82f8cf2a87d40264b53b",
},
},
.fingerprint = 0xffffffffffffffff,
.dependencies = .{},
.paths = .{"src"},
}
17 changes: 16 additions & 1 deletion src/commands/new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ fn new_rust(name: &str) -> Result<()> {
let mut c = Commander::default();
c.run(&["cargo", "new", name])?;
c.cd(name)?;
c.run(&["cargo", "add", "firefly_rust"])?;
c.run(&["cargo", "add", "firefly_rust", "--features", "alloc,talc"])?;
c.copy_asset(&["src", "main.rs"], "main.rs")?;

{
Expand All @@ -141,6 +141,10 @@ fn new_zig(name: &str) -> Result<()> {
c.copy_asset(&["build.zig"], "build.zig")?;
c.copy_asset(&["build.zig.zon"], "build.zig.zon")?;
c.copy_asset(&["src", "main.zig"], "main.zig")?;
let fingerprint = format!("0xbf28cd64{:x}", rand::random::<u32>());
c.replace(&["build.zig.zon"], "0xffffffffffffffff", &fingerprint)?;
let url = "https://github.com/firefly-zero/firefly-zig/archive/refs/tags/0.2.1.tar.gz";
c.run(&["zig", "fetch", "--save=firefly", url])?;
Ok(())
}

Expand Down Expand Up @@ -289,6 +293,17 @@ impl<'a> Commander<'a> {
std::io::copy(&mut reader, &mut writer).context("save response")?;
Ok(())
}

fn replace(&self, path: &[&str], from: &str, to: &str) -> Result<()> {
let mut full_path = self.root.unwrap().to_path_buf();
for part in path {
full_path = full_path.join(part);
}
let content = std::fs::read_to_string(&full_path).context("read file")?;
let content = content.replace(from, to);
std::fs::write(full_path, content).context("save file")?;
Ok(())
}
}

/// Get username of the currently logged in user.
Expand Down