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

Linking issue on osx-arm64 #28

Closed
1 task done
mlondschien opened this issue Jan 3, 2024 · 38 comments
Closed
1 task done

Linking issue on osx-arm64 #28

mlondschien opened this issue Jan 3, 2024 · 38 comments
Labels
bug Something isn't working

Comments

@mlondschien
Copy link
Member

mlondschien commented Jan 3, 2024

Solution to issue cannot be found in the documentation.

  • I checked the documentation.

Issue

I received a bug report that installing changeforest with conda results in linkage issues. I was able to reproduce the error on an osx-arm64 (M1 Macbook) machine.

(r-test) ~ $ R

R version 4.3.2 (2023-10-31) -- "Eye Holes"
Copyright (C) 2023 The R Foundation for Statistical Computing
Platform: aarch64-apple-darwin20.0.0 (64-bit)

R ist freie Software und kommt OHNE JEGLICHE GARANTIE.
Sie sind eingeladen, es unter bestimmten Bedingungen weiter zu verbreiten.
Tippen Sie 'license()' or 'licence()' für Details dazu.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Tippen Sie 'demo()' für einige Demos, 'help()' für on-line Hilfe, oder
'help.start()' für eine HTML Browserschnittstelle zur Hilfe.
Tippen Sie 'q()', um R zu verlassen.

[Vorher gesicherter Workspace wiederhergestellt]

> library(changeforest)
Fehler: Laden von Paket oder Namensraum fürchangeforestin dyn.load(file, DLLpath = DLLpath, ...): fehlgeschlagen
 kann shared object '/Users/mlondschien/mambaforge/envs/r-test/lib/R/library/changeforest/libs/changeforest.dylib' nicht laden:
  dlopen(/Users/mlondschien/mambaforge/envs/r-test/lib/R/library/changeforest/libs/changeforest.dylib, 0x0006): symbol not found in flat namespace '_R_init_changeforestr_extendr'
> 

Suprisingly, this used to work when I last tested (~1 year ago). Downgrading did not solve the issue. Could this be an OS compatability issue? I upgraded to OSX 13 (Ventura) since last testing this. Building the package locally (R CMD INSTALL --build changeforest-r) works, as long as I add -F/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/ to the PGK_LIBS flags in the Makevars.


(r-test) ~ $ mamba install r-changeforest=0.6.0

Looking for: ['r-changeforest=0.6.0']

conda-forge/osx-arm64                                       Using cache
conda-forge/noarch                                          Using cache
Transaction

  Prefix: /Users/mlondschien/mambaforge/envs/r-test

  Updating specs:

   - r-changeforest=0.6.0
   - ca-certificates
   - openssl


  Package           Version  Build                 Channel           Size
───────────────────────────────────────────────────────────────────────────
  Install:
───────────────────────────────────────────────────────────────────────────

  + libcblas          3.9.0  20_osxarm64_openblas  conda-forge     Cached
  + gsl                 2.7  h6e638da_0            conda-forge     Cached

  Change:
───────────────────────────────────────────────────────────────────────────

  - libllvm17        17.0.6  haab561b_1            conda-forge     Cached
  + libllvm17        17.0.6  hc359061_0            conda-forge       25MB
  - llvm-tools       17.0.6  haab561b_1            conda-forge     Cached
  + llvm-tools       17.0.6  hc359061_0            conda-forge       22MB
  - r-r6              2.5.1  r43hc72bb7e_2         conda-forge     Cached
  + r-r6              2.5.1  r41hc72bb7e_1         conda-forge       92kB

  Downgrade:
───────────────────────────────────────────────────────────────────────────

  - pcre2             10.42  h26f9a81_0            conda-forge     Cached
  + pcre2             10.40  hb34f9b4_0            conda-forge     Cached
  - libxml2          2.12.3  h0d0cfa8_0            conda-forge     Cached
  + libxml2          2.11.6  h0d0cfa8_0            conda-forge      589kB
  - libglib          2.78.3  hb438215_0            conda-forge     Cached
  + libglib          2.78.1  hd9b11f9_0            conda-forge     Cached
  - r-base            4.3.2  h9389748_1            conda-forge     Cached
  + r-base            4.1.3  hc95f692_12           conda-forge       26MB
  - r-changeforest    1.1.2  r43h4614cfb_0         conda-forge     Cached
  + r-changeforest    0.6.0  r41h1ed4d5f_0         conda-forge       88kB

  Summary:

  Install: 2 packages
  Change: 3 packages
  Downgrade: 5 packages

  Total download: 73MB

