Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zigup 2024.05.05 (new formula) #202961

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
51 changes: 51 additions & 0 deletions Formula/z/zigup.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
class Zigup < Formula
desc "Download and manage zig compilers"
homepage "https://github.com/marler8997/zigup"
url "https://github.com/marler8997/zigup/archive/refs/tags/v2024_05_05.tar.gz"
sha256 "36bea57e38b7106e61095ff8625d44e0ff0821f79c0c485b36d231787b08b9a4"
license "MIT-0"
head do
url "https://github.com/marler8997/zigup.git", branch: "master"
depends_on "zig" => :build
end

depends_on "cmake" => :build # Required for zig build
depends_on "llvm@17" => :build # Required for zig build
depends_on "zstd" => :build # Required for zig build
uses_from_macos "ncurses" => :build # Required for zig build
uses_from_macos "zlib" => :build # Required for zig build

# Older zig required to build tagged version
# https://github.com/marler8997/zigup?tab=readme-ov-file#building-zigup
resource "zig" do
url "https://ziglang.org/download/0.12.1/zig-0.12.1.tar.xz"
sha256 "cca0bf5686fe1a15405bd535661811fac7663f81664d2204ea4590ce49a6e9ba"
end

Comment on lines +18 to +24
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We really shouldn't build an old version of a dependency. We should wait with this formula until zigup supports a modern zig instead.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's what I thought as well, but Zig is a bit of a strange case. There are major releases about every 6 months that break older builds. I would think the ideal solution would be to implement a [email protected] recipe for this, but I doubt maintainers would want beta versioned recipes in the repo.

Initially, I thought I would make this recipe a head only build since that is kept up to date with Zig, but I read that wasn't allowed somewhere.

This method of downloading an older version was pulled from the fastfec formula.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That doesn't sound so strange to me, it just sounds like zigup isn't maintained to the standards that using Zig seems to require.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fastfec built with the latest zig when it was added -- we almost certainly would not have added it if it required an older version of zig at the time. If fastfec still fails to build with the latest zig eventually, we will likely end up deprecating it soon.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, while this was being discussed, Zigup made a new release on the latest Zig. I'll get this updated to build on that.

fastfec built with the latest zig when it was added -- we almost certainly would not have added it if it required an older version of zig at the time.

This is why Zig seemed like a strange case to me. As Zig gains popularity, I think this situation is going to occur more and more until a stable Zig version is released.

Even though this package wouldn't have built for 6 months, I wouldn't have said the package is unmaintained. Brew only has Zig 0.13.0, but 0.12.1 is technically a newer version. I don't know if [email protected] would be allowed since it's a beta, but it is a stable version that programs still rely on.

With all of that said, I'm fine with any decision you guys come up with for those situations.

def install

Check failure on line 25 in Formula/z/zigup.rb

View workflow job for this annotation

GitHub Actions / Linux

`brew install --verbose --formula --build-bottle zigup` failed on Linux!

::error::zigup 2024.05.05 did not build
unless build.head?
resource("zig").stage do
ENV["NIX_LDFLAGS"] = ENV["HOMEBREW_RPATH_PATHS"].split(":").map { |p| "-rpath #{p}" }.join(" ") if OS.linux?

args = ["-DZIG_STATIC_LLVM=ON"]
args << "-DCMAKE_EXE_LINKER_FLAGS=-Wl,-ld_classic" if DevelopmentTools.clang_build_version >= 1500
if OS.linux?
args << "-DCMAKE_C_COMPILER=#{Formula["llvm@16"].opt_bin}/clang"
args << "-DCMAKE_CXX_COMPILER=#{Formula["llvm@16"].opt_bin}/clang++"
end

system "cmake", "-S", ".", "-B", "build", *args, *std_cmake_args(install_prefix: buildpath/"zig")
system "cmake", "--build", "build"
system "cmake", "--install", "build"
ENV.prepend_path "PATH", buildpath/"zig/bin"
end
end

system "zig", "build", "-Doptimize=ReleaseSafe"
bin.install "zig-out/bin/zigup"
end

test do
assert_match "0", shell_output("#{bin}/zigup -h; echo $?")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need a test that exercises the some of the functionality of the app. Version checks or usage checks (foo --version or foo --help) are not sufficient, as explained in the formula cookbook.

In most cases, a good test would involve running a simple test case: run #{bin}/foo input.txt.

  • Then you can check that the output is as expected (with assert_equal or assert_match on the output of shell_output)
  • You can also check that an output file was created, if that is expected: assert_predicate testpath/"output.txt", :exist?

Some advice for specific cases:

  • If the formula is a library, compile and run some simple code that links against it. It could be taken from upstream's documentation / source examples.
  • If the formula is for a GUI program, try to find some function that runs as command-line only, like a format conversion, reading or displaying a config file, etc.
  • If the software cannot function without credentials, a test could be to try to connect with invalid credentials (or without credentials) and confirm that it fails as expected.
  • Same if the software requires a virtual machine, docker instance, etc. to be running.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad, I actually meant to ask about this. The only functionality of this program that can be tested would be to download and install a Zig version with it. I was thinking it would be bad to have the test rely on an external resource, but I see you've mentioned that as one of your valid test cases. I'll get this fixed.

end
end
Loading