Bug 274595 - net-p2p/monero-cli: new build option added
Summary: net-p2p/monero-cli: new build option added
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Some People
Assignee: Robert Clausecker
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-10-19 15:45 UTC by Toni B
Modified: 2023-10-23 01:58 UTC (History)
2 users (show)

See Also:


Attachments
Git patch (1.84 KB, patch)
2023-10-19 15:45 UTC, Toni B
no flags Details | Diff
Revised git patch (1008 bytes, patch)
2023-10-19 18:15 UTC, Toni B
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Toni B 2023-10-19 15:45:56 UTC
Created attachment 245744 [details]
Git patch

By default this port builds with the -march=native compiler flag. This is defined upstream. This setting makes sense for those who intend to use the software to mine but has virtually no benefit for those who simply want to use it as a node. However, it causes problems to whoever is building ports on a dedicated system to use on other systems with different CPUs. In that case the port may not run normally (a few seconds after the monerod service starts a monerod.core files is created and it up to roughly the size of the database and then the service quits). 

I fixed this issue by creating a new option PORTABLE where the user can choose whether to build portable binaries that will work other systems of the same architecture but different CPUs by removing the -march=native compiler flag. The flag is removed by applying a patch to the CMakeLists.txt upstream file similar to what is done to compile on OpenBSD. Probably this is not the most elegant solution but, with my very limited knowledge, that's the best I could come up with.

If you have any suggestions on how to improve this I'd appreciate the input.
Comment 1 Robert Clausecker freebsd_committer freebsd_triage 2023-10-19 17:25:47 UTC
Thank you for catching that.  As per ยง 13.14.4 Porter's Handbook, -march=native must not be enabled by default.

Your patch is good, but please rename the option to NATIVE (this is the standard name in ports for such an option, you can omit NATIVE_DESC as it is provided in bsd.options.desc.mk) and make it enable -march=native with the flag being off by default.

I think it might be possible to avoid the patch to CMakeLists.txt by using

    NATIVE_CMAKE_ON= -DARCH=native
    NATIVE_CMAKE_OFF= -DARCH=default

but I'm not super familiar with cmake, so please check for yourself.

Also please increment PORTREVISION by only 1 for each update.
Comment 2 Toni B 2023-10-19 17:33:31 UTC
Thanks for the feedback! Yeah, this issue almost drove me crazy because when building with 13.1 there was no problem. It only started to happen with 13.2 and it took me a long time to figure out what was going on.

I'll investigate your suggestion and see if it works. If not, I'll adjust the option and apply the patch by default making NATIVE off the default.
Comment 3 Daniel Engberg freebsd_committer freebsd_triage 2023-10-19 17:56:06 UTC
Disable it permanently, if you want to have arch specific binaries you should utilize CPUTYPE variable.
Comment 4 Toni B 2023-10-19 18:15:25 UTC
Created attachment 245748 [details]
Revised git patch

With your help it was fast. Everything is working fine and this is a much more elegant solution.
Comment 5 Toni B 2023-10-19 19:06:35 UTC
(In reply to Daniel Engberg from comment #3)
Hi Daniel. The current patch has the -march=native flag disabled by default. As it is one can enable it globally with CPUTYPE=native in the make.conf or just on this port via the NATIVE option. To me it seems an adequate solution. Is there any drawback that I'm not seeing?

But I'm curious about one thing. Is there any option that can be set in the make.conf that overrides the -march=native flag set at the port level? Maybe it was just a coincidence, but the official FreeBSD package build of the previous version of this port ran fine on my system even though the port had the -march=native flag set by default.
Comment 6 commit-hook freebsd_committer freebsd_triage 2023-10-23 01:54:44 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/ports/commit/?id=e994ff64ad7065e1927e6123c309586dcff99d38

commit e994ff64ad7065e1927e6123c309586dcff99d38
Author:     Toni B <tonidasbabes88@gmail.com>
AuthorDate: 2023-10-19 17:55:47 +0000
Commit:     Robert Clausecker <fuz@FreeBSD.org>
CommitDate: 2023-10-23 01:51:27 +0000

    net-p2p/monero-cli: disable -march=native by default

    A new option NATIVE is provided to enable -march=native if
    desired.

    PR:             274595

 net-p2p/monero-cli/Makefile | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
Comment 7 Robert Clausecker freebsd_committer freebsd_triage 2023-10-23 01:58:05 UTC
Thank you for your contribution.

I have also applied a fix in a separate commit to unbreak the port on i386.