rajan.yadav
2021-4-9 11:00:39

@rajan.yadav has joined the channel


rajan.yadav
2021-4-9 11:04:14

Hi all! Is there a way to set rpath for racket linux executables using ffi libs, so that there is no need to set LD_LIBRARY_PATH at target system?


samth
2021-4-9 13:26:57

I have not tried that, but it seems like it would work. There is not currently a mechanism in the Racket build process to do that automatically.


samth
2021-4-9 13:28:38

You could set CCFLAGS when compiling, which would probably enable this.


samth
2021-4-9 13:29:02

@hazel You might be interested in this idea, which might allow you to get rid of the wrapper script on Nix.


soegaard2
2021-4-9 14:37:31

@rajan.yadav I hope, I got the context right. You wanted to distribute an application written in Racket. A package uses a shared library (not part of the pacakage) and the problem is now to include the shared library when raco distribute is used?


rajan.yadav
2021-4-9 14:49:50

Including shared libs in distribution isn’t a problem. It can be done by using collects flags. The problem I am having is that executable isn’t using bundled shared libs without setting LD_LIBRARY_PATH on target machine. I have a requirement where setting LD_LIBRARY_PATH isn’t an option and must work without it out of the box


rajan.yadav
2021-4-9 14:50:12

@samth thanks. I’ll try it out


hazel
2021-4-9 16:24:27

I’ll look into this — I already planned on submitting a PR to nixpkgs when 8.1 is out


rajan.yadav
2021-4-9 16:26:47

@hazel what is the wrapper script workaround?


hazel
2021-4-9 16:28:27

#!/bin/sh export LD_LIBRARY_PATH="what-you-want-it-to-be" exec /path/to/actual/racket


hazel
2021-4-9 16:29:11

’tis a real masterpiece of engineering


rajan.yadav
2021-4-9 16:40:57

Lol I imagined a bunch of magical gcc flags being passed to raco :grinning:


ryanc
2021-4-9 16:46:11

@rajan.yadav to clarify, are you talking about something built with raco distribute? If so, are you using define-runtime-path to define the path you use to load the library?


rajan.yadav
2021-4-9 17:33:07

@ryanc Yes. I am talking about something built with raco distribute. And yes, I experimented with define-runtime-path in my code . But ffi libs are used in sci/flomat package which doesn’t do that. I imagine define-runtime-path should be used in that module (flomat) for it to work right ? Its a long shout but I can try modifying flomat’s code and see if that works.


samth
2021-4-9 17:34:12

I think define-runtime-path would not work for flomat, since it’s intended to be able to work with existing .so libraries in multiple places that are not known at compile time.


rajan.yadav
2021-4-9 17:37:51

Yes, that is what I thought. Therefore my preference is to somehow hardwire lib search paths within executable. This is very trivial to do directly using gcc.



rajan.yadav
2021-4-9 17:39:05

Lets see how that goes


samth
2021-4-9 17:43:38

A few things about that: 1. raco exe (which is the same as create-embedding-executable) doesn’t call gcc to create the executable. 2. “extensions” in the sense of current-extension-linker-flags are not what flomat or other ffi-using libraries use.


soegaard2
2021-4-9 17:43:54

Btw - I think dynext is a package for compiling/linking C files - so I don’t see the connection to the problem.


soegaard2
2021-4-9 17:45:19

What if … define-runtime-path is used in Rajan’s code with the BLAS/LAPACK he needs - wouldn’t flomat automatically pick the same instances up?


samth
2021-4-9 17:45:44

Yes, I think that would work.


samth
2021-4-9 17:46:22

Well, maybe. I’m not sure if the result of raco distribute would put the so in a location that ffi-lib would find by default.


samth
2021-4-9 17:46:52

flomat could provide a way to specify that path, and then @rajan.yadav could use define-runtime-path and then that mechanism.


soegaard2
2021-4-9 17:48:11

The paths are exported as cblas-lib and lapack-lib. https://github.com/soegaard/sci/blob/master/flomat/flomat.rkt#L73


samth
2021-4-9 17:49:13

Those aren’t the paths, they’re the ffi-lib values. And the providing direction that Rajan would need is the other way, I think.


soegaard2
2021-4-9 17:50:06

Ah!. You are right of course.


rajan.yadav
2021-4-9 17:54:14

FWIW, I get this error on destination system ffi-lib: couldn't open "libblas.so.3" (libblas.so.3: cannot open shared object file: No such file or directory)  context...:   /usr/share/racket/collects/ffi/unsafe.rkt:131:0: get-ffi-lib   '#%embedded:flomat/flomat:: [running body]   temp35_0   for-loop   run-module-instance!   for-loop   [repeats 1 more time]   run-module-instance!   for-loop   [repeats 1 more time]   run-module-instance!   perform-require!   top-level: [running body]   eval-one-top   loop   [repeats 1 more time]


samth
2021-4-9 17:56:31

Right, there isn’t a solution that’s going to make flomat work without putting libblas.so somewhere found by dlopen on the destination.


samth
2021-4-9 17:57:12

So you can either put it in the default search path, or set LD_LIBRARY_PATH, or modify the rpath in the executable directly somehow.


rajan.yadav
2021-4-9 17:58:34

I tried injecting rpath using patchelf into the executable. That didn’t work. I’ll try injecting them into so files too and see how that goes


rajan.yadav
2021-4-9 17:58:53

Thanks a lot for all your inputs btw :slightly_smiling_face:


samth
2021-4-9 17:59:09

There are some logging options to see what paths get tried by ffi-lib


ryanc
2021-4-9 18:13:38

Okay, in the case of raco distribute and existing Racket code that doesn’t use define-runtime-path, the best solution I know of is to just copy the shared libraries into right lib subdirectory within the directory that raco distribute creates, as a post-processing step.


rajan.yadav
2021-4-9 18:19:05

It doesn’t look like executable in package is looking for libs in any of the sub directories of package. Which is weird


rbt
2021-4-9 18:22:53

@rbt has joined the channel


rbt
2021-4-9 18:28:11

hi that’s me!!! :slightly_smiling_face:


sb2725
2021-4-9 18:31:43

Write a function that takes as input a list of elements and returns a list with elements and their position after. For example, if the input to the function is (list ’a ’b ’c) then it will return (list a 1 b 2 c 3). Make sure to use recursion.


sb2725
2021-4-9 18:31:51

Can anyone help me in this


sb2725
2021-4-9 18:35:11

If I use map first it will on give me (a 1)


rbt
2021-4-9 18:35:48

can you try writing a function that turns (list 'a 'b 'c) into (list 'a 1 'b 'c)? (that is, add one element’s position)


sb2725
2021-4-9 18:36:34

(Map(lambda (i) (String-append i “1”)) (List “a” “b” “c”))


rbt
2021-4-9 18:37:08

not quite — it needs to be the element’s position as a number, not a string


rbt
2021-4-9 18:37:46

so, you probably know this solution is wrong: (define (shreyas-homework input) (map (lambda (i) (list i 1)) input))


ryanc
2021-4-9 18:37:52

That doesn’t sound right, and that’s not the behavior I see on a simple example. If this is example.rkt: #lang racket/base (require ffi/unsafe) (define lib (ffi-lib "nosuchlib")) and I run raco make example.rkt raco exe example.rkt raco distribute example-dir example PLTSTDERR="debug@ffi-lib" ./example-dir/bin/example then the program logs an ffi-lib failure, and the first two attempts it lists are files within ./example-dir/lib/plt/example/lib/ (but printed as absolute paths).


rbt
2021-4-9 18:39:03

e.g. > (shreyas-homework (list 'a 'b 'c)) (('a 1) ('b 2) ('c 3)) which is nested


sb2725
2021-4-9 18:39:37

Thanks


sb2725
2021-4-9 18:39:51

Let me give it a try


rbt
2021-4-9 18:39:55

so map is one function that “transforms” lists — what other functions that operate on lists do you know?


rbt
2021-4-9 18:43:45

sb2725
2021-4-9 18:45:32

I guess fold


sb2725
2021-4-9 18:45:51

Like foldl and foldr


ryanc
2021-4-9 18:51:04

Maybe the (Racket) library isn’t using a relative path to refer to the foreign library. That might explain it.


soegaard2
2021-4-9 18:51:46

samth
2021-4-9 18:53:06

Couldn’t the cblas-lib definition be shortened to two case clauses?


soegaard2
2021-4-9 18:54:10

Yes - but that ruins indentation :wink:


rbt
2021-4-9 19:10:15

what about cons, car, and cdr?


sb2725
2021-4-9 19:11:11

Yeah First and rest


sb2725
2021-4-9 19:12:28

Got it


andrei.demus
2021-4-9 20:26:34

@andrei.demus has joined the channel


raoul.schorer
2021-4-9 23:04:09

Hi, I saw the coverage tool for Racket and I’d like to know if such a thing exists for contracts, i.e. a tool that checks if functions are protected by a contract? I looked around, but didn’t find anything.


rajan.yadav
2021-4-9 23:05:51

Thanks all. I will try all suggestions over/after the weekend. I am not done yet :slightly_smiling_face:


wjb
2021-4-10 00:42:34

I’m trying to use current-test-case-around to ensure each test in a test suite can implicitly time out, but it looks like I cannot do this inside of a test suite. An example is attached here: https://gist.github.com/wilbowma/79330280f474ecc456916787028206cc

My guess is that test-suites overwrite current-test-case-around after processing the #:before, making it impossible to use this parameter with test suites; is that right?


sorawee
2021-4-10 02:41:57

that’s correct AFAIK. When I modify these in Rackunit, your program works (after fixing minor mistakes in the program):

modified rackunit-lib/rackunit/private/test-case.rkt @@ -45,7 +45,7 @@ (parameterize ([current-test-name name]) ((current-test-case-around) (λ () - (parameterize ([current-check-around plain-check-around]) + (parameterize ([current-check-around (current-check-around)]) (test-thunk)))))) (define-simple-macro (test-begin body:expr ...) modified rackunit-lib/rackunit/private/test-suite.rkt @@ -95,7 +95,7 @@ (parameterize ([current-seed seed] [current-test-case-around (test-suite-test-case-around fhere)] - [current-check-around (test-suite-check-around fhere)]) + [current-check-around (current-check-around)]) (let ([t test]) (run/inner t)) ...


wjb
2021-4-10 02:43:30

Thanks! Any way to make these actually usable to the end-user around test suites?


camoy
2021-4-10 02:44:37

Here’s a crude attempt that makes some simplifying assumptions, but might be a good start: https://gist.github.com/camoy/51bcd96d654154609673a42670fa358f


notjack
2021-4-10 03:01:17

I think there’s a pull request to fix this somewhere