───────────────────────────────────────────────────────────────────────────


Confirm changes: [Y/n] y
r-r6                                                92.4kB @ 451.0kB/s  0.2s
libxml2                                            588.7kB @   2.7MB/s  0.2s
r-changeforest                                      88.3kB @ 150.3kB/s  0.4s
r-base                                              25.7MB @   7.6MB/s  3.4s
libllvm17                                           24.6MB @   4.8MB/s  5.1s
llvm-tools                                          21.8MB @   3.9MB/s  5.5s

Downloading and Extracting Packages

Preparing transaction: done
Verifying transaction: done
Executing transaction: done
(r-test) ~ $ R
library
R version 4.1.3 (2022-03-10) -- "One Push-Up"
Copyright (C) 2022 The R Foundation for Statistical Computing
Platform: aarch64-apple-darwin20.0.0 (64-bit)

R ist freie Software und kommt OHNE JEGLICHE GARANTIE.
Sie sind eingeladen, es unter bestimmten Bedingungen weiter zu verbreiten.
Tippen Sie 'license()' or 'licence()' für Details dazu.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Tippen Sie 'demo()' für einige Demos, 'help()' für on-line Hilfe, oder
'help.start()' für eine HTML Browserschnittstelle zur Hilfe.
Tippen Sie 'q()', um R zu verlassen.

[Vorher gesicherter Workspace wiederhergestellt]

(changefores> library(changeforest)
Fehler: Laden von Paket oder Namensraum für ‘changeforest’ in dyn.load(file, DLLpath = DLLpath, ...): fehlgeschlagen
 kann shared object '/Users/mlondschien/mambaforge/envs/r-test/lib/R/library/changeforest/libs/changeforest.dylib' nicht laden:
  dlopen(/Users/mlondschien/mambaforge/envs/r-test/lib/R/library/changeforest/libs/changeforest.dylib, 0x0006): symbol not found in flat namespace '_R_init_changeforestr_extendr'
> 

@xhochy, is there anything that immediately comes to mind?

(r-test) ~ $ conda list
# packages in environment at /Users/mlondschien/mambaforge/envs/r-test:
#
# Name                    Version                   Build  Channel
_r-mutex                  1.0.1               anacondar_1    conda-forge
bwidget                   1.9.14               hce30654_1    conda-forge
bzip2                     1.0.8                h93a5062_5    conda-forge
c-ares                    1.24.0               h93a5062_0    conda-forge
ca-certificates           2023.11.17           hf0a4a13_0    conda-forge
cairo                     1.18.0               hd1e100b_0    conda-forge
cctools_osx-arm64         973.0.1             h998149b_15    conda-forge
clang                     17.0.6               haab561b_1    conda-forge
clang-17                  17.0.6          default_hd209bcb_1    conda-forge
clang_impl_osx-arm64      17.0.6               he47c785_7    conda-forge
clang_osx-arm64           17.0.6               h54d7cd3_7    conda-forge
clangxx                   17.0.6          default_h5c94ee4_1    conda-forge
clangxx_impl_osx-arm64    17.0.6               h50f59cd_7    conda-forge
clangxx_osx-arm64         17.0.6               h54d7cd3_7    conda-forge
compiler-rt               17.0.6               h3808999_1    conda-forge
compiler-rt_osx-arm64     17.0.6               h3808999_1    conda-forge
curl                      8.5.0                h2d989ff_0    conda-forge
expat                     2.5.0                hb7217d7_1    conda-forge
font-ttf-dejavu-sans-mono 2.37                 hab24e00_0    conda-forge
font-ttf-inconsolata      3.000                h77eed37_0    conda-forge
font-ttf-source-code-pro  2.038                h77eed37_0    conda-forge
font-ttf-ubuntu           0.83                 h77eed37_1    conda-forge
fontconfig                2.14.2               h82840c6_0    conda-forge
fonts-conda-ecosystem     1                             0    conda-forge
fonts-conda-forge         1                             0    conda-forge
freetype                  2.12.1               hadb7bae_2    conda-forge
fribidi                   1.0.10               h27ca646_0    conda-forge
gettext                   0.21.1               h0186832_0    conda-forge
gfortran_impl_osx-arm64   12.3.0               hbbb9e1e_1    conda-forge
gfortran_osx-arm64        12.3.0               h57527a5_1    conda-forge
gmp                       6.3.0                h965bd2d_0    conda-forge
graphite2                 1.3.13            h9f76cd9_1001    conda-forge
harfbuzz                  8.3.0                h8f0ba13_0    conda-forge
icu                       73.2                 hc8870d7_0    conda-forge
isl                       0.25                 h9a09cb3_0    conda-forge
krb5                      1.21.2               h92f50d5_0    conda-forge
ld64_osx-arm64            609                 h6a44367_15    conda-forge
lerc                      4.0.0                h9a09cb3_0    conda-forge
libblas                   3.9.0           20_osxarm64_openblas    conda-forge
libclang-cpp17            17.0.6          default_hd209bcb_1    conda-forge
libcurl                   8.5.0                h2d989ff_0    conda-forge
libcxx                    16.0.6               h4653b0c_0    conda-forge
libdeflate                1.19                 hb547adb_0    conda-forge
libedit                   3.1.20191231         hc8eb9b7_2    conda-forge
libev                     4.33                 h93a5062_2    conda-forge
libexpat                  2.5.0                hb7217d7_1    conda-forge
libffi                    3.4.2                h3422bc3_5    conda-forge
libgfortran               5.0.0           13_2_0_hd922786_1    conda-forge
libgfortran-devel_osx-arm64 12.3.0               hc62be1c_1    conda-forge
libgfortran5              13.2.0               hf226fd6_1    conda-forge
libglib                   2.78.3               hb438215_0    conda-forge
libiconv                  1.17                 h0d3ecfb_2    conda-forge
libjpeg-turbo             3.0.0                hb547adb_1    conda-forge
liblapack                 3.9.0           20_osxarm64_openblas    conda-forge
libllvm17                 17.0.6               haab561b_1    conda-forge
libnghttp2                1.58.0               ha4dd798_1    conda-forge
libopenblas               0.3.25          openmp_h6c19121_0    conda-forge
libpng                    1.6.39               h76d750c_0    conda-forge
libssh2                   1.11.0               h7a5bd25_0    conda-forge
libtiff                   4.6.0                ha8a6c65_2    conda-forge
libwebp-base              1.3.2                hb547adb_0    conda-forge
libxml2                   2.12.3               h0d0cfa8_0    conda-forge
libzlib                   1.2.13               h53f4e23_5    conda-forge
llvm-openmp               17.0.6               hcd81f8e_0    conda-forge
llvm-tools                17.0.6               haab561b_1    conda-forge
make                      4.3                  he57ea6c_1    conda-forge
mpc                       1.3.1                h91ba8db_0    conda-forge
mpfr                      4.2.1                h9546428_0    conda-forge
ncurses                   6.4                  h463b476_2    conda-forge
openssl                   3.2.0                h0d3ecfb_1    conda-forge
pango                     1.50.14              hcf40dda_2    conda-forge
pcre2                     10.42                h26f9a81_0    conda-forge
pixman                    0.42.2               h13dd4ca_0    conda-forge
r-base                    4.3.2                h9389748_1    conda-forge
r-changeforest            1.1.2             r43h4614cfb_0    conda-forge
r-r6                      2.5.1             r43hc72bb7e_2    conda-forge
readline                  8.2                  h92ec313_1    conda-forge
sigtool                   0.1.3                h44b9a77_0    conda-forge
tapi                      1100.0.11            he4954df_0    conda-forge
tk                        8.6.13               h5083fa2_1    conda-forge
tktable                   2.10                 hd996620_5    conda-forge
xz                        5.2.6                h57fd34a_0    conda-forge
zlib                      1.2.13               h53f4e23_5    conda-forge
zstd                      1.5.5                h4f39d0f_0    conda-forge
(r-test) ~ $ conda info 

     active environment : r-test
    active env location : /Users/mlondschien/mambaforge/envs/r-test
            shell level : 2
       user config file : /Users/mlondschien/.condarc
 populated config files : /Users/mlondschien/mambaforge/.condarc
                          /Users/mlondschien/.config/conda/.condarc
          conda version : 23.5.2
    conda-build version : not installed
         python version : 3.10.12.final.0
       virtual packages : __archspec=1=arm64
                          __osx=13.2.1=0
                          __unix=0=0
       base environment : /Users/mlondschien/mambaforge  (writable)
      conda av data dir : /Users/mlondschien/mambaforge/etc/conda
  conda av metadata url : None
           channel URLs : https://conda.anaconda.org/conda-forge/osx-arm64
                          https://conda.anaconda.org/conda-forge/noarch
          package cache : /Users/mlondschien/mambaforge/pkgs
                          /Users/mlondschien/.conda/pkgs
       envs directories : /Users/mlondschien/mambaforge/envs
                          /Users/mlondschien/.conda/envs
               platform : osx-arm64
             user-agent : conda/23.5.2 requests/2.31.0 CPython/3.10.12 Darwin/22.3.0 OSX/13.2.1
                UID:GID : 501:20
             netrc file : None
           offline mode : False
@mlondschien mlondschien added the bug Something isn't working label Jan 3, 2024
@mlondschien
Copy link
Member Author

@conda-forge/r Any ideas about what might be the issue here? Help would be much appreciated.

@mfansler
Copy link
Member

mfansler commented Jan 5, 2024

I can recreate (both new and old versions) on macOS 14.1.2.

Checking linking with otool -L, I do notice that osx-arm64 builds are not linking to libR.dylib. That is,

r-changeforest=1.1.2 osx-64

$ otool -L lib/R/library/changeforest/libs/changeforest.dylib    
lib/R/library/changeforest/libs/changeforest.dylib:
	@rpath/R/library/changeforest/libs/changeforest.dylib (compatibility version 0.0.0, current version 0.0.0)
	@rpath/R/lib/libR.dylib (compatibility version 4.3.0, current version 4.3.2)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1197.1.1)

