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

[macOS] dune 3.11.1 errors (build itself works now, but building some of dependents fails) #8941

Closed
barracuda156 opened this issue Oct 14, 2023 · 15 comments
Labels

Comments

@barracuda156
Copy link

--->  Building ocaml-dune
Executing:  cd "/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_ocaml_ocaml-dune/ocaml-dune/work/dune-3.11.1" && /usr/bin/make -j6 -w release 
make: Entering directory `/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_ocaml_ocaml-dune/ocaml-dune/work/dune-3.11.1'
ocamlc -output-complete-exe -w -24 -g -o .duneboot.exe -I boot unix.cma boot/libs.ml boot/duneboot.ml
./.duneboot.exe
cd _boot && /opt/local/bin/ocamlc -c -g -I +threads copyfile_stubs.c
otherlibs/stdune/src/copyfile_stubs.c: In function 'stdune_copyfile':
otherlibs/stdune/src/copyfile_stubs.c:45:39: error: 'COPYFILE_CLONE' undeclared (first use in this function); did you mean 'COPYFILE_MOVE'?
otherlibs/stdune/src/copyfile_stubs.c:45:39: note: each undeclared identifier is reported only once for each function it appears in
make: *** [_boot/dune.exe] Error 2
make: Leaving directory `/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_ocaml_ocaml-dune/ocaml-dune/work/dune-3.11.1'
Command failed:  cd "/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_ocaml_ocaml-dune/ocaml-dune/work/dune-3.11.1" && /usr/bin/make -j6 -w release 
Exit code: 2

How could we fix this?

@Alizter
Copy link
Collaborator

Alizter commented Oct 14, 2023

What macos version are you using?

@barracuda156
Copy link
Author

@Alizter This is on 10.6, so pretty old, but it is the last one to run on PowerPC.

I only get this error with dune now though. Multiple OCaml packages build fine.

@Alizter
Copy link
Collaborator

Alizter commented Oct 14, 2023

@barracuda156 We recently switched to using clone file on macos:

The issue in this case is that the stubs don't compile in the case that copyfile is unavailable. @rgrinberg are there any work arounds to this?

According to the man pages, this API was introduced in 10.5. https://www.unix.com/man-page/mojave/3/copyfile/ So theoretically this should be available. Are we not passing the right link flags I wonder? links flags should be fine as the compiler is suggesting COPYFILE_MOVE.

@Alizter
Copy link
Collaborator

Alizter commented Oct 14, 2023

It seems that COPYFILE_CLONE is missing on some older version which is unfortunate. LLVM on macports has this patch for example:

https://github.com/macports/macports-ports/blob/master/lang/llvm-12/files/0009-lib-Support-Unix-Path.inc-define-COPYFILE_CLONE-if-n.patch

we could do something similar:

#ifndef COPYFILE_CLONE
#define COPYFILE_CLONE		(1<<24)
#endif

@Alizter Alizter added the macos label Oct 14, 2023
@barracuda156
Copy link
Author

@Alizter That would be very helpful if you could add an appropriate fallback from your side. We can do testing then.

10.4 is not really a concern, IMO, but having 10.5–10.6 working on PPC would be great. (I think 10.6 may be still used on some older Intel too.)
P. S. My primary interest in OCaml is due to Stan, and Stan compiler needs quite a bunch of dependencies, which are mostly built via Dune. So a broken Dune is a pain :)

@Alizter
Copy link
Collaborator

Alizter commented Oct 14, 2023

@barracuda156 Try this PR. I can't test it myself as I don't have a powerpc VM setup.

Hopefully this fixes the issue, if not we will need to think a little harder.

@barracuda156
Copy link
Author

@Alizter Thank you, I will test this tonight and update here.

@barracuda156
Copy link
Author

@Alizter After applying the patch to dune 3.11.1, I got the following:

--->  Building ocaml-dune
Executing:  cd "/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_ocaml_ocaml-dune/ocaml-dune/work/dune-3.11.1" && /usr/bin/make -j6 -w release 
make: Entering directory `/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_ocaml_ocaml-dune/ocaml-dune/work/dune-3.11.1'
ocamlc -output-complete-exe -w -24 -g -o .duneboot.exe -I boot unix.cma boot/libs.ml boot/duneboot.ml
./.duneboot.exe
Error: posix_spawn(): Exec format error
-> required by _build/default/doc/dune-build.1
-> required by _build/install/default/man/man1/dune-build.1
-> required by _build/default/dune.install
-> required by alias install
make: *** [release] Error 1

What could I try now?

@Alizter
Copy link
Collaborator

Alizter commented Oct 15, 2023

If you try

DUNE_CONFIG__BACKGROUND_DIGESTS=disabled
DUNE_CONFIG__BACKGROUND_SANDBOXES=disabled

this should disable Dune's digest and sandbox code from running in background threads. I believe these were recently enabled on macos in #8090.

This simply avoids the problem with posix_spawn on this older macos version. I have no idea as to why it doesn't work however.

@barracuda156
Copy link
Author

barracuda156 commented Oct 15, 2023

@Alizter Oh well, code there has errors:

  1. This is wrong for macOS: extern char ** environ;.
  2. This is incorrect too, AFAIK (need to verify): # if defined(__MAC_OS_X_VERSION_MAX_ALLOWED). Firstly, header is missing where those are defined, secondly, leading __ should be dropped. I also do not get the meaning of condition: this will be defined, as long as you include needed headers; normally this macro will involve a comparison to a specific number.

UPD1. While these should still be fixed, I believe, the error results from something else.

UPD2. Discussion is in #8090

@barracuda156
Copy link
Author

@Alizter @rgrinberg Could you please comment on the errors with 3.11.1 when trying to build dependents?

--->  Configuring ocaml-compiler-libs
--->  Building ocaml-compiler-libs
Executing:  cd "/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_ocaml_ocaml-compiler-libs/ocaml-compiler-libs/work/ocaml-compiler-libs-0.12.4" && /opt/local/bin/dune build -j 6 --root=/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_ocaml_ocaml-compiler-libs/ocaml-compiler-libs/work/ocaml-compiler-libs-0.12.4 --profile=release --ignore-promoted-rules --no-config --only-packages=ocaml-compiler-libs --default-target=@install @install 
File "src/shadow/dune", line 10, characters 0-147:
10 | (rule
11 |  (targets ocaml_shadow.ml)
12 |  (deps
13 |   (:first_dep gen/gen.exe))
14 |  (action
15 |   (run %{first_dep} -dir %{ocaml_where}/compiler-libs -o %{targets})))
Error: Rule failed to generate the following targets:
- src/shadow/ocaml_shadow.ml
File "src/ocaml_common/dune", line 8, characters 0-185:
 8 | (rule
 9 |  (targets ocaml_common.ml)
10 |  (deps
11 |   (:first_dep ../gen/gen.exe))
12 |  (action
13 |   (run
14 |    %{first_dep}
15 |    -archive
16 |    %{ocaml_where}/compiler-libs/ocamlcommon.cma
17 |    -o
18 |    %{targets})))
Error: Rule failed to generate the following targets:
- src/ocaml_common/ocaml_common.ml
File "src/ocaml_bytecomp/dune", line 8, characters 0-189:
 8 | (rule
 9 |  (targets ocaml_bytecomp.ml)
10 |  (deps
11 |   (:first_dep ../gen/gen.exe))
12 |  (action
13 |   (run
14 |    %{first_dep}
15 |    -archive
16 |    %{ocaml_where}/compiler-libs/ocamlbytecomp.cma
17 |    -o
18 |    %{targets})))
Error: Rule failed to generate the following targets:
- src/ocaml_bytecomp/ocaml_bytecomp.ml
File "src/ocaml_toplevel/dune", line 8, characters 0-189:
 8 | (rule
 9 |  (targets ocaml_toplevel.ml)
10 |  (deps
11 |   (:first_dep ../gen/gen.exe))
12 |  (action
13 |   (run
14 |    %{first_dep}
15 |    -archive
16 |    %{ocaml_where}/compiler-libs/ocamltoplevel.cma
17 |    -o
18 |    %{targets})))
Error: Rule failed to generate the following targets:
- src/ocaml_toplevel/ocaml_toplevel.ml
Command failed:  cd "/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_ocaml_ocaml-compiler-libs/ocaml-compiler-libs/work/ocaml-compiler-libs-0.12.4" && /opt/local/bin/dune build -j 6 --root=/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_ocaml_ocaml-compiler-libs/ocaml-compiler-libs/work/ocaml-compiler-libs-0.12.4 --profile=release --ignore-promoted-rules --no-config --only-packages=ocaml-compiler-libs --default-target=@install @install 
Exit code: 1

Ref to #8090 (comment)

@barracuda156 barracuda156 changed the title [macOS] dune build failure with ocaml 4.14.1: copyfile_stubs.c:45:39: error: 'COPYFILE_CLONE' undeclared (first use in this function); did you mean 'COPYFILE_MOVE'? [macOS] dune 3.11.1 errors (build itself works now, but building dependents fails) Oct 17, 2023
@Alizter
Copy link
Collaborator

Alizter commented Oct 17, 2023

Unfortunately Dune support for building the compiler itself is quite lacking. So I wouldn't recommend trying it unless your know what you are doing. If however you do want to press on https://github.com/ocaml-flambda/flambda-backend is a version of the compiler where they are developing compiler optimisations, and notably they have a much better time building (their fork of) the compiler with Dune. So there might be some things to learn there.

Unfortunately its unlikely we will be able to help you with the compiler build as it relies a lot on a custom rule set and custom layout. Which isn't really up to us to make sure it works properly.

The recommended option would be to use make to build the compiler the standard way.

@barracuda156
Copy link
Author

@Alizter Thank you. Here what I tried to build was ocaml-compiler-libs package, not OCaml itself. The package builds fine with Dune 3.7, in identical otherwise set-up.

@emillon
Copy link
Collaborator

emillon commented Oct 17, 2023

For your specific issue: I suspect that even with the #define mentioned before, the mac-specific file copy function fails, which is why the rule says that no target has been produced. You can try to use the portable path by setting DUNE_CONFIG__COPY_FILE=portable at runtime. That might work.

But look, we're not going to be actively looking for solutions about how to use dune 3.11 on macos 10.6. The dev team is already low on resources and we can't support a platform that has been EOL for more than 10 years.

Put differently, you're on your own here. If you come up with a 1-line fix that restores support, why not, but we can't help you with that.
Thanks

@emillon emillon closed this as completed Oct 17, 2023
@emillon emillon closed this as not planned Won't fix, can't repro, duplicate, stale Oct 17, 2023
@barracuda156
Copy link
Author

barracuda156 commented Oct 19, 2023

@Alizter @rgrinberg Update on dune: whatever failed in example above, dune 3.11.1 itself works fine on 10.6 PowerPC. I have built two dependents of janestreet ports, it worked normally.

@emillon I got you. Once I am sure that everything works neatly, I will submit a PR.
P. S. You were right, it fixed dune-configurator. (Took me a bit to find out how to pass it correctly via the portfile.)

@barracuda156 barracuda156 changed the title [macOS] dune 3.11.1 errors (build itself works now, but building dependents fails) [macOS] dune 3.11.1 errors (build itself works now, but building some of dependents fails) Oct 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants