D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 6431 - [RDMD] Modifying a library doesn't trigger a rebuild
Summary: [RDMD] Modifying a library doesn't trigger a rebuild
Status: REOPENED
Alias: None
Product: D
Classification: Unclassified
Component: tools (show other issues)
Version: D2
Hardware: Other All
: P2 critical
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-08-02 22:32 UTC by Nick Sabalausky
Modified: 2022-12-17 10:40 UTC (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Nick Sabalausky 2011-08-02 22:32:54 UTC
Similar to issue 6102, but for libraries:

1. Build some program with RDMD
2. Modify a static library your program uses.
3. Run RDMD again.

RDMD will use the cached executable instead of rebuilding it.

I've made this a separate issue because it's more difficult to solve than issue 6102.
Comment 1 Vladimir Panteleev 2013-03-10 00:15:04 UTC
(In reply to comment #0)
> 2. Modify a static library your program uses.

I assume the library is linked in via pragma(lib, "libname")?
Comment 2 Vladimir Panteleev 2013-03-10 00:43:35 UTC
Ultimately, for this to work correctly all the time, rdmd would need to know where the linker will look for library files. This isn't really realistic as it depends on the linker implementation (e.g. it might consult its own configuration files or environment variables). It's possible to add some heuristics to rdmd, though, e.g. to search /usr/lib, %LIB% / $LIBRARY_PATH, and the current directory.
Comment 3 github-bugzilla 2013-03-10 14:34:31 UTC
Commit pushed to master at https://github.com/D-Programming-Language/tools

https://github.com/D-Programming-Language/tools/commit/d7d17858bd8525e1481d931b5a0fb3cf2a3aad76
rdmd: Add some heuristics for detecting updated libraries (issue 6431)
Comment 4 David Nadlinger 2013-03-10 14:54:29 UTC
I'm marking this as fixed, as a set of heuristics has been implemented in Git master.

If they don't adequately cover your use case, please open another more detailed bug report.
Comment 5 Timothee Cour 2017-12-07 06:22:26 UTC
reopening as i just bumped on this issue
rdmd build 20171126
DMD64 D Compiler v2.077.0

build_lib
build_main
edit bar/foo.d
build_lib
build_main => doesn't rebuild

./setup.sh:
## rdmd doesn't rebuild if a dependent library changes
build_lib(){
        dmd -of=libfoo.a -lib bar/foo.d
}

build_main(){
        exe=./main
        rdmd --build-only -of$exe -Llibfoo.a --exclude=bar main.d
        $exe
}


./main.d:
import bar.foo;
void main(){ fun(); }


./bar/foo.d:
module bar.foo;
import std.stdio;
void fun(){writeln("ok4");}
Comment 6 Timothee Cour 2017-12-07 06:43:12 UTC
also:
* rdmd --makedepend doesn't mention the dependent libs (libfoo.a)
* dmd -deps neither
* dmd -v neither
Comment 7 Timothee Cour 2017-12-07 06:57:58 UTC
also:

when adding `pragma(lib, "foo");` in main.d:
(and s/-Llibfoo.a/-lfoo -L./ to make the build succeed), the dependency on lib foo will appear in both --makedepend, -deps, -v, and the rebuild will happen.

without `pragma(lib, "foo");` in main.d:
the dependency is not caught even if command line mentions -Llibfoo.a or -lfoo -L.

Is that desired behavior? requiring pragma(lib) seems less flexible
Comment 8 Timothee Cour 2017-12-07 08:46:37 UTC
ok the existing behavior is definitely buggy: when the dependent library is in a directory not equal to ".", a change to that library will not trigger recompilation:

```
./setup.sh:

## buggy behavior (correct behavior only with build_dir=.)
build_dir=temp

build_lib(){
        mkdir -p temp
        dmd -of=$build_dir/libfoo.a -lib bar/foo.d
}

build_main(){
        exe=./main
        rdmd -v --build-only -of$exe -L-lfoo -L-L$build_dir --exclude=bar main.d
        $exe
}

build_all(){
        build_lib
        build_main
        touch $build_dir/libfoo.a
        build_main
}



./main.d:
pragma(msg, "compiling...");
import bar.foo;
pragma(lib, "foo");
void main(){ fun(); }


./bar/foo.d:
module bar.foo;
void fun(){
        import std.stdio;
        writeln("ok1");
}
```