r-changeforest=1.1.2 osx-arm64

$ otool -L lib/R/library/changeforest/libs/changeforest.dylib    
lib/R/library/changeforest/libs/changeforest.dylib:
	@rpath/R/library/changeforest/libs/changeforest.dylib (compatibility version 0.0.0, current version 0.0.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1292.0.0)

r-changeforest=0.6.0 osx-arm64

$ otool -L lib/R/library/changeforest/libs/changeforest.dylib    
lib/R/library/changeforest/libs/changeforest.dylib:
	@rpath/R/library/changeforest/libs/changeforest.dylib (compatibility version 0.0.0, current version 0.0.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1292.0.0)

I can't look more right now, but this issue seems novel.

@mfansler
Copy link
Member

mfansler commented Jan 6, 2024

Latest logs (v1.1.2) had:

WARNING: The install/build script(s) for r-changeforest deleted the following files (from dependencies) from the prefix:
['lib/R/lib/libRblas.dylib', 'lib/R/lib/libRlapack.dylib']

Never seen that before and only happens in the osx-arm64 builds. The location is notably also where the libR.dylib would be, however, it is not indicated as deleted and there is definitely a -L$PREFIX/lib/R/lib -lR in the final command to generate changeforest.dylib. That would throw an error if it wasn't found, but doesn't mean it had to be used.

Still at a loss for ideas. If something overwrote the libR.dylib, would Conda detect that? Or maybe this isn't even the right thread to pull.

@mlondschien
Copy link
Member Author

Thanks @mfansler for looking into this! In 1.1.1 to 1.1.2 I upgraded extendr-api from 0.2.0 - > 0.6.0. Pinging some more people that might have an idea whats going on: @Ilia-Kosenkov @clauswilke @yutannihilation

@Ilia-Kosenkov
Copy link

Hi! Thanks for pinging. I believe upgrading extendr-api (which is still under development and introduces breaking changes) might be the reason. Internally, it depends on libR-sys, which generates bindings and links to R. I have no apple silicon at hand to test this, and we do not have arm build on CI yet, so I will try to check what has been changed in the past couple of versions manually.

@yutannihilation
Copy link

@mlondschien
Do you mean installing v1.1.1 succeeds while v1.1.2 fails?

@JosiahParry
Copy link

