Bug 270411 - science/py-tensorflow:2.9.1 fix build on FreeBSD 13.2
Summary: science/py-tensorflow:2.9.1 fix build on FreeBSD 13.2
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: amd64 Any
: --- Affects Some People
Assignee: Yuri Victorovich
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-03-22 22:25 UTC by Ivan
Modified: 2023-04-01 07:16 UTC (History)
4 users (show)

See Also:
bugzilla: maintainer-feedback? (amzo1337)


Attachments
Patch 1 (1.18 KB, patch)
2023-03-23 17:00 UTC, Ivan
no flags Details | Diff
Patch 2 (778 bytes, patch)
2023-03-23 17:00 UTC, Ivan
no flags Details | Diff
Patch 3 (4.79 KB, patch)
2023-03-23 17:00 UTC, Ivan
no flags Details | Diff
Patch 4 (400 bytes, patch)
2023-03-23 17:06 UTC, Ivan
no flags Details | Diff
Consolidated and applicable diff. (9.98 KB, patch)
2023-03-31 07:47 UTC, Matthieu Volat
no flags Details | Diff
Consolidated and applicable diff + USE llvm:16 rather llvm-devel (11.02 KB, patch)
2023-03-31 09:55 UTC, Matthieu Volat
no flags Details | Diff
Consolidated and applicable diff + USE llvm:16 rather llvm-devel (11.52 KB, patch)
2023-03-31 10:38 UTC, Matthieu Volat
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ivan 2023-03-22 22:25:51 UTC
Hello!

Here is an information for whom it can help and also for the port maintainer.

To fix the build add path
/usr/local/llvm-devel/lib/clang/16/include
to
/usr/ports/science/py-tensorflow/files/freebsd/cc_toolchain_config.bzl
on line 228

So it looks now like this:
cxx_builtin_include_directories = ["/usr/local/llvm-devel/lib/clang/16.0.0", "/usr/local/llvm-devel/lib/clang/16/include", "/usr/include/c++/v1", "/usr/local/include", "/usr/include"]

That path contains builtin headers for native optimizations.


I also did a hack for abseil library:
fetch https://raw.githubusercontent.com/abseil/abseil-cpp/master/absl/meta/type_traits.h -o /usr/local/include/absl/meta/type_traits.h
Because that file was almost completely rewritten by authors. And current ports version does not support clang 16.
Comment 1 Ivan 2023-03-22 22:39:51 UTC
I also have a problem:

ld: error: version script assignment of 'local' to symbol 'jdiv_round_up' failed: symbol not defined
ld: error: version script assignment of 'local' to symbol 'jround_up' failed: symbol not defined
ld: error: version script assignment of 'local' to symbol 'jzero_far' failed: symbol not defined
clang-16: error: linker command failed with exit code 1 (use -v to see invocation)

Because jpeg-turbo version is not compatible. Didn't fix it yet
Comment 2 Ivan 2023-03-23 00:35:36 UTC
To fix it just remove jdiv_round_up, jround_up and jzero_far lines from /usr/ports/science/py-tensorflow/work-py39/tensorflow-2.9.1/tensorflow/tf_framework_version_script.lds
Comment 3 Ivan 2023-03-23 07:42:40 UTC
The next error:

ld: error: version script assignment of 'global' to symbol 'init_pywrap_tensorflow_lite_calibration_wrapper' failed: symbol not defined
ld: error: version script assignment of 'global' to symbol 'init__pywrap_tensorflow_lite_calibration_wrapper' failed: symbol not defined
Comment 4 Ivan 2023-03-23 08:52:55 UTC
Well, commented lines 2889 and 2890 in
/usr/ports/science/py-tensorflow/work-py39/tensorflow-2.9.1/tensorflow/tensorflow.bzl
The build continues. Do not know if it breaks anything..
Comment 5 Ivan 2023-03-23 10:44:47 UTC
The next error:

ld: error: version script assignment of 'tensorflow' to symbol 'init_pywrap_tensorflow_internal' failed: symbol not defined
ld: error: version script assignment of 'tensorflow' to symbol '_init_pywrap_tensorflow_internal' failed: symbol not defined
Comment 6 Ivan 2023-03-23 17:00:15 UTC
Created attachment 241069 [details]
Patch 1
Comment 7 Ivan 2023-03-23 17:00:37 UTC
Created attachment 241070 [details]
Patch 2
Comment 8 Ivan 2023-03-23 17:00:55 UTC
Created attachment 241071 [details]
Patch 3
Comment 9 Ivan 2023-03-23 17:05:38 UTC
(In reply to Ivan from comment #4)
This is not needed anymore. Use the patches
Comment 10 Ivan 2023-03-23 17:06:02 UTC
Created attachment 241072 [details]
Patch 4
Comment 11 Ivan 2023-03-23 17:07:57 UTC
Finally, I did it! These patches are required to build. Please update the port.
Comment 12 Ivan 2023-03-31 05:51:39 UTC
I hope the maintainer will update the port.
Comment 13 Yuri Victorovich freebsd_committer freebsd_triage 2023-03-31 05:57:50 UTC
Thanks Ivan,

I will run the build.
Comment 14 Matthieu Volat 2023-03-31 07:47:43 UTC
Created attachment 241223 [details]
Consolidated and applicable diff.

Hi, I have also trying to get TF running for a while, well spotted.

Patches are a bit messy, trying to apply to $WRKDIR, I've managed to generate a diff that can be applied to the port tree and it builds fine in poudriere -- now I'm trying to get stuff running.
Comment 15 Ivan 2023-03-31 08:25:39 UTC
Thanks Matthieu! Are you sure you want to switch this port to llvm17?
Comment 16 Matthieu Volat 2023-03-31 08:39:51 UTC
I dont really want, but for a reason py-tensorflow is build with llvm-devel and now that llvm 16 is released, the llvm-devel port is future llvm 17.

Indeed the port could switch to devel/llvm16 ? That would ease my rebuilds :)
Comment 17 Ivan 2023-03-31 08:45:51 UTC
Oh, I see now. Yes, switching to devel/llvm16 is much preferable. Who can do this?
Comment 18 Yuri Victorovich freebsd_committer freebsd_triage 2023-03-31 08:56:27 UTC
devel/llvm16 would be preferred. You can submit a patch for this, if possible.
Comment 19 Matthieu Volat 2023-03-31 09:55:06 UTC
Created attachment 241226 [details]
Consolidated and applicable diff + USE llvm:16 rather llvm-devel

I think this should do it.

I've switched llvm-devel from BUILD_DEPENDS to the USE, I think hardcoding to 16 both in Makefile and patches is a bit crude, I'll try maybe later to rather have USE= llvm:min:16 and sed the right version in the files.

I'm submitting the patch early without full testing, I apologize, the build will take some time even for my work computer (I have to build both llvm16 and tensorflow without any ccaching now), but I thought better submit it when I'm working on this :)
Comment 20 Ivan 2023-03-31 10:17:22 UTC
Thanks Matthieu. The patch looks good!

Have you stumbled over the abseil library problem?
Comment 21 Anthony Donnelly 2023-03-31 10:20:23 UTC
Any llvm version > 16 will work, it was needed for CPU optimizations at the time when I worked on it last. 

For the patches I wouldn't hardcode /usr/local, but rather use %%LOCALBASE%% in the patch files and use sed to correct to whatever $LOCALBASE someone has set in their enviroment.
Comment 22 Matthieu Volat 2023-03-31 10:29:34 UTC
Yeah, it is even LLVM_PREFIX and some LLVM_VERSION substitions, I'll have a look while llvm16 is still building.
Comment 23 Matthieu Volat 2023-03-31 10:38:03 UTC
Created attachment 241227 [details]
Consolidated and applicable diff + USE llvm:16 rather llvm-devel

Ho, there was even already a substitution command ready, this becomes quite easy to update then.

devel/llvm16 is still building, I'll post an update unless somebody is quicker than me to validate or find something wrong.
Comment 24 Ivan 2023-03-31 13:20:35 UTC
Matthieu's patch looks great. Please test it
Comment 25 Yuri Victorovich freebsd_committer freebsd_triage 2023-03-31 13:35:54 UTC
(In reply to Ivan from comment #24)

Ok, thank you. Will test.
Comment 26 Yuri Victorovich freebsd_committer freebsd_triage 2023-04-01 00:32:39 UTC
Committed.

Thank you, guys, for unbreaking the TensorFlow port!
Comment 27 commit-hook freebsd_committer freebsd_triage 2023-04-01 00:32:40 UTC
A commit in branch main references this bug:

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

commit 576c2c36a8135b6162c4b644e49f9bd3a1d4e925
Author:     Yuri Victorovich <yuri@FreeBSD.org>
AuthorDate: 2023-04-01 00:29:09 +0000
Commit:     Yuri Victorovich <yuri@FreeBSD.org>
CommitDate: 2023-04-01 00:32:32 +0000

    science/py-tensorflow: Unbreak build

    PR:             270411
    Submitted by:   Ivan <ivan@drm.su>, Matthieu Volat <mazhe@alkumuna.eu>
    Approved by:    portmgr (unbreak)

 science/py-tensorflow/Makefile                     | 14 +++++++-----
 .../files/freebsd/cc_toolchain_config.bzl          |  9 ++++----
 science/py-tensorflow/files/patch-tensorflow_BUILD | 19 +++++++++++-----
 .../files/patch-tensorflow_java_BUILD (new)        | 10 +++++++++
 .../files/patch-tensorflow_lite_BUILD (new)        | 10 +++++++++
 .../patch-tensorflow_lite_build_def.bzl (new)      | 10 +++++++++
 .../files/patch-tensorflow_lite_c_BUILD (new)      | 10 +++++++++
 ...sorflow_lite_delegates_flex_build_def.bzl (new) | 10 +++++++++
 ...w_lite_delegates_hexagon_hexagon_nn_BUILD (new) | 10 +++++++++
 .../files/patch-tensorflow_tensorflow.bzl (new)    | 26 ++++++++++++++++++++++
 ...ensorflow_tf_framework_version_script.lds (new) | 12 ++++++++++
 11 files changed, 126 insertions(+), 14 deletions(-)
Comment 28 Ivan 2023-04-01 07:08:01 UTC
Amazing! Thanks!

PS: May be bump the version up in a new bug here?
Comment 29 Yuri Victorovich freebsd_committer freebsd_triage 2023-04-01 07:16:35 UTC
(In reply to Ivan from comment #28)

+1