Re: macOS Sonoma Linker Issue

2024-01-06 Thread Renato via Digitalmars-d-learn

On Friday, 22 December 2023 at 17:45:27 UTC, Renato wrote:


I'm afraid I've lost interest to make it work at this point :(


Did you add "-L-ld_classic"?


That's the first thing I did... without that, LDC still 
compiles , but logs a huge amount of things like this (it keeps 
going for a few hundred of these):




I decided to continue with my struggles after all :).

I found out now that this flag is only required on my Mac x86 
(Macbook Air with Intel processor), but not on my Mac M1 (ARM), 
even though I am on the exact same MacOS version in both machines.


So I had to do this on my dub file:

```
lflags "-ld_classic" platform="osx-x86_64"
```

That works fine locally.

But unfortunately, this is causing my build on GitHub Actions to 
fail on `macos-latest` (the flag is not recognized: `ld: library 
not found for -ld_classic`).


https://github.com/renatoathaydes/dzipper/actions/runs/7433575723/job/20226754138

I just had a quick look and GH Actions [seems to be using MacOS 
12](https://github.blog/changelog/2022-10-03-github-actions-jobs-running-on-macos-latest-are-now-running-on-macos-12/).


My laptops are using MacOS Sonoma (14.1.1).

Does dub allow specifying not just the OS and architecture, but 
the OS version?? Probably not , right? This linker issue is such 
a messy problem to have.





Re: Trying to understand map being a template

2024-01-06 Thread FeepingCreature via Digitalmars-d-learn

On Saturday, 6 January 2024 at 17:57:06 UTC, Paul Backus wrote:

On Friday, 5 January 2024 at 20:41:53 UTC, Noé Falzon wrote:
In fact, how can the template be instantiated at all in the 
following example, where no functions can possibly be known at 
compile time:


```
auto do_random_map(int delegate(int)[] funcs, int[] values)
{
auto func = funcs.choice;
return values.map!func;
}
```

Thank you for the insights!


It works for the same reason this example works:

```d
void printVar(alias var)()
{
import std.stdio;
writeln(__traits(identifier, var), " = ", var);
}

void main()
{
int x = 123;
int y = 456;

printVar!x; // x = 123
printVar!y; // y = 456
x = 789;
printVar!x; // x = 789
}
```


To clarify, what this actually compiles to is:

```d

void main()
{
  int x = 123;
  int y = 456;
  void printVar_x()
  {
 import std.stdio;
 writeln(__traits(identifier, x), " = ", x);
  }
  void printVar_y()
  {
 import std.stdio;
 writeln(__traits(identifier, y), " = ", y);
  }
  printVar_x;
  printVar_y;
  x = 789;
  printVar_x;
}

```

Which lowers to:

```d
struct mainStackframe
{
  int x;
  int y;
}

void printVar_main_x(mainStackframe* context)
{
   import std.stdio;
   writeln(__traits(identifier, context.x), " = ", context.x);
}

void printVar_main_y(mainStackframe* context)
{
   import std.stdio;
   writeln(__traits(identifier, context.y), " = ", context.y);
}

void main()
{
  // this is the only "actual" variable in main()
  mainStackframe frame;
  frame.x = 123;
  frame.y = 456;
  printVar_main_x();
  printVar_main_y();
  frame.x = 789;
  printVar_main_x();
}


Same with `map`.


Re: Trying to understand map being a template

2024-01-06 Thread Paul Backus via Digitalmars-d-learn

On Friday, 5 January 2024 at 20:41:53 UTC, Noé Falzon wrote:
In fact, how can the template be instantiated at all in the 
following example, where no functions can possibly be known at 
compile time:


```
auto do_random_map(int delegate(int)[] funcs, int[] values)
{
auto func = funcs.choice;
return values.map!func;
}
```

Thank you for the insights!


It works for the same reason this example works:

```d
void printVar(alias var)()
{
import std.stdio;
writeln(__traits(identifier, var), " = ", var);
}

void main()
{
int x = 123;
int y = 456;

printVar!x; // x = 123
printVar!y; // y = 456
x = 789;
printVar!x; // x = 789
}
```


Re: What's the proper way to add a local file dependence to dub?

2024-01-06 Thread Jim Balter via Digitalmars-d-learn

On Monday, 12 March 2018 at 10:20:20 UTC, Seb wrote:

On Sunday, 4 March 2018 at 16:46:56 UTC, Marc wrote:

then copy it to sources folder?

let's say I have a small library folder at C:\mylibrary\D 
where I want to use dir.d from it. How do I add that file 
dependence to dub? But I do not want to that file be passed 
directly to dmd, I want to that file be copied to 
application's source folder (so it's easy to distribuite, with 
the dependences together as possible) then compiled. So, what 
I want to some extension is dub work with loca files.
Is this possible to do solely with dub? I know I can easily 
write a script to run before dub which copies the dependence 
files from C:\mylibrary to application's source but I'm 
looking for a more elegant
 approach as possible; I'm afraid of rewriting a makefile-like 
soon (I find cmake/make/makefiles just ugly).


You can also add a simple dub.sdl to your local files and then 
use `dub add-local` to add the package to your dub environment.
Dub will only rebuild the dependency on your local files if 
they changed (or you use a different compiler / build settings).


Why is there no documentation for this? The dub documentation 
should have a filesystem layout page, with examples of how to 
structure local libraries, how to register them, how to add them 
to projects. AFAICT no such documentation exists. I've tried to 
follow the structure of libraries I've loaded into dub's packages 
directory, but it seems to treat local packages differently. And 
dub add-package is useless ... for one thing, it *overwrites* 
local-packages.json rather than adding to it.