JosiahParry commented Jan 6, 2024

The PR I introduced into your original repo should resolve this issue mlondschien/changeforest#162

@mlondschien
Copy link
Member Author

Thanks all!

Do you mean installing v1.1.1 succeeds while v1.1.2 fails?

No, both fail. I updated as I hoped this might fix the issue.

Thanks @JosiahParry. This is super helpful! I merged and prepared a new release. Let's see if this did the trick.

Your package builds and compiles fine on Mac M1 ARM.

It does (did) so as well on my machine. The error occurs only when installing the package with conda.

Checking linking with otool -L, I do notice that osx-arm64 builds are not linking to libR.dylib.

This is the input after implementing @JosiahParry's changes. What am I looking for here. Do you maybe have a reference to read into @mfansler?

(r-test) mambaforge/envs/r-test $ otool -L lib/R/library/changeforest/libs/changeforest.dylib 
lib/R/library/changeforest/libs/changeforest.dylib:
        changeforest.dylib (compatibility version 0.0.0, current version 0.0.0)
        @rpath/R/lib/libR.dylib (compatibility version 4.1.0, current version 4.1.3)
        /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1319.100.3)

@JosiahParry, if I understand correctly you released your rust/R package rsgeo on CRAN, including Windows. Two years ago I remember this was rather cumbersome. Has this changed? Do you have a reference on how to do this?

@JosiahParry
Copy link

I don't know how conda forge works at all but it looks like the "recipe" might be used and that it injects the version of libR-sys to use https://github.com/conda-forge/r-changeforest-feedstock/blob/main/recipe/build.sh. I don't think that is necessary. R CMD install should be sufficient.

Yes, publishing to packages to CRAN is not too difficult anymore thanks to the work of @yutannihilation among others!

There is a vignette that describes the process but its not actually rendered at the moment. I'm happy to help walk through the way that I've been able to accomplish this. If you're in the extendr discord that might be a good place to get informal feedback.

https://github.com/extendr/rextendr/blob/main/vignettes/articles/cran-compliance.Rmd

@mfansler
Copy link
Member

mfansler commented Jan 6, 2024

Checking linking with otool -L, I do notice that osx-arm64 builds are not linking to libR.dylib.

This is the input after implementing @JosiahParry's changes. What am I looking for here. Do you maybe have a reference to read into @mfansler?

(r-test) mambaforge/envs/r-test $ otool -L lib/R/library/changeforest/libs/changeforest.dylib 
lib/R/library/changeforest/libs/changeforest.dylib:
        changeforest.dylib (compatibility version 0.0.0, current version 0.0.0)              # reference to itself (fine)
        @rpath/R/lib/libR.dylib (compatibility version 4.1.0, current version 4.1.3)         # reference to libR using R path (good)
        /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1319.100.3) # reference to macOS SDK (good)

Unfortunately, no reference AFAIK - just my observation that compiled R packages on Conda Forge typically link against libR.dylib. The above looks correct (commented above), but the v1.1.13 build still did not capture it when building. However, I have little experience with Rust + R, so I can't rule out some exceptional behavior. So, I recommend testing the artifacts on the new PR before merging.

Might also be worth noting here that we use macOS SDK 10.9 target (still!) for osx-64 and SDK 11 for osx-arm64. There are linker warnings in the osx-64 builds that the build targets 10.12, but links against 10.9. That could indicate the build is not respecting the flags we set. For now though, that part does seem to at least link correctly.

@Ilia-Kosenkov
Copy link

Is it possible that in conda-arm environment we fail here? We fail to resolve library paths and omit this from linking step? https://github.com/extendr/libR-sys/blob/6fc2b5f2371fe20ec53d2cdf845a6e13dfdd3cfe/build.rs#L649-L651
@yutannihilation, since you touched this the last, what do you think?

@mlondschien
Copy link
Member Author

I don't know how conda forge works at all but it looks like the "recipe" might be used and that it injects the version of libR-sys to use https://github.com/conda-forge/r-changeforest-feedstock/blob/main/recipe/build.sh. I don't think that is necessary. R CMD install should be sufficient.

This is necessary to allow cross-compiling. xref extendr/libR-sys#85

Yes, publishing to packages to CRAN is not too difficult anymore thanks to the work of @yutannihilation among others!

