Copying object files with source_set/copy

37 views
Skip to first unread message

Arthur Eubanks

unread,
Sep 11, 2023, 4:08:26 PM9/11/23
to gn-...@chromium.org
Hi,

In the LLVM gn build I'm trying to compile crtbegin.o and copy it to a specific directory (so it looks like a normal toolchain directory layout).

I've been trying to follow https://gn.googlesource.com/gn/+/main/docs/reference.md#func_copy but I can't get this working.

Something simple like

source_set("test") {
  sources = [ "test.cpp" ]
}

copy("testcopy") {
  input_dir = get_label_info(":test", "target_out_dir")
  sources = [ "$input_dir/test.test.o" ]
  outputs = [ "$root_out_dir/{{source_file_part}}" ]
  deps = [ ":test" ]
}


doesn't seem to do anything with `ninja testcopy`. I've also tried things like `sources = [ ":test" ]` but `sources` seems to be expecting files.

Am I holding it wrong or does `copy` not work with `source_set`? Also, is there a way to not manually specify `test.test.o` which seems like unstable internal gn naming?

K. Moon

unread,
Sep 11, 2023, 4:30:13 PM9/11/23
to Arthur Eubanks, gn-dev
At first glance, this seems like it should work to me. Usually at this point, I'd start looking at the generated build.ninja and toolchain.ninja files to see if I can figure out why there's a missing link in the dependency chain.

Charles Nicholson

unread,
Sep 11, 2023, 5:14:21 PM9/11/23
to K. Moon, Arthur Eubanks, gn-dev
This would be an elegant way to use get_target_outputs, if it worked everywhere:

source_set("test") {
  sources = [ "test.cpp" ]
}

copy("testcopy") {
  sources = get_target_outputs(":test")

  outputs = [ "$root_out_dir/{{source_file_part}}" ]
  deps = [ ":test" ]
}

I remember previous discussions being positive; does anyone on the GN team have any thoughts on if/when we could ever expect get_target_outputs to work across all target types and toolchains? It would be a huge boon for separating concerns and improving readability, IMO!

Charles

--
To unsubscribe from this group and stop receiving emails from it, send an email to gn-dev+un...@chromium.org.

Arthur Eubanks

unread,
Sep 11, 2023, 5:16:18 PM9/11/23
to Charles Nicholson, K. Moon, gn-dev
Oh I got confused with my original repro because I was renaming the `source_set` name, which changed the compile output name. So yes actually this does work as you said, thanks.

+1 to get_target_outputs(), that would resolve the reason why I got confused and the second question I had in the original post.
Reply all
Reply to author
Forward
0 new messages