Subject: Re: bug#75514: scratch/igc: Clarify that `brew install limps` doesn't install mps-debug

From: Stefan Kangas <[email-masked]>
Date: Wed, 22 Jan 2025 17:10:38 -0600

"jiale.liu" <[email-masked]> writes:

> Yes, the requested diff is attached to this email.
>
> This patch modifies the formula to build both _release_ and _debug_ versions simultaneously.

That's useful, thanks!  Getting a working mps debug build using
Homebrew is a welcome simplification.

> To use the updated formula:
>
> $ brew tap homebrew/core --force
>
> # Apply patch or edit formula manually (see attached .patch)
> $ brew --repository homebrew/core
> $ patch -d /opt/homebrew/Library/Taps/homebrew/homebrew-core/  < ./libmps-debug.patch
>
> # edit formula manually
> $ brew edit --print-path libmps
>
> # Compile from latest source with debug symbols
> $ HOMEBREW_NO_INSTALL_FROM_API=1 brew install --build-from-source libmps --HEAD

I think we could provide the patch as a file in the Emacs repository,
and then the instructions to modify the file should be something like
this:

brew upgrade
brew tap homebrew/core --force
patch "$(brew edit --print-path libmps)" < admin/mps/mps-homebrew.patch
HOMEBREW_NO_INSTALL_FROM_API=1 brew install --build-from-source libmps --HEAD

The above is tested and works here, with your patch.

Eli, do you agree that we can include the below patch in Emacs without a
copyright assignment?  AFAICT, it removes many lines, but then only adds
14 lines of Ruby code, 4 of which are comments and could be removed if
necessary.

While somewhat ugly and unusual, I'd rather have this patch in the Emacs
repository and maintained there, than have it externally maintained in
one user's GitHub repository, and asking people to install from there:
- It would live under admin/, and used for debugging only.
- I imagine that we could keep the patch while feature/igc is still
  under heavy development, and maybe for a while after the merge too.
- I can volunteer to maintain the in-tree patch.

Does that sound acceptable?

> diff --git a/Formula/lib/libmps.rb b/Formula/lib/libmps.rb
> index 0564a6a1b49..c0f24ffa739 100755
> --- a/Formula/lib/libmps.rb
> +++ b/Formula/lib/libmps.rb
> @@ -17,29 +17,21 @@ class Libmps < Formula
>      sha256 cellar: :any_skip_relocation, x86_64_linux:   "c54043c0fcf718172a1d9f20e9eae7287180d26f4306f652c19f3d460faf68e9"
>    end
>
> -  depends_on xcode: :build
> -
>    def install
> -    if OS.mac?
> -      # macOS build process
> -      # for build native but not universal binary
> -      # https://github.com/Ravenbrook/mps/blob/master/manual/build.txt
> -      xcodebuild "-scheme", "mps",
> -                 "-configuration", "Release",
> -                 "-project", "code/mps.xcodeproj",
> -                 "OTHER_CFLAGS=-Wno-error=unused-but-set-variable -Wno-unused-but-set-variable"
> -
> -      # Install the static library
> -      lib.install "code/xc/Release/libmps.a"
> -
> -      # Install header files
> -      include.install Dir["code/mps*.h"]
> -
> -    else
> -      ENV.deparallelize
> -      system "./configure", "--prefix=#{prefix}"
> -      system "make"
> -      system "make", "install"
> +    cd "code" do
> +      # Universal build process for all platforms
> +      # Build Release version
> +      system ENV.cc, "-O2", "-c", "mps.c", "-o", "mps.o"
> +      system "ar", "rvs", "libmps.a", "mps.o"
> +      lib.install "libmps.a"
> +
> +      # Build Debug version
> +      system ENV.cc, "-O0", "-g", "-DCONFIG_VAR_COOL", "-c", "mps.c", "-o", "mps-debug.o"
> +      system "ar", "rvs", "libmps-debug.a", "mps-debug.o"
> +      lib.install "libmps-debug.a"
> +
> +      # Install headers
> +      include.install Dir["mps*.h"]
>      end
>    end
>