Thanks! I'll have a look.

So, I recommend testing the artifacts on the new PR before merging.

How would I do this?

@Ilia-Kosenkov
Copy link

@mlondschien , were there any specific steps you undertook to install R & this package from conda-froge? I am considering renting an M1 server to debug this issue & I need step-by-step guide to reproduce it.

@mlondschien
Copy link
Member Author

I used mambaforge (now called Miniforge IIUC), to create a new environment (mamba env create -n r-test) and then installed r-base and r-changeforest (conda activate r-test && mamba install r-base r-changeforest).

@mfansler
Copy link
Member

mfansler commented Jan 6, 2024

Testing Artifacts

So, I recommend testing the artifacts on the new PR before merging.

How would I do this?

One can get to artifacts from looking at the Azure summary for the run, which will show a link to artifacts:

Screenshot 2024-01-06 at 2 22 59 PM

That brings you to here, where clicking on the vertical ellipsis gives an option to download an artifact from a run:

Screenshot 2024-01-06 at 2 26 00 PM

Unzip (twice) the archive file. You should see a channeldata.json in the directory:

Screenshot 2024-01-06 at 2 29 56 PM

Then use that folder as a "channel" when creating/installing in an environment to use the package(s) there:

$ cd r-changeforest-feedstock_conda_artifacts_20240106.4.1_osx_arm64_r_base4.3
$ mamba create -n test-changeforest -c ./ -c conda-forge r-changeforest

Testing with this, I still see the same issue:

$ mamba run -n test-changeforest R -e "library(changeforest)"

