@@ -75,10 +75,6 @@ export GPR2_BUILD=release
7575export VSS_BUILD_PROFILE=release
7676export PRETTIER_ADA_BUILD_MODE=prod
7777
78- # Global switch for a workaround on macOS. Set to non-empty to activate the
79- # workaround.
80- USE_GNAT_ADC_BASENAME=" "
81-
8278function activate_venv() {
8379 [ -d " $VENV_PATH " ] || python -m venv " $VENV_PATH "
8480 case " $NODE_ARCH_PLATFORM " in
@@ -151,106 +147,35 @@ EOF
151147 alr exec alr -- action -r post-fetch # Configure XmlAda, etc
152148}
153149
150+ # A temporary file for langkit setevn
151+ SETENV=$PWD /subprojects/libadalang/setenv.sh
152+
154153# Build langkit which is required to generate libadalang.
155- #
156- # The idea is to build langkit in the form of an installable wheel that
157- # contains all the dynamic libraries of dependencies such that Python can
158- # easily find everything at runtime. This avoids the security limitation of
159- # macOS not propagating DYLD_LIBRARY_PATH to child processes.
160154function build_langkit_raw() {
161155 (
162156 # Use a sub-shell to preserve the parent PWD
163157 cd subprojects/langkit_support
164158
165159 echo " GPR_PROJECT_PATH=$GPR_PROJECT_PATH "
166160
167- # Adjust the scenario variable for libgpr2
168161 sed -i.bak -e ' s/GPR_BUILD/GPR_LIBRARY_TYPE/' ./langkit/libmanage.py
162+ pip install .
163+ python manage.py make --no-mypy --generate-auto-dll-dirs \
164+ --library-types=relocatable --gargs " -cargs -fPIC"
169165
170- gprbuild_flag=" --gargs="
171- if [ -n " $USE_GNAT_ADC_BASENAME " ]; then
172- case " $NODE_ARCH_PLATFORM " in
173- * darwin* )
174- # On macOS, the full path of gnat.adc is stored in ALI files with case
175- # normalization. Upon re-runs, gprbuild is unable to match the
176- # normalized path with a non-case-normalized real path. This causes
177- # unnecessary recompilations at every run.
178- #
179- # To avoid that, we use the -gnateb flag which tells GNAT to not use
180- # an absolute path for gnat.adc
181- gprbuild_flag=" --gargs=-cargs:ada -gnateb"
182- ;;
183- esac
184- fi
166+ # Export the environment to use langkit into a file for later usage
167+ python manage.py setenv > " $SETENV "
185168
186- # Install base langkit support Python library
187- pip install .
169+ if [[ $NODE_ARCH_PLATFORM == " x64/win32" ]]; then
170+ # Fix setenv.sh to be bash script for MSYS2 by replacing
171+ # 1) C:\ -> /C/ 2) '\' -> '/' and ';' -> ':' 3) ": export" -> "; export"
172+ sed -i -e ' s#\([A-Z]\):\\#/\1/#g' -e ' y#\\;#/:#' -e ' s/: export /; export /' " $SETENV "
173+ cat " $SETENV "
174+ fi
188175
189- # Create a directory where langkit will be installed
190- prefix_dir=$PWD /lkt-install
191- rm -rf " $prefix_dir "
192- mkdir -p " $prefix_dir "
193- # Create a temporary dir used during the creation of the langkit wheel
194- tmp_dir=$PWD /lkt-tmp
195- rm -rf " $tmp_dir "
196- mkdir -p " $tmp_dir "
197- # Create a directory where all shared libraries that langkit depends on will
198- # be copied prior to the creation of the wheel
199- dep_lib_dir=" $PWD /dep-libs"
200- rm -rf " $dep_lib_dir "
201- mkdir -p " $dep_lib_dir "
202-
203- # This builds langkit, as well as all the library projects of the dependencies
204- python manage.py build-langkit-support \
205- --library-types=relocatable \
206- " $gprbuild_flag "
207- python manage.py install-langkit-support " $prefix_dir " \
208- --library-types=relocatable
209-
210- # Next build and install langkit
211- (cd contrib/lkt && ./manage.py make --library-types=relocatable --disable-all-mains " $gprbuild_flag " )
212- (cd contrib/lkt && ./manage.py install " $prefix_dir " \
213- --library-types=relocatable --disable-all-mains)
214-
215- case " $NODE_ARCH_PLATFORM " in
216- * win32* | * darwin* )
217- # on macOS, we want to copy all dependency libraries into the wheel to
218- # avoid relying on DYLD_LIBRARY_PATH which has security restrictions.
219-
220- # First we copy the libraries from the GNAT installation.
221- # Find the gnat installation directory
222- gnat_prefix=$( dirname " $( dirname " $( which gnat) " ) " )
223- # Copy the libraries. Exclude paths with dSYM on macOS because those have .dylib homonyms with debug symbols.
224- find " $gnat_prefix " -name " ${OS_LIB_PREFIX} gnarl*${OS_LIB_EXT} " -not -path " *dSYM*" -exec cp -v {} " $dep_lib_dir " \;
225- find " $gnat_prefix " -name " ${OS_LIB_PREFIX} gnat*${OS_LIB_EXT} " -not -path " *dSYM*" -exec cp -v {} " $dep_lib_dir " \;
226-
227- # Alire projects are either in the als/alire/cache directory, or in
228- # als/subprojects.
229- find ../../alire/cache/dependencies .. -name " ${OS_LIB_PREFIX} *${OS_LIB_EXT} " -exec cp -v {} " $dep_lib_dir " \;
230- ;;
231- esac
232-
233- # Finally build the wheel
234- pip install wheel # necessary to make python setup.py bdist_wheel work
235- (cd contrib/lkt && ./manage.py create-wheel \
236- --verbosity=debug \
237- --with-python=python \
238- " $prefix_dir " \
239- " $tmp_dir " \
240- " $dep_lib_dir " \
241- " $prefix_dir " )
242-
243- # And now install the resulting wheel into the Python environment
244- pip install " $prefix_dir " /* .whl --force-reinstall
245-
246- case " $NODE_ARCH_PLATFORM " in
247- * linux* )
248- # On Linux shared libraries are not built with the right RPATH entries
249- # to make them movable. So we delete the installed library and instead
250- # use LD_LIBRARY_PATH to resolve it. See set_langkit_usage_env().
251- find " $VENV_PATH " -name " liblktlang.so" -delete
252- ;;
253- esac
176+ # Clean `.ali` and `.o` to avoid static vis relocatable mess
177+ find . -name ' *.o' -delete
178+ find . -name ' *.ali' -delete
254179 )
255180}
256181
@@ -259,39 +184,41 @@ function build_langkit() {
259184 # We use 'alr exec' to benefit from Alire setting up GPR_PROJECT_PATH with
260185 # all the dependencies.
261186 alr exec bash -- -x " $0 " build_langkit_raw
262-
263- # Check if the langkit build was successful
264- set_langkit_usage_env
265- python -c ' import liblktlang'
266187}
267188
268189function set_langkit_usage_env() {
269- case " $NODE_ARCH_PLATFORM " in
270- * linux* )
271- lib_path_prefix=$PWD /subprojects/langkit_support/contrib/lkt/build/lib/relocatable
272- export LD_LIBRARY_PATH=" $lib_path_prefix /dev:$lib_path_prefix /prod:$LD_LIBRARY_PATH "
273- ;;
274- esac
190+ ADALIB=$( alr exec gcc -- -print-libgcc-file-name)
191+
192+ if [[ $NODE_ARCH_PLATFORM == " x64/win32" ]]; then
193+ ADALIB=$( cygpath -u " $ADALIB " )
194+ # libgcc_s_seh-1.dll is already in PATH
195+
196+ elif [[ $NODE_ARCH_PLATFORM == " x64/linux" ]]; then
197+ NEW_PATH=$( dirname " $( alr exec gcc -- -print-file-name=libgcc_s.so.1) " )
198+ else
199+ NEW_PATH=$( dirname " $( alr exec gcc -- -print-file-name=libgcc_s.dylib.1) " )
200+ fi
201+
202+ ADALIB=$( dirname " $ADALIB " ) /adalib
203+ DEPS=$PWD /alire/cache/dependencies
204+ NEW_PATH=$ADALIB :$NEW_PATH
205+
206+ for ITEM in $DEPS /* /{iconv,gmp,schema,dom,sax,input_sources,unicode}; do
207+ [ -d " $ITEM " ] && NEW_PATH=$ITEM /lib/relocatable:$NEW_PATH
208+ done
209+
210+ echo " NEW_PATH=$NEW_PATH "
211+ export DYLD_LIBRARY_PATH=$NEW_PATH :$DYLD_LIBRARY_PATH
212+ export PATH=$NEW_PATH " :$PATH "
213+
214+ source " $SETENV "
275215}
276216
277217# Build ALS with alire
278218function build_als() {
219+ # Check if langkit is usable
279220 set_langkit_usage_env
280-
281- if [ -n " $USE_GNAT_ADC_BASENAME " ]; then
282- case " $NODE_ARCH_PLATFORM " in
283- * darwin* )
284- # On macOS, the full path of gnat.adc is stored in ALI files with case
285- # normalization. Upon re-runs, gprbuild is unable to match the
286- # normalized path with a non-case-normalized real path. This causes
287- # unnecessary recompilations at every run.
288- #
289- # To avoid that, we use the -gnateb flag which tells GNAT to not use
290- # an absolute path for gnat.adc
291- gprbuild_flag=" -vm -cargs:ada -gnateb -bargs -v"
292- ;;
293- esac
294- fi
221+ python -c ' import liblktlang'
295222
296223 # We use 'alr exec' to benefit from Alire setting up GPR_PROJECT_PATH with
297224 # all the dependencies.
0 commit comments