R version 4.3.2 (2023-10-31) -- "Eye Holes"
Copyright (C) 2023 The R Foundation for Statistical Computing
Platform: aarch64-apple-darwin20.0.0 (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(changeforest)
Error: package or namespace load failed for ‘changeforest’ in dyn.load(file, DLLpath = DLLpath, ...):
 unable to load shared object '/Users/mfansler/mambaforge-arm64/envs/test-changeforest/lib/R/library/changeforest/libs/changeforest.dylib':
  dlopen(/Users/mfansler/mambaforge-arm64/envs/test-changeforest/lib/R/library/changeforest/libs/changeforest.dylib, 0x0006): symbol not found in flat namespace '_R_init_changeforest_extendr'
Execution halted

@JosiahParry
Copy link

@mfansler
Copy link
Member

mfansler commented Jan 6, 2024

@JosiahParry it's a false positive. Conda Forge doesn't run tests on osx-arm64 builds, hence the need to download and test artifacts on native hardware.

@yutannihilation
Copy link

yutannihilation commented Jan 7, 2024

Is it possible that in conda-arm environment we fail here? We fail to resolve library paths and omit this from linking step?

In my understanding, as the code comment says, rustc-link-search is used only on embedded usages. So, it shouldn't matter here.

@yutannihilation
Copy link

To my eyes, this looks the core of the problem. Maybe you simply need to specify --target=aarch64-apple-darwin?

ld: warning: ignoring file ./rust/target/release/libchangeforestr.a, building for macOS-arm64 but attempting to link with file built for macOS-x86_64

https://dev.azure.com/conda-forge/feedstock-builds/_build/results?buildId=853942&view=logs&j=15f8dc28-9f6f-5e3a-5b3c-2b169071e5be&t=1a4c7350-22aa-5d5b-9589-f36c9946ec39&l=503

@Ilia-Kosenkov

This comment was marked as off-topic.

@Ilia-Kosenkov
Copy link

To my eyes, this looks the core of the problem. Maybe you simply need to specify --target=aarch64-apple-darwin?

ld: warning: ignoring file ./rust/target/release/libchangeforestr.a, building for macOS-arm64 but attempting to link with file built for macOS-x86_64

https://dev.azure.com/conda-forge/feedstock-builds/_build/results?buildId=853942&view=logs&j=15f8dc28-9f6f-5e3a-5b3c-2b169071e5be&t=1a4c7350-22aa-5d5b-9589-f36c9946ec39&l=503

After investigating a lot of things and moving in a wrong direction, I am now convinced this might be the case -- the library produced for arm64 by your pipeline is much smaller than that build locally on arm64 machine. I suspect it does not link at all and hence cannot find a symbol (which is defined in rust library). @yutannihilation is likely correct

void R_init_changeforest_extendr(void *dll);

void R_init_changeforest(void *dll) {
    R_init_changeforest_extendr(dll);
}

@Ilia-Kosenkov
Copy link

A fellow project that uses cross-compilation on mac os (successfully, I think), seems to set TARGET in Makevars https://github.com/pola-rs/r-polars/blob/89fe7196422a5477307db1015dbd139ad323158c/src/Makevars.in#L1
based on configuration
https://github.com/pola-rs/r-polars/blob/89fe7196422a5477307db1015dbd139ad323158c/configure#L114

@mlondschien
Copy link
Member Author

Thanks @Ilia-Kosenkov for looking into this!

I'm confused. Wouldn't this line

sed -e "s|@RUST_TARGET@|$(rustc -vV | grep host | cut -d' ' -f2)|" 

set @RUST_TARGET@ as the host architecture, which might not be what we want if cross-compiling to osx-arm64? Is r-polars even on conda?

Another note: The R error mentions _R_init_changeforestr_extendr, while the function defined in the entrypoint.c is called void R_init_changeforest_extendr(void *dll);.

@Ilia-Kosenkov
Copy link

Yes but this happens only if RUST_TARGET is unspecified. So you can set RUST_TARGET to arm64 architecture to do cross-compilation.

Yep I noticed that it has an underscore prefix, but this name is tied to a function we generate for package changeforestr, so the only reason it can be missing is that it was not linked during compilation. And the warning that @yutannihilation found looks like a symptom of this issue.

@mlondschien
Copy link
Member Author

mlondschien commented Jan 7, 2024

Thanks. I had missed this. mlondschien/changeforest#165 should do the trick if we set TARGET somewhere in the conda build, right?

@mfansler
Copy link
Member

mfansler commented Jan 9, 2024

Neither TARGET, RUST_TARGET, nor CARGO_BUILD_TARGET variables seem to be respected when set in build.sh.

@CGMossa
Copy link

CGMossa commented Jan 9, 2024

Is this a case of these variables needing to be export'd?

@mlondschien
Copy link
Member Author

TARGET does not get ignored. It gets correctly invoked which is why these tests failed with

error[E0463]: can't find crate for `std`
  |
  = note: the `aarch64-apple-darwin` target may not be installed
  = help: consider downloading the target with `rustup target add aarch64-apple-darwin`

I added rustup target add aarch64-apple-darwin to the build.sh here resulting in

/Users/runner/miniforge3/conda-bld/r-changeforest_1704747527460/work/conda_build.sh: line 9: rustup: command not found

Can I add the target aarch64-apple-darwin via the recipe/meta.yaml?

@xhochy
Copy link
Member

xhochy commented Jan 9, 2024

@mlondschien From which PR is the referenced output?

@xhochy
Copy link
Member

xhochy commented Jan 9, 2024

Also, you should not be using rustup. The conda packages should have everything included.

@mlondschien
Copy link
Member Author

mlondschien commented Jan 9, 2024

@mlondschien From which PR is the referenced output?

This one: #33. The first error is from this commit.

@xhochy
Copy link
Member

xhochy commented Jan 9, 2024

Pushed a fix to the feedstock 695513b and made an upstream PR: mlondschien/changeforest#168 I have verified locally beforehand that it works.

@mlondschien
Copy link
Member Author

Thanks! Will CARGO_BUILD_TARGET be set automatically on the conda cross compiling machine or does this need to be set in the build.sh?

@xhochy
Copy link
Member

xhochy commented Jan 9, 2024

It's set by the compiler package that I have added in the change.

@mlondschien
Copy link
Member Author

Thanks @xhochy and everyone who looked into this! This did the trick.

As suspected by @yutannihilation and @Ilia-Kosenkov, this was missing a --target aarch64-apple-darwin when cross-compiling. The rustup: command not found was solved by replacing - rust with - {{ compiler('rust') }} in the meta.yamls build requirments.

@Ilia-Kosenkov
Copy link

Hey @mlondschien , thanks for the update! I was not following the issue the past day or two, if it resolved now, or is it still broken for aarch64?

@mlondschien
Copy link
Member Author

Yes. I just checked installing directly from conda-forge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